adpating script + readme

OPMAAS-3253
rforstner 2022-08-25 15:43:08 +02:00
parent b648aa2cd8
commit 87cafc8814
2 changed files with 55 additions and 47 deletions

View File

@ -7,17 +7,18 @@ from datetime import datetime
from git import Repo from git import Repo
import os import os
#set STAGING global dashboard name #set STAGING global dashboard name
DASHBOARD_NAME = "[STAGING]Global Offboard Reliability - Touchpoint Mobile #" DASHBOARD_NAME = "[STAGING]Global Offboard Reliability - Touchpoint "
AUTHSTRING = config("BITBUCKET_USERNAME")+":"+config("BITBUCKET_TOKEN") AUTHSTRING = config("BITBUCKET_USERNAME")+":"+config("BITBUCKET_TOKEN")
CONFIG_REPO_URL = "https://"+AUTHSTRING+"atc.bmwgroup.net/bitbucket/scm/opapm/shared_configuration.git" CONFIG_REPO_URL = "https://"+AUTHSTRING+"@atc.bmwgroup.net/bitbucket/scm/opapm/shared_configuration.git"
CONFIG_REPO_NAME = "shared_configuration" CONFIG_REPO_NAME = "shared_configuration"
ARCHIVE_REPO_URL = "https://"+AUTHSTRING+"atc.bmwgroup.net/bitbucket/scm/opapm/archive.git" ARCHIVE_REPO_URL = "https://"+AUTHSTRING+"@atc.bmwgroup.net/bitbucket/scm/opapm/archive.git"
ARCHIVE_REPO_NAME = "archive" ARCHIVE_REPO_NAME = "archive"
parser = argparse.ArgumentParser(description="Generate and deploy the Dynatrace Global Dashboard as Code. Auto deployment works only for STAGING dashboard", parser = argparse.ArgumentParser(description="Generate and deploy the Dynatrace Global Dashboard as Code. Auto deployment works only for STAGING dashboard",
formatter_class=argparse.ArgumentDefaultsHelpFormatter) formatter_class=argparse.ArgumentDefaultsHelpFormatter)
parser.add_argument("-R", "--rows", type=int, help="Number of rows per dashboard. If not specified, all rows will be added to single dashboard") parser.add_argument("-R", "--rows", type=int, help="Number of rows per dashboard. If not specified, all rows will be added to single dashboard")
parser.add_argument('--auto-upload', default=False, action='store_true', help="Auto upload to STAGING dashboard") parser.add_argument('--auto-upload', default=False, action='store_true', help="Auto upload to STAGING dashboard")
parser.add_argument('-T', '--touchpoint', type=str, help="Define touchpoint for which the dashboard should be updated: 'Mobile' or 'Vehicle'")
args = parser.parse_args() args = parser.parse_args()
def clone_repo_if_notexist(repourl, reponame): def clone_repo_if_notexist(repourl, reponame):
@ -66,9 +67,11 @@ def make_request(url, DTAPIToken,verify, method, jsondata):
return "An Unknown Error occurred" + repr(err) return "An Unknown Error occurred" + repr(err)
return response return response
def get_all_dashboards_withname(DTAPIToken, DTENV,name): def get_all_dashboards_withname(DTAPIToken, DTENV,name):
DTAPIURL= DTENV + "api/config/v1/dashboards" DTAPIURL= DTENV + "api/config/v1/dashboards"
r = make_request(DTAPIURL,DTAPIToken,True,"get",None) r = make_request(DTAPIURL,DTAPIToken,True,"get",None)
print(r)
entityResponse = r.json() entityResponse = r.json()
result = [] result = []
if("dashboards" in entityResponse): if("dashboards" in entityResponse):
@ -77,6 +80,7 @@ def get_all_dashboards_withname(DTAPIToken, DTENV,name):
result.append(dashboard) result.append(dashboard)
result = sorted(result, key=lambda x : x['name'], reverse=False) result = sorted(result, key=lambda x : x['name'], reverse=False)
return result return result
def backup_dashboards(DTAPIToken, DTENV, dashboards): def backup_dashboards(DTAPIToken, DTENV, dashboards):
for dashboard in dashboards: for dashboard in dashboards:
DTAPIURL = DTENV + "api/config/v1/dashboards/" + dashboard["id"] DTAPIURL = DTENV + "api/config/v1/dashboards/" + dashboard["id"]
@ -95,6 +99,7 @@ def remove_dashboards(DTAPIToken, DTENV, dashboards):
print("Removing STAGING dashboard from Dynatrace: "+dashboard["name"]) print("Removing STAGING dashboard from Dynatrace: "+dashboard["name"])
DTAPIURL = DTENV + "api/config/v1/dashboards/" + dashboard["id"] DTAPIURL = DTENV + "api/config/v1/dashboards/" + dashboard["id"]
print(make_request(DTAPIURL,DTAPIToken,True,"delete",None)) print(make_request(DTAPIURL,DTAPIToken,True,"delete",None))
def create_or_update_dashboard(DTAPIToken, DTENV, dashboards, files): def create_or_update_dashboard(DTAPIToken, DTENV, dashboards, files):
if(files): if(files):
for index, filename in enumerate(files,start=1): for index, filename in enumerate(files,start=1):
@ -118,7 +123,7 @@ def create_or_update_dashboard(DTAPIToken, DTENV, dashboards, files):
print("Dashboard for file: "+filename + " not found.") print("Dashboard for file: "+filename + " not found.")
newdashboard = { newdashboard = {
"dashboardMetadata":{ "dashboardMetadata":{
"name": DASHBOARD_NAME+str(index), "name": DASHBOARD_NAME+ args.touchpoint + "#" + str(index),
"owner": "PATRYK.GUDALEWICZ@partner.bmw.de" "owner": "PATRYK.GUDALEWICZ@partner.bmw.de"
}, },
"tiles":[] "tiles":[]
@ -129,8 +134,6 @@ def create_or_update_dashboard(DTAPIToken, DTENV, dashboards, files):
print(make_request(DTAPIURL,DTAPIToken,True,"post",json.dumps(newdashboard))) print(make_request(DTAPIURL,DTAPIToken,True,"post",json.dumps(newdashboard)))
remove_dashboards(DTAPIToken, DTENV, dashboards) remove_dashboards(DTAPIToken, DTENV, dashboards)
def get_bounds (grid_row, grid_column, tile_columnwidth, tile_rowheight): def get_bounds (grid_row, grid_column, tile_columnwidth, tile_rowheight):
grid_brick = 38 grid_brick = 38
grid_top = 0 if grid_row == 0 else grid_row * grid_brick grid_top = 0 if grid_row == 0 else grid_row * grid_brick
@ -256,17 +259,17 @@ def create_default_tiles():
) )
# EMEA HUB # EMEA HUB
newDashboardTiles.append({ "name": "Header" ,"tileType": "MARKDOWN" , "configured": "true" , "bounds": get_bounds(0 , 7 , 20 , 2), "tileFilter": {}, "markdown": "# EMEA" }) newDashboardTiles.append({ "name": "Header" ,"tileType": "MARKDOWN" , "configured": "true" , "bounds": get_bounds(0 , 7 , 20 , 2), "tileFilter": {}, "markdown": "# EMEA" })
newDashboardTiles.append({ "name": "ACTUAL" ,"tileType": "HEADER" , "configured": "true" , "bounds": get_bounds(2 , 7 , 4 , 1), "tileFilter": {} }) newDashboardTiles.append({ "name": "CURRENT" ,"tileType": "HEADER" , "configured": "true" , "bounds": get_bounds(2 , 7 , 4 , 1), "tileFilter": {} })
newDashboardTiles.append({ "name": "10 DAYS" ,"tileType": "HEADER" , "configured": "true" , "bounds": get_bounds(2 , 11 , 12 , 1), "tileFilter": {} }) newDashboardTiles.append({ "name": "10 DAYS" ,"tileType": "HEADER" , "configured": "true" , "bounds": get_bounds(2 , 11 , 12 , 1), "tileFilter": {} })
newDashboardTiles.append({ "name": "YTD" ,"tileType": "HEADER" , "configured": "true" , "bounds": get_bounds(2 , 23 , 4 , 1), "tileFilter": {} }) newDashboardTiles.append({ "name": "YTD" ,"tileType": "HEADER" , "configured": "true" , "bounds": get_bounds(2 , 23 , 4 , 1), "tileFilter": {} })
# NORTH AMERICA HUB # NORTH AMERICA HUB
newDashboardTiles.append({ "name": "Header" ,"tileType": "MARKDOWN" , "configured": "true" , "bounds": get_bounds(0 , 27 , 20 , 2), "tileFilter": {}, "markdown": "# NORTH AMERICA" }) newDashboardTiles.append({ "name": "Header" ,"tileType": "MARKDOWN" , "configured": "true" , "bounds": get_bounds(0 , 27 , 20 , 2), "tileFilter": {}, "markdown": "# NORTH AMERICA" })
newDashboardTiles.append({ "name": "ACTUAL" ,"tileType": "HEADER" , "configured": "true" , "bounds": get_bounds(2 , 27 , 4 , 1), "tileFilter": {} }) newDashboardTiles.append({ "name": "CURRENT" ,"tileType": "HEADER" , "configured": "true" , "bounds": get_bounds(2 , 27 , 4 , 1), "tileFilter": {} })
newDashboardTiles.append({ "name": "10 DAYS" ,"tileType": "HEADER" , "configured": "true" , "bounds": get_bounds(2 , 31 , 12 , 1), "tileFilter": {} }) newDashboardTiles.append({ "name": "10 DAYS" ,"tileType": "HEADER" , "configured": "true" , "bounds": get_bounds(2 , 31 , 12 , 1), "tileFilter": {} })
newDashboardTiles.append({ "name": "YTD" ,"tileType": "HEADER" , "configured": "true" , "bounds": get_bounds(2 , 43 , 4 , 1), "tileFilter": {} }) newDashboardTiles.append({ "name": "YTD" ,"tileType": "HEADER" , "configured": "true" , "bounds": get_bounds(2 , 43 , 4 , 1), "tileFilter": {} })
# CHINA HUB # CHINA HUB
newDashboardTiles.append({ "name": "Header" ,"tileType": "MARKDOWN" , "configured": "true" , "bounds": get_bounds(0 , 47 , 20 , 2), "tileFilter": {}, "markdown": "# CHINA" }) newDashboardTiles.append({ "name": "Header" ,"tileType": "MARKDOWN" , "configured": "true" , "bounds": get_bounds(0 , 47 , 20 , 2), "tileFilter": {}, "markdown": "# CHINA" })
newDashboardTiles.append({ "name": "ACTUAL" ,"tileType": "HEADER" , "configured": "true" , "bounds": get_bounds(2 , 47 , 4 , 1), "tileFilter": {} }) newDashboardTiles.append({ "name": "CURRENT" ,"tileType": "HEADER" , "configured": "true" , "bounds": get_bounds(2 , 47 , 4 , 1), "tileFilter": {} })
newDashboardTiles.append({ "name": "10 DAYS" ,"tileType": "HEADER" , "configured": "true" , "bounds": get_bounds(2 , 51 , 12 , 1), "tileFilter": {} }) newDashboardTiles.append({ "name": "10 DAYS" ,"tileType": "HEADER" , "configured": "true" , "bounds": get_bounds(2 , 51 , 12 , 1), "tileFilter": {} })
newDashboardTiles.append({ "name": "YTD" ,"tileType": "HEADER" , "configured": "true" , "bounds": get_bounds(2 , 63 , 4 , 1), "tileFilter": {} }) newDashboardTiles.append({ "name": "YTD" ,"tileType": "HEADER" , "configured": "true" , "bounds": get_bounds(2 , 63 , 4 , 1), "tileFilter": {} })
@ -311,6 +314,9 @@ def main(slo_path):
if(args.rows is not None): if(args.rows is not None):
rowcount = args.rows rowcount = args.rows
for slo_name, configuration in slo_doc.items(): for slo_name, configuration in slo_doc.items():
if "TP_" + args.touchpoint in slo_name:
print (slo_name + " eq " + args.touchpoint)
if "TP_" + args.touchpoint in slo_name:
slo_index = configuration["index"] slo_index = configuration["index"]
currindex = slo_index currindex = slo_index
if rowcount > 0 and slo_index > rowcount: if rowcount > 0 and slo_index > rowcount:
@ -358,7 +364,7 @@ def main(slo_path):
DTTOKEN = config(token.get('env-token-name')) DTTOKEN = config(token.get('env-token-name'))
DTURL = url.get('env-url') DTURL = url.get('env-url')
existingdashboards = get_all_dashboards_withname(DTTOKEN, DTURL,DASHBOARD_NAME) existingdashboards = get_all_dashboards_withname(DTTOKEN, DTURL,DASHBOARD_NAME + args.touchpoint)
print("Uploading STAGING dashboards to Dynatrace...") print("Uploading STAGING dashboards to Dynatrace...")
backup_dashboards(DTTOKEN, DTURL, existingdashboards) backup_dashboards(DTTOKEN, DTURL, existingdashboards)
now=datetime.now() now=datetime.now()

