From 4a1d22c212884d3afa4934c3f9e285a447523e19 Mon Sep 17 00:00:00 2001 From: rforstner Date: Thu, 7 Jul 2022 13:51:40 +0200 Subject: [PATCH] adding mrp.py --- MRP_microservices.py | 56 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 MRP_microservices.py diff --git a/MRP_microservices.py b/MRP_microservices.py new file mode 100644 index 0000000..6199257 --- /dev/null +++ b/MRP_microservices.py @@ -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) \ No newline at end of file