Implemented interaction with git (archive and shared config)
parent
d5f7976967
commit
1482f949cf
|
|
@ -1,3 +1,5 @@
|
||||||
.env
|
.env
|
||||||
dashboard_tiles_*
|
dashboard_tiles_*
|
||||||
\[STAGING\]*
|
\[STAGING\]*
|
||||||
|
shared_configuration/
|
||||||
|
archive/
|
||||||
|
|
@ -4,14 +4,35 @@ import json
|
||||||
import argparse
|
import argparse
|
||||||
import requests
|
import requests
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
|
from git import Repo
|
||||||
|
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 Mobile #"
|
||||||
|
CONFIG_REPO_URL = "https://atc.bmwgroup.net/bitbucket/scm/opapm/shared_configuration.git"
|
||||||
|
CONFIG_REPO_NAME = "shared_configuration"
|
||||||
|
ARCHIVE_REPO_URL = "https://atc.bmwgroup.net/bitbucket/scm/opapm/archive.git"
|
||||||
|
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")
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
|
def clone_repo_if_notexist(repourl, reponame):
|
||||||
|
if(not os.path.isdir(reponame)):
|
||||||
|
repo = Repo.clone_from(repourl, reponame)
|
||||||
|
return repo
|
||||||
|
return Repo(reponame)
|
||||||
|
def pull_repo(repo):
|
||||||
|
origin = repo.remotes.origin
|
||||||
|
origin.pull()
|
||||||
|
|
||||||
|
def push_repo(repo, message):
|
||||||
|
repo.git.add(all=True)
|
||||||
|
repo.index.commit(message)
|
||||||
|
origin = repo.remotes.origin
|
||||||
|
origin.push()
|
||||||
|
|
||||||
def load_slo_parameter(path):
|
def load_slo_parameter(path):
|
||||||
# the first part is to read a yaml and only select latest, valid config
|
# the first part is to read a yaml and only select latest, valid config
|
||||||
with open(path) as file:
|
with open(path) as file:
|
||||||
|
|
@ -62,7 +83,10 @@ def backup_dashboards(DTAPIToken, DTENV, dashboards):
|
||||||
print("Downloaded dashboard from Dynatrace: "+entityResponse["dashboardMetadata"]["name"]+", creating backup...")
|
print("Downloaded dashboard from Dynatrace: "+entityResponse["dashboardMetadata"]["name"]+", creating backup...")
|
||||||
now=datetime.now()
|
now=datetime.now()
|
||||||
strnow = now.strftime("%Y%m%d_%H%M%S")
|
strnow = now.strftime("%Y%m%d_%H%M%S")
|
||||||
with open(entityResponse["dashboardMetadata"]["name"]+"_"+strnow+".json", "w") as file:
|
strnowdate = now.strftime("%Y%m%d")
|
||||||
|
if not os.path.isdir("./archive/"+strnowdate):
|
||||||
|
os.makedirs("./archive/"+strnowdate)
|
||||||
|
with open("./archive/"+strnowdate+"/"+entityResponse["dashboardMetadata"]["name"]+"_"+strnow+".json", "w") as file:
|
||||||
json.dump(entityResponse, file, indent=2)
|
json.dump(entityResponse, file, indent=2)
|
||||||
def remove_dashboards(DTAPIToken, DTENV, dashboards):
|
def remove_dashboards(DTAPIToken, DTENV, dashboards):
|
||||||
for dashboard in dashboards:
|
for dashboard in dashboards:
|
||||||
|
|
@ -70,7 +94,6 @@ def remove_dashboards(DTAPIToken, DTENV, dashboards):
|
||||||
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):
|
||||||
backup_dashboards(DTAPIToken, DTENV, dashboards)
|
|
||||||
if(files):
|
if(files):
|
||||||
for index, filename in enumerate(files,start=1):
|
for index, filename in enumerate(files,start=1):
|
||||||
with open('./'+filename) as file:
|
with open('./'+filename) as file:
|
||||||
|
|
@ -248,6 +271,10 @@ def create_default_tiles():
|
||||||
return newDashboardTiles
|
return newDashboardTiles
|
||||||
|
|
||||||
def main(slo_path):
|
def main(slo_path):
|
||||||
|
configrepo = clone_repo_if_notexist(CONFIG_REPO_URL, CONFIG_REPO_NAME)
|
||||||
|
pull_repo(configrepo)
|
||||||
|
archiverepo = clone_repo_if_notexist(ARCHIVE_REPO_URL, ARCHIVE_REPO_NAME)
|
||||||
|
pull_repo(archiverepo)
|
||||||
print("Generating dashboard tiles...")
|
print("Generating dashboard tiles...")
|
||||||
slo_doc = load_slo_parameter(slo_path)
|
slo_doc = load_slo_parameter(slo_path)
|
||||||
dashboard_json = create_default_tiles()
|
dashboard_json = create_default_tiles()
|
||||||
|
|
@ -328,11 +355,15 @@ def main(slo_path):
|
||||||
print("Gather data, hold on a minute")
|
print("Gather data, hold on a minute")
|
||||||
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)
|
||||||
print("Uploading STAGING dashboards to Dynatrace...")
|
print("Uploading STAGING dashboards to Dynatrace...")
|
||||||
|
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)
|
create_or_update_dashboard(DTTOKEN, DTURL, existingdashboards, generatedfiles)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
main('./slo_parameter.yaml')
|
main('./shared_configuration/slo_parameter.yaml')
|
||||||
|
|
@ -2,4 +2,5 @@ python-decouple
|
||||||
pyyaml
|
pyyaml
|
||||||
requests
|
requests
|
||||||
datetime
|
datetime
|
||||||
argparse
|
argparse
|
||||||
|
GitPython
|
||||||
|
|
@ -1,262 +0,0 @@
|
||||||
---
|
|
||||||
TP_Mobile_Login:
|
|
||||||
index: 1
|
|
||||||
selector_type: "text"
|
|
||||||
selector_var: 'CoCo-QM-Report_Mobile'
|
|
||||||
yearstart: "2022-01-01"
|
|
||||||
displayname: "Login"
|
|
||||||
department: "DE-442"
|
|
||||||
metric: "func:slo.tp_mobile_login"
|
|
||||||
doc_url: "https://atc.bmwgroup.net/confluence/x/R1OqdQ"
|
|
||||||
ops_dashboard:
|
|
||||||
emea: "https"
|
|
||||||
na: ""
|
|
||||||
cn: ""
|
|
||||||
hubs:
|
|
||||||
euprod:
|
|
||||||
tiles: ["actual","graph","ytd"]
|
|
||||||
naprod:
|
|
||||||
tiles: ["actual","graph","ytd"]
|
|
||||||
cnprod:
|
|
||||||
tiles: ["actual","graph","ytd"]
|
|
||||||
thresholds:
|
|
||||||
single_value: "99_#577025|98_#f5d30f|0_#ff0000"
|
|
||||||
graph_value: "99_#353535|98_#f5d30f|0_#ff0000"
|
|
||||||
|
|
||||||
TP_Mobile_Mapping:
|
|
||||||
index: 2
|
|
||||||
selector_type: "text"
|
|
||||||
selector_var: 'CoCo-QM-Report_Mobile'
|
|
||||||
yearstart: "2022-01-01"
|
|
||||||
displayname: "Mapping"
|
|
||||||
department: "DE-443"
|
|
||||||
metric: "func:slo.tp_mobile_mapping"
|
|
||||||
doc_url: "https://atc.bmwgroup.net/confluence/x/WFOqdQ"
|
|
||||||
ops_dashboard:
|
|
||||||
emea: "https"
|
|
||||||
na: ""
|
|
||||||
cn: ""
|
|
||||||
hubs:
|
|
||||||
euprod:
|
|
||||||
tiles: ["actual","graph","ytd"]
|
|
||||||
naprod:
|
|
||||||
tiles: ["graph","ytd"]
|
|
||||||
thresholds:
|
|
||||||
single_value: "99_#577025|98_#f5d30f|0_#ff0000"
|
|
||||||
graph_value: "99_#353535|98_#f5d30f|0_#ff0000"
|
|
||||||
|
|
||||||
TP_Mobile_VehicleList:
|
|
||||||
index: 3
|
|
||||||
selector_type: "text"
|
|
||||||
selector_var: 'CoCo-QM-Report_Mobile'
|
|
||||||
yearstart: "2022-01-01"
|
|
||||||
displayname: "Vehicle List"
|
|
||||||
department: "DE-43"
|
|
||||||
metric: "func:slo.tp_mobile_vehiclelist"
|
|
||||||
doc_url: "https://atc.bmwgroup.net/confluence/x/c1OqdQ"
|
|
||||||
ops_dashboard:
|
|
||||||
emea: "https"
|
|
||||||
na: ""
|
|
||||||
cn: ""
|
|
||||||
hubs:
|
|
||||||
euprod:
|
|
||||||
tiles: ["actual","graph","ytd"]
|
|
||||||
naprod:
|
|
||||||
tiles: ["actual","graph","ytd"]
|
|
||||||
cnprod:
|
|
||||||
tiles: ["actual","graph","ytd"]
|
|
||||||
thresholds:
|
|
||||||
single_value: "99_#577025|98_#f5d30f|0_#ff0000"
|
|
||||||
graph_value: "99_#353535|98_#f5d30f|0_#ff0000"
|
|
||||||
|
|
||||||
TP_Mobile_VehicleData:
|
|
||||||
index: 4
|
|
||||||
selector_type: "text"
|
|
||||||
selector_var: 'CoCo-QM-Report_Mobile'
|
|
||||||
yearstart: "2022-01-01"
|
|
||||||
displayname: "Vehicle Data"
|
|
||||||
department: "DE-733"
|
|
||||||
metric: "func:slo.tp_mobile_vehicledata"
|
|
||||||
doc_url: "https://atc.bmwgroup.net/confluence/x/LFOqdQ"
|
|
||||||
ops_dashboard:
|
|
||||||
emea: "https"
|
|
||||||
na: ""
|
|
||||||
cn: ""
|
|
||||||
hubs:
|
|
||||||
euprod:
|
|
||||||
tiles: ["actual","graph","ytd"]
|
|
||||||
naprod:
|
|
||||||
tiles: ["actual","graph","ytd"]
|
|
||||||
cnprod:
|
|
||||||
tiles: ["actual","graph","ytd"]
|
|
||||||
thresholds:
|
|
||||||
single_value: "99_#577025|98_#f5d30f|0_#ff0000"
|
|
||||||
graph_value: "99_#353535|98_#f5d30f|0_#ff0000"
|
|
||||||
|
|
||||||
TP_Mobile_RemoteServices:
|
|
||||||
index: 5
|
|
||||||
selector_type: "text"
|
|
||||||
selector_var: 'CoCo-QM-Report_Mobile'
|
|
||||||
yearstart: "2022-01-01"
|
|
||||||
displayname: "Remote Services"
|
|
||||||
department: "DE-723"
|
|
||||||
metric: "func:slo.tp_mobile_remoteservices"
|
|
||||||
doc_url: "https://atc.bmwgroup.net/confluence/x/dFSqdQ"
|
|
||||||
ops_dashboard:
|
|
||||||
emea: "https://xxu26128.live.dynatrace.com/#dashboard;gtf=-35m%20to%20-5m;gf=all;id=a3d9155e-24fd-4ec9-b9bc-31eb5772422f"
|
|
||||||
na: ""
|
|
||||||
cn: ""
|
|
||||||
hubs:
|
|
||||||
euprod:
|
|
||||||
tiles: ["actual","graph","ytd"]
|
|
||||||
naprod:
|
|
||||||
tiles: ["actual","graph","ytd"]
|
|
||||||
cnprod:
|
|
||||||
tiles: ["actual","graph","ytd"]
|
|
||||||
thresholds:
|
|
||||||
single_value: "99_#577025|98_#f5d30f|0_#ff0000"
|
|
||||||
graph_value: "99_#353535|98_#f5d30f|0_#ff0000"
|
|
||||||
|
|
||||||
TP_Mobile_Remote360:
|
|
||||||
index: 6
|
|
||||||
selector_type: "text"
|
|
||||||
selector_var: 'CoCo-QM-Report_Mobile'
|
|
||||||
yearstart: "2022-01-01"
|
|
||||||
displayname: "Remote Camera"
|
|
||||||
department: "DE-723"
|
|
||||||
metric: "func:slo.tp_mobile_remote360"
|
|
||||||
doc_url: "https://atc.bmwgroup.net/confluence/x/aVSqdQ"
|
|
||||||
ops_dashboard:
|
|
||||||
emea: "https"
|
|
||||||
na: ""
|
|
||||||
cn: ""
|
|
||||||
hubs:
|
|
||||||
euprod:
|
|
||||||
tiles: ["actual","graph","ytd"]
|
|
||||||
naprod:
|
|
||||||
tiles: ["actual","graph","ytd"]
|
|
||||||
cnprod:
|
|
||||||
tiles: ["actual","graph","ytd"]
|
|
||||||
thresholds:
|
|
||||||
single_value: "99_#577025|98_#f5d30f|0_#ff0000"
|
|
||||||
graph_value: "99_#353535|98_#f5d30f|0_#ff0000"
|
|
||||||
|
|
||||||
TP_Mobile_Send2VehicleMGU:
|
|
||||||
index: 7
|
|
||||||
selector_type: "text"
|
|
||||||
selector_var: 'CoCo-QM-Report_Mobile'
|
|
||||||
yearstart: "2022-01-01"
|
|
||||||
displayname: "Send to Vehicle (MGU)"
|
|
||||||
department: "DE-320"
|
|
||||||
metric: "func:slo.tp_mobile_send2vehiclemgu"
|
|
||||||
doc_url: "https://atc.bmwgroup.net/confluence/x/qFSqdQ"
|
|
||||||
ops_dashboard:
|
|
||||||
emea: "https"
|
|
||||||
na: ""
|
|
||||||
cn: ""
|
|
||||||
hubs:
|
|
||||||
euprod:
|
|
||||||
tiles: ["actual","graph","ytd"]
|
|
||||||
naprod:
|
|
||||||
tiles: ["actual","graph","ytd"]
|
|
||||||
cnprod:
|
|
||||||
tiles: ["actual","graph","ytd"]
|
|
||||||
thresholds:
|
|
||||||
single_value: "99_#577025|98_#f5d30f|0_#ff0000"
|
|
||||||
graph_value: "99_#353535|98_#f5d30f|0_#ff0000"
|
|
||||||
|
|
||||||
TP_Mobile_Send2VehicleLegacy:
|
|
||||||
index: 8
|
|
||||||
selector_type: "text"
|
|
||||||
selector_var: 'CoCo-QM-Report_Mobile'
|
|
||||||
yearstart: "2022-01-01"
|
|
||||||
displayname: "Send to Vehicle (Legacy)"
|
|
||||||
department: "DE-723"
|
|
||||||
metric: "func:slo.tp_mobile_send2vehiclelegacy"
|
|
||||||
doc_url: "https://atc.bmwgroup.net/confluence/x/z1SqdQ"
|
|
||||||
ops_dashboard:
|
|
||||||
emea: "https"
|
|
||||||
na: ""
|
|
||||||
cn: ""
|
|
||||||
hubs:
|
|
||||||
euprod:
|
|
||||||
tiles: ["actual","graph","ytd"]
|
|
||||||
naprod:
|
|
||||||
tiles: ["actual","graph","ytd"]
|
|
||||||
cnprod:
|
|
||||||
tiles: ["actual","graph","ytd"]
|
|
||||||
thresholds:
|
|
||||||
single_value: "99_#577025|98_#f5d30f|0_#ff0000"
|
|
||||||
graph_value: "99_#353535|98_#f5d30f|0_#ff0000"
|
|
||||||
|
|
||||||
TP_Mobile_PersonalFavorites:
|
|
||||||
index: 9
|
|
||||||
selector_type: "text"
|
|
||||||
selector_var: 'CoCo-QM-Report_Mobile'
|
|
||||||
yearstart: "2022-01-01"
|
|
||||||
displayname: "Personal Favorites"
|
|
||||||
department: "DE-443"
|
|
||||||
metric: "func:slo.tp_mobile_personalfavorites"
|
|
||||||
doc_url: "https://atc.bmwgroup.net/confluence/x/w1SqdQ"
|
|
||||||
ops_dashboard:
|
|
||||||
emea: "https"
|
|
||||||
na: ""
|
|
||||||
cn: ""
|
|
||||||
hubs:
|
|
||||||
euprod:
|
|
||||||
tiles: ["actual","graph","ytd"]
|
|
||||||
naprod:
|
|
||||||
tiles: ["actual","graph","ytd"]
|
|
||||||
cnprod:
|
|
||||||
tiles: ["actual","graph","ytd"]
|
|
||||||
thresholds:
|
|
||||||
single_value: "99_#577025|98_#f5d30f|0_#ff0000"
|
|
||||||
graph_value: "99_#353535|98_#f5d30f|0_#ff0000"
|
|
||||||
|
|
||||||
TP_Mobile_DigitalKey:
|
|
||||||
index: 10
|
|
||||||
selector_type: "text"
|
|
||||||
selector_var: 'CoCo-QM-Report_Mobile'
|
|
||||||
yearstart: "2022-01-01"
|
|
||||||
displayname: "Digital Key"
|
|
||||||
department: "DE-730"
|
|
||||||
metric: "func:slo.tp_mobile_digitalkey"
|
|
||||||
doc_url: "https://atc.bmwgroup.net/confluence/x/u1SqdQ"
|
|
||||||
ops_dashboard:
|
|
||||||
emea: "https"
|
|
||||||
na: ""
|
|
||||||
cn: ""
|
|
||||||
hubs:
|
|
||||||
euprod:
|
|
||||||
tiles: ["actual","graph","ytd"]
|
|
||||||
naprod:
|
|
||||||
tiles: ["actual","graph","ytd"]
|
|
||||||
cnprod:
|
|
||||||
tiles: ["actual","graph","ytd"]
|
|
||||||
thresholds:
|
|
||||||
single_value: "99_#577025|98_#f5d30f|0_#ff0000"
|
|
||||||
graph_value: "99_#353535|98_#f5d30f|0_#ff0000"
|
|
||||||
|
|
||||||
TP_Mobile_RSU:
|
|
||||||
index: 11
|
|
||||||
selector_type: "text"
|
|
||||||
selector_var: 'CoCo-QM-Report_Mobile'
|
|
||||||
yearstart: "2022-01-01"
|
|
||||||
displayname: "RSU Mobile"
|
|
||||||
department: "DE-430"
|
|
||||||
metric: "func:slo.wirkkette__rsu__mobile_____reliability_of_key_requests"
|
|
||||||
doc_url: "https://atc.bmwgroup.net/confluence/x/NpnwdQ"
|
|
||||||
ops_dashboard:
|
|
||||||
emea: "https"
|
|
||||||
na: ""
|
|
||||||
cn: ""
|
|
||||||
hubs:
|
|
||||||
euprod:
|
|
||||||
tiles: ["actual","graph","ytd"]
|
|
||||||
naprod:
|
|
||||||
tiles: ["actual","graph","ytd"]
|
|
||||||
cnprod:
|
|
||||||
tiles: ["actual","graph","ytd"]
|
|
||||||
thresholds:
|
|
||||||
single_value: "99_#577025|98_#f5d30f|0_#ff0000"
|
|
||||||
graph_value: "99_#353535|98_#f5d30f|0_#ff0000"
|
|
||||||
Loading…
Reference in New Issue