first working version locally
parent
fce1040da6
commit
96da23953e
36
main.py
36
main.py
|
|
@ -8,6 +8,23 @@ from dynatrace import Dynatrace
|
|||
import logging
|
||||
|
||||
|
||||
def calculateDifference(dashboards, viewCounts):
|
||||
ids = []
|
||||
for stub in getattr(dashboards, "_PaginatedList__elements"):
|
||||
ids.append(getattr(stub, "id"))
|
||||
|
||||
viewIds = []
|
||||
for metricSeries in getattr(viewCounts, "_PaginatedList__elements"):
|
||||
for metric in getattr(metricSeries, "data"):
|
||||
viewIds.append(getattr(metric, "dimension_map")["id"])
|
||||
|
||||
obsolete = []
|
||||
for value in ids:
|
||||
if value not in viewIds:
|
||||
obsolete.append(value)
|
||||
return obsolete
|
||||
|
||||
|
||||
def getDashboardsWithViewCount(DT_CLIENT, METRIC_SELECTOR, RESOLUTION,
|
||||
FROM_DATE, TO_DATE):
|
||||
metrics = DT_CLIENT.metrics.query(METRIC_SELECTOR, RESOLUTION, FROM_DATE,
|
||||
|
|
@ -22,13 +39,13 @@ def getDashboards(DT_CLIENT):
|
|||
|
||||
if __name__ == "__main__":
|
||||
|
||||
logging.basicConfig(level=logging.WARNING, format='%(levelname)s: %(message)s')
|
||||
logging.basicConfig(level=logging.INFO, format='%(levelname)s: %(message)s')
|
||||
|
||||
with open(os.path.basename("./environment.yaml")) as env_cfg:
|
||||
environment = yaml.safe_load(env_cfg)
|
||||
|
||||
for item, doc in environment.items():
|
||||
logging.info(item, " checking token ...")
|
||||
logging.info("%s checking token...", str(item))
|
||||
|
||||
if config(dict(doc[2]).get("env-token-name"), default='') != "":
|
||||
DT_URL = dict(doc[1]).get("env-url")
|
||||
|
|
@ -38,15 +55,20 @@ if __name__ == "__main__":
|
|||
FROM_DATE= dict(doc[7]).get("fromDate")
|
||||
TO_DATE= dict(doc[8]).get("toDate")
|
||||
|
||||
logging.info(item, " init Dynatrace client ...")
|
||||
logging.info("%s init Dynatrace client...", str(item))
|
||||
DT_CLIENT = Dynatrace(DT_URL, DT_TOKEN, logging.Logger("ERROR"),
|
||||
None, None, 0, 10*1000)
|
||||
|
||||
logging.info(item, " fetching all dashboards ...")
|
||||
logging.info("%s get all dashboards...", str(item))
|
||||
dashboards = getDashboards(DT_CLIENT)
|
||||
|
||||
logging.info(item, " fetching dashboards with view count that are\
|
||||
older than 6 Months...")
|
||||
viewcounts = getDashboardsWithViewCount(DT_CLIENT, METRIC_SELECTOR,
|
||||
logging.info("%s get viewcount of dashboards older than 6 months..."
|
||||
, str(item))
|
||||
viewCounts = getDashboardsWithViewCount(DT_CLIENT, METRIC_SELECTOR,
|
||||
RESOLUTION, FROM_DATE,
|
||||
TO_DATE)
|
||||
|
||||
logging.info("%s calculate difference...", str(item))
|
||||
result = calculateDifference(dashboards, viewCounts)
|
||||
|
||||
logging.info("%s calculated!", str(item))
|
||||
Loading…
Reference in New Issue