adding mrp.py
commit
4a1d22c212
|
|
@ -0,0 +1,56 @@
|
||||||
|
from decouple import config
|
||||||
|
import yaml
|
||||||
|
import requests
|
||||||
|
import json
|
||||||
|
import pandas as pd
|
||||||
|
import time
|
||||||
|
from distutils.version import LooseVersion
|
||||||
|
from dynatraceAPI import Dynatrace
|
||||||
|
|
||||||
|
|
||||||
|
def GatherAllAgents(DTAPIToken, DTENV,friendlyName):
|
||||||
|
reportingFolder = config('REPORTING_FOLDER')
|
||||||
|
|
||||||
|
env = DTENV
|
||||||
|
DTAPIToken = DTAPIToken
|
||||||
|
|
||||||
|
result_tags = ["Environment", "Hub", "PaaS", "Cloud", "ms-id","compass-id","app-id","app.bmwgroup.com/archetype","app.bmwgroup.com/archetype-version"]
|
||||||
|
search_tags = ["app.bmwgroup.com/archtetype"]
|
||||||
|
dtClient = Dynatrace(env, DTAPIToken)
|
||||||
|
params = {}
|
||||||
|
|
||||||
|
pgs = dtClient.returnPageination(f"/api/v2/entities?entitySelector=type(PROCESS_GROUP),tag([KUBERNETES]app.bmwgroup.com/archetype)&fields=+tags", params, list_item="entities")
|
||||||
|
df = pd.DataFrame()
|
||||||
|
for pg in pgs.elements:
|
||||||
|
row={'displayName':pg['displayName']}
|
||||||
|
|
||||||
|
|
||||||
|
for tag in pg['tags']:
|
||||||
|
if tag['key'] in result_tags:
|
||||||
|
try:
|
||||||
|
row.update({ tag['key']:tag['value']})
|
||||||
|
except:
|
||||||
|
row.update({ tag['key']:tag['key']})
|
||||||
|
|
||||||
|
df = df.append(row,ignore_index=True)
|
||||||
|
df.to_csv(reportingFolder + friendlyName + '_mrps.csv')
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
with open('./environment.yaml') as file:
|
||||||
|
doc = yaml.safe_load(file)
|
||||||
|
|
||||||
|
for item, doc in doc.items():
|
||||||
|
token = dict(doc[2])
|
||||||
|
url = dict(doc[1])
|
||||||
|
print("Crawling through: " + item)
|
||||||
|
print("Check if token exists in environment...")
|
||||||
|
if(config(token.get('env-token-name')) != ""):
|
||||||
|
print("Gather data, hold on a minute")
|
||||||
|
DTTOKEN = config(token.get('env-token-name'))
|
||||||
|
DTURL = url.get('env-url')
|
||||||
|
|
||||||
|
GatherAllAgents(DTTOKEN,DTURL,item)
|
||||||
|
|
||||||
|
else:
|
||||||
|
print("token not found, skipping " + item)
|
||||||
Loading…
Reference in New Issue