View File

@ -3,14 +3,14 @@ This repository holds the code to generate the Dynatrace Global Dashboard as Cod
The Global Dashboard splits in 2 different dashboards: The Global Dashboard splits in 2 different dashboards:
- STAGING (https://jyy23483.live.dynatrace.com/#dashboard;gtf=defaultTimeFrame;gf=defaultManagementZone;id=2f1be2c6-9109-4e6b-8ec1-895be69935e3) - STAGING
- PROD - PROD
While the PROD dashboard is adapted manually, the Staging dashboard is auto updated when this script runs. While the PROD dashboard is adapted manually, the Staging dashboard is auto updated when this script runs.
# Dashboard Splitting # Dashboard Splitting
To enable flexibility for different screensizes, the script takes an -R or --ROWS parameter to define how many SLOs should be on one dedicated dashboard. To enable flexibility for different screensizes, the script takes an -R or --ROWS parameter to define how many SLOs should be on one dedicated dashboard.
If left empty, only one dashboard will be created, if entered a row the dashboard will be splitted to multiple dashboards and uploaded with the following name: [STAGING]Global Offboard Reliability - Touchpoint Mobile #1 ..#2..#3 If left empty, only one dashboard will be created, if entered a row the dashboard will be splitted to multiple dashboards and uploaded with the following name: [STAGING]Global Offboard Reliability - Touchpoint Mobile|Vehicle #1 ..#2..#3
# shared configuration # shared configuration
@ -40,14 +40,16 @@ To provide authentication for API calls, create ".env" file in the script direct
# Usage # Usage
python createDash.py [-h] [-R ROWS] [--auto-upload] usage: createDash.py [-h] [-R ROWS] [--auto-upload] [-T TOUCHPOINT]
options: Generate and deploy the Dynatrace Global Dashboard as Code. Auto deployment works only for STAGING dashboard
-h, --help show help message and exit
-R ROWS, --rows ROWS Number of rows per dashboard. If not specified, all rows will be added to single dashboard optional arguments:
(default: None) -h, --help show this help message and exit
-R ROWS, --rows ROWS Number of rows per dashboard. If not specified, all rows will be added to single dashboard (default: None)
--auto-upload Auto upload to STAGING dashboard (default: False) --auto-upload Auto upload to STAGING dashboard (default: False)
-T TOUCHPOINT, --touchpoint TOUCHPOINT
Define touchpoint for which the dashboard should be updated: 'Mobile' or 'Vehicle' (default: None)
# Files # Files
## slo_parameter.yaml ## slo_parameter.yaml