From 3be1a6d76efb709406dc6c9f7f9e7c7b65467c0f Mon Sep 17 00:00:00 2001 From: Patryk Gudalewicz Date: Tue, 18 Jul 2023 13:23:47 +0200 Subject: [PATCH] OPMAAS-4530, OPMAAS-4534 Bug fixes --- config.yaml | 4 ++-- createDash.py | 24 +++++++++++++++++++++++- remoteDashboard.py | 8 ++++---- 3 files changed, 29 insertions(+), 7 deletions(-) diff --git a/config.yaml b/config.yaml index 4fad1dc..4cd6131 100644 --- a/config.yaml +++ b/config.yaml @@ -1,7 +1,7 @@ --- metadata: - basename: "Global Offboard Reliability 2.0" - stagingname: "[STAGING]Global Offboard Reliability 2.0" + basename: "Global Offboard Reliability 2.1" + stagingname: "[STAGING]Global Offboard Reliability 2.1" owner: "PATRYK.GUDALEWICZ@partner.bmw.de" #actual tile single_value_header_1: "Last 1 h" diff --git a/createDash.py b/createDash.py index 483eb65..1d6d0b9 100644 --- a/createDash.py +++ b/createDash.py @@ -2,6 +2,7 @@ import yaml from decouple import config import json +from datetime import datetime import argparse from tileFactory import createHeaderTiles from tileFactory import createImageTile @@ -11,6 +12,9 @@ from repoConfig import pull_repo from repoConfig import push_repo from sloHelper import load_slo_parameter from sloConfigLoader import getSloConfigurations +from remoteDashboard import get_all_dashboards_withname +from remoteDashboard import backup_dashboards +from remoteDashboard import create_or_update_dashboard import warnings warnings.filterwarnings("ignore") @@ -91,7 +95,25 @@ def main(): with open("./tiles/dashboard_tiles_"+str(dahboardcount)+".json", "w") as file: json.dump(dashboard_json, file, indent=2) generatedfiles.append("dashboard_tiles_"+str(dahboardcount)+".json") - + #Upload staging dashboard if auto upload is specified + if args.auto_upload: + print("Getting existing STAGING dashboards from Dynatrace") + for item, doc in doc.items(): + if(item == "globaldashboard"): + token = dict(doc[2]) + url = dict(doc[1]) + print("Crawling through: " + item) + print("Gather data, hold on a minute") + DTTOKEN = config(token.get('env-token-name')) + DTURL = url.get('env-url') + print("Downloading STAGING dashboards to local repo ("+blname+")...") + existingdashboards = get_all_dashboards_withname(DTTOKEN, DTURL,script_config["metadata"]["stagingname"]+" - " +blname) + print("Uploading STAGING dashboards to Dynatrace ("+blname+")...") + backup_dashboards(DTTOKEN, DTURL, existingdashboards) + now=datetime.now() + strnowdate = now.strftime("%Y%m%d") + push_repo(archiverepo, strnowdate+"_Global dashboard as code auto-upload backup") + create_or_update_dashboard(DTTOKEN, DTURL, existingdashboards, generatedfiles, blname,script_config,args.department) print("DONE") if __name__ == "__main__": main() \ No newline at end of file diff --git a/remoteDashboard.py b/remoteDashboard.py index 654169e..ac7658d 100644 --- a/remoteDashboard.py +++ b/remoteDashboard.py @@ -66,7 +66,7 @@ def remove_dashboards(DTAPIToken, DTENV, dashboards): def create_or_update_dashboard(DTAPIToken, DTENV, dashboards, files, businessline, config, department): if(files): for index, filename in enumerate(files,start=1): - with open('./'+filename) as file: + with open('./tiles/'+filename) as file: tilesjson = json.load(file) if any(dashboard["name"].endswith("#"+str(index)) for dashboard in dashboards): existingdashboard = next((dashboard for dashboard in dashboards if dashboard["name"].endswith("#"+str(index))), None) @@ -85,13 +85,13 @@ def create_or_update_dashboard(DTAPIToken, DTENV, dashboards, files, businesslin else: print("Dashboard for file: "+filename + " not found.") if(department == "ALL"): - dashfullname = config["stagingname"] + dashfullname = config["metadata"]["stagingname"] else: - dashfullname = config["stagingname"] + " - " + businessline + " #" + str(index) + dashfullname = config["metadata"]["stagingname"] + " - " + businessline + " #" + str(index) newdashboard = { "dashboardMetadata":{ "name": dashfullname, - "owner": "PATRYK.GUDALEWICZ@partner.bmw.de" + "owner": config["metadata"]["owner"] }, "tiles":[] }