Controller (SaaS, On Premise)

cancel
Showing results for 
Search instead for 
Did you mean: 

AppD Inventory Website

SOLVED
Highlighted

AppD Inventory Website

Hi,

 

I would like to create an AppD inventory Website with the following details.

EAI, Application Name, Agent Type, Agent Version, Environment (PROD,QA, INT & DEV). 

 

What are the best practices to create this? Do we have any scripts or plugins to do that? I'm thinking about doing it on WordPress by automating the data from CSV or excel. 

 

Thanks,

Sravan

AppD Inventory Website
3 REPLIES 3
Architect

Re: AppD Inventory Website

Hi. Not sure if you can post json data to WordPress? If so I can share a pythyon script I use for pushing stuff to elastic to get you started.

Re: AppD Inventory Website

Yes Please Share it along with the process and any additional steps I need to do. Thanks for your help.

Architect

Re: AppD Inventory Website

Replace mydomain.com in all places

replace uid and pwd in "usage statment"

replace prodserver and testserver with your controllers

replace (if using elastic) esuid and espwd

 

You need python 3

 

Produces output like this for each node:

 

{'appAgentVersion': 'Server Agent #4.5.7.24863 v4.5.7 GA compatible with 4.4.1.0 radaa5f09cafb67679c435337aa86ecda35877078 master', 'machineAgentVersion': '', 'agentType': 'APP_AGENT', 'type': 'Other', 'machineName': 'sso73-openshift-customiz-47-tzc9c', 'appAgentPresent': True, 'nodeUniqueLocalId': '', 'machineId': 271232, 'machineOSType': 'Linux', 'tierId': 2727, 'tierName': 'CD_DEV_sso', 'machineAgentPresent': False, 'name': 'CD_DEV_sso73-openshift-customiz-47-tzc9c', 'ipAddresses': None, 'id': 586157, 'application': 'CD_DEV_sso', 'date': '2019-10-31T13:09:33.468978', 'description': ''}

 

 

 

 

import requests
import json
from requests.utils import requote_uri
import string
import urllib.parse
from ast import literal_eval
import datetime
import urllib3
import sys


'''
function to loop through all applications based on it's ID
'''
def load(appl):
ID = str(appl['id'])
# use the global variable!
global app_name
global description
app_name = appl['name']
description = appl['description']
url = f"https://{controller}.mydomain.com:8181/controller/rest/applications/{ID}/nodes?output=json"
r = requests.get(url, auth=(uid, pwd), verify=False)
tiers = r.json()

for data in tiers:
loop_tiers(data)


'''
loop throough json array as datatype dict
'''
def loop_tiers(data):
global app_name
global description
#add stuff to the dictionary
data['application'] = app_name
data['date'] = datetime.datetime.utcnow().isoformat()
data['description'] = description
print(data)
# Post it off to elastic
year = str(datetime.datetime.now().year)

esuid = 'elastic'
espwd = 'my_elasticpwd'
esurl = f"https://myelasticserver.mydomain.com:9243/appd-(year)/_doc/"
headers = {'content-type': 'application/json'}
requests.post(esurl, data=json.dumps(data), auth=(esuid, espwd), headers=headers, verify=False)


'''
usage stement
'''
#set up incoming arguments
urllib3.disable_warnings()
if len(sys.argv) != 2:
print(f"\n To few or to many arguments expects either prod or test as first argumet \n Usage: python {(sys.argv[0])} appdyn_heapsize.py prod|test")
exit()
env = str.lower(sys.argv[1])
if env == 'prod':
controller = 'prodserver.mydomain.com'
uid = 'uid@customer1'
pwd = 'mypwd'
elif env == 'test':
controller = 'testserver.mydomain.com'
uid = 'uid@customer1'
pwd = 'mypwd'
else:
print('\n first argument must be either prod or test \n')
exit()

'''
Get all applications and their ID
'''
url = f"https://{controller}.mydomain.com:8181/controller/rest/applications?output=json"
app_name = ''
description = ''
r = requests.get(url, auth=(uid, pwd), verify=False)
applications = r.json()
# Call load function for each application's ID
for a_name in applications:
load(a_name)

exit(0)