import yaml from decouple import config import json def load_slo_parameter(path): # the first part is to read a yaml and only select latest, valid config with open(path) as file: slo_doc = yaml.safe_load(file) return slo_doc def get_bounds (grid_row, grid_column, tile_columnwidth, tile_rowheight): grid_brick = 38 grid_top = 0 if grid_row == 0 else grid_row * grid_brick grod_left = 0 if grid_column == 0 else grid_column * grid_brick grod_width = 0 if tile_columnwidth == 0 else tile_columnwidth * grid_brick grod_height = 0 if tile_rowheight == 0 else tile_rowheight * grid_brick bounds = { "top": grid_top, "left": grod_left, "width": grod_width, "height": grod_height } return bounds def get_dataExplorerTileSloThreshold(sloThresholdValuesAndColor): value1 = int(str(sloThresholdValuesAndColor).split("|")[0].split("_")[0]) value2 = int(str(sloThresholdValuesAndColor).split("|")[1].split("_")[0]) value3 = int(str(sloThresholdValuesAndColor).split("|")[2].split("_")[0]) color1 = str(sloThresholdValuesAndColor).split("|")[0].split("_")[1] color2 = str(sloThresholdValuesAndColor).split("|")[1].split("_")[1] color3 = str(sloThresholdValuesAndColor).split("|")[2].split("_")[1] dataExplorerTileThreshold = [ { "value": value1, "color": color1 }, { "value": value2, "color": color2 }, { "value": value3, "color": color3 } ] return dataExplorerTileThreshold def get_DataExplorerTile_Markdown(name_short, department, bounds, detailDashboardUrl_EMEA,detailDashboardUrl_NA, detailDashboardUrl_CN, docURL ): # dataExplorerTile_Markdown = { # "name": "Markdown", # "tileType": "MARKDOWN", # "configured": "true", # "bounds": bounds, # "tileFilter": {}, # "markdown": "___________\n## " + name_short + "\n\n" + department + " | --> [EMEA](" + detailDashboardUrl_EMEA + ") [NA](" + detailDashboardUrl_NA + ") [CN](" + detailDashboardUrl_CN + ")\n [Documentation](" + docURL + ")" # } #without team links dataExplorerTile_Markdown = { "name": "Markdown", "tileType": "MARKDOWN", "configured": "true", "bounds": bounds, "tileFilter": {}, "markdown": "___________\n## " + name_short + "\n\n" + department + " \n [Documentation](" + docURL + ")" } return dataExplorerTile_Markdown def get_DataExplorerTile_SingleValue(customName, metricSelector, remoteEnvironmentUrl, bounds, timeframe, graphThreshold): dataExplorerTile_SingleValue = { "name": "", "tileType": "DATA_EXPLORER", "configured": "true", "bounds": bounds, "tileFilter": { "timeframe": timeframe }, "remoteEnvironmentUri": remoteEnvironmentUrl, "customName": customName, "queries": [ { "id": "A", "timeAggregation": "DEFAULT", "metricSelector": metricSelector, "foldTransformation": "TOTAL", "enabled": "true" } ], "visualConfig": { "type": "SINGLE_VALUE", "global": { "seriesType": "LINE", "hideLegend": "true" }, "rules": [ { "matcher": "A:", "properties": { "color": "DEFAULT", "seriesType": "LINE", "alias": "SLO" }, "seriesOverrides": [{"name": customName, "color": "#ffffff"}] } ], "axes": { "xAxis": { "visible": "true" }, "yAxes": [] }, "heatmapSettings": {}, "singleValueSettings": { "showTrend": "false", "showSparkLine": "false", "linkTileColorToThreshold": "true" }, "thresholds": [ { "axisTarget": "LEFT", "rules": graphThreshold, "queryId": "", "visible": "true" } ], "tableSettings": { "isThresholdBackgroundAppliedToCell": "false" }, "graphChartSettings": { "connectNulls": "false" } }, "queriesSettings": { "resolution": "" } } return dataExplorerTile_SingleValue def get_DataExplorerTile_Graph(customName, metricSelector, remoteEnvironmentUrl, bounds, timeframe, axisTargetMin, axisTargetMax, graphThreshold ): dataExplorerTile_Graph = { "name": "", "tileType": "DATA_EXPLORER", "configured": "true", "bounds": bounds, "tileFilter": { "timeframe": timeframe }, "remoteEnvironmentUri": remoteEnvironmentUrl, "customName": customName, "queries": [ { "id": "A", "timeAggregation": "DEFAULT", "metricSelector": metricSelector, "foldTransformation": "TOTAL", "enabled": "true" } ], "visualConfig": { "type": "GRAPH_CHART", "global": { "seriesType": "LINE", "hideLegend": "true" }, "rules": [ { "matcher": "A:", "properties": { "color": "DEFAULT", "seriesType": "LINE", "alias": "SLO" }, "seriesOverrides": [{"name": customName, "color": "#ffffff"}] } ], "axes": { "xAxis": { "visible": "true" }, "yAxes": [{ "displayName": "", "visible": "true", "min": axisTargetMin, "max": axisTargetMax, "position": "LEFT", "queryIds": [ "A" ], "defaultAxis": "true" }] }, "heatmapSettings": {}, "singleValueSettings": { "showTrend": "false", "showSparkLine": "false", "linkTileColorToThreshold": "true" }, "thresholds": [ { "axisTarget": "LEFT", "rules": graphThreshold, "queryId": "", "visible": "true" } ], "tableSettings": { "isThresholdBackgroundAppliedToCell": "false" }, "graphChartSettings": { "connectNulls": "false" } }, "queriesSettings": { "resolution": "" } } return dataExplorerTile_Graph def create_default_tiles(): newDashboardTiles = [] # HEADER TILES # Picture Tile newDashboardTiles.append( { "name": "Image", "tileType": "IMAGE", "configured": "true", "bounds": {"top": 0, "left": 0, "width": 76, "height": 114}, "tileFilter": {}, "image": "data:image/webp;base64,UklGRlYHAABXRUJQVlA4WAoAAAAQAAAAOQAAcAAAQUxQSAQBAAABgGNt2zHn2cDYUzM2O6tyNWVsLCJZAav5+2QWEHZONmBbpTHW95zvpExEoG3bNlS7FdmaIxCVylExPCKo4UqHCvFqXzp8Cgjr6XCpLZbe9x0Q3LdPH339AUL+qKMEKClhje8cb7XATIDUFHQrLIsa9xHLicd5wHLo+js59nnKb3kGAjzDUuogyjplDpJRwSVPv4SD9h1DNC+1PIERokGmYaLmVx7nPo/rkKdXyidDMhoi6uO5LSP+bmcPcaPknsu4OZ0H/5VxH7EcewxrLGt6zLHMAc2fHB9NABQOBWH2PYYtawRKF8Sbz0d0usmNs3dx3s/WJ3SIkyXdOzYqqHFvugWRAFZQOCAsBgAAkBoAnQEqOgBxAD5tMJNHJCKhoSYVXdCADYlpDbwAiVj9T4g+Rr19KlpQ3/9rj/S8IrYT0C+8HEJxzeAh9f5w/Pv9WewZ0rPRuDyMFLG6crgiIWlUyjpmL5HPrpvWBMvukVcE5YNx8ruVhPIdFYzcMcSKDt6WbR2pWVaPGgSC2qlIjC2BEG5M26HdCGzRgIB5zaaZ07nGiRZzz9vXMi/llb00XYLoUdkiCDl3QGQsoImUReZw/BdBhECojaxfssBPjD/e0Byn4skcilQkqjWBGiPtxxnxE2z2ij64eQAA/vk3/iQ3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h6YOF5nqdGp8kJEdzOIvpOAlVY0IlHeRHo1RjWnkf5/AUGU5e+U9mZisn16llZslRbu+7wszY2HNDg8Am1OKUXeqUPrhoZk9XeN7e4IBkz4UxRDlR4AFjdguVyHqFYnRD9kSl+6LqSjNs+o3lQclsjtqAdomU57RrASjAKYfdFeyVDh+ZaWuANksKPrtNXV8ot8BUnu952F0PU7Zq7Vj+jLBw3myGlA6swuz+0bKItmuttXGxhx/Go+wAtOzWFWwjB2SdKNNpL/ovEF5ibZz+5Fzibio4yW8apoq+UkpCcLbkd5abaPjdrjIXelYG8EDHz402pdyJW8vk49MRRFOvKqyGHJVZY1JZON2Y2oosF+xNq96ekOv09l4mW4zQrUCBiq1MHeB6bTk3Ujc6/9W5W3YpjxPrkQyIykHM0imBojob2/II37UldcLDY8MuG3Dci8rbo8TASEZ/6vAYAvtE16IFVn2Yft/fM1p/aBQQh/6Auz+OqKcSZ4GaCPzmOYHsgIieWAsZJ93o6gdU/cl9NTD/m3ZqtX1n/kCwYHEXOAX9KyvqjXqg55cTK4GnWZzFtojcfG0Fd30O9AlVl0yzSwxwxFA128xJmPoCrDV339n/l1jnaYx3ivNfCCZU7qhzUpecgzq4p/VsMQX3Pb8elQ40J68H/2n/2/Nl4O/sRgFXm9Y3Qmj0Bs0wbYY7/3//aU7iSogAAAAA=" } ) # EMEA HUB 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": "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": {} }) # 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": "ACTUAL" ,"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": "YTD" ,"tileType": "HEADER" , "configured": "true" , "bounds": get_bounds(2 , 43 , 4 , 1), "tileFilter": {} }) # CHINA HUB 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": "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": {} }) return newDashboardTiles def main(slo_path): slo_doc = load_slo_parameter(slo_path) dashboard_json = create_default_tiles() hub_config = { "euprod": { "offset": 0, "remote_url": 'https://xxu26128.live.dynatrace.com' }, "naprod": { "offset": 20, "remote_url": 'https://wgv50241.live.dynatrace.com' }, "cnprod": { "offset": 40, "remote_url": 'https://dynatrace-cn-int.bmwgroup.com:443/e/b921f1b9-c00e-4031-b9d1-f5a0d530757b' } } timeframe_actual = "-1h" timeframe_graph = "-10d to now" for slo_name, config in slo_doc.items(): slo_index = config["index"] slo_display = config["displayname"] slo_department = config["department"] timeframe_ytd = config["yearstart"] + " 00:00 to now" slo_graphThreshold_SingleValue = get_dataExplorerTileSloThreshold(config["thresholds"]["single_value"]) slo_graphThreshold_Graph = get_dataExplorerTileSloThreshold(config["thresholds"]["graph_value"]) if len(config["hubs"]) > 0: dashboard_json.append(get_DataExplorerTile_Markdown(slo_display, slo_department, get_bounds(((slo_index)*(3)) , 0 , 7 , 3), config["ops_dashboard"]["emea"], config["ops_dashboard"]["na"], config["ops_dashboard"]["cn"],config["doc_url"])) for hub,tiles in config["hubs"].items(): if 'actual' in tiles["tiles"]: dashboard_json.append(get_DataExplorerTile_SingleValue(slo_name, config["metric"], hub_config[hub]["remote_url"], get_bounds(((slo_index)*(3)) , 7 + hub_config[hub]["offset"] , 4 , 3), timeframe_actual, slo_graphThreshold_SingleValue)) if "graph" in tiles["tiles"]: dashboard_json.append(get_DataExplorerTile_Graph(slo_name, config["metric"], hub_config[hub]["remote_url"], get_bounds(((slo_index)*(3)) , 11 + hub_config[hub]["offset"] , 12 , 3), timeframe_graph, "97", "102", slo_graphThreshold_Graph)) if "ytd" in tiles["tiles"]: dashboard_json.append(get_DataExplorerTile_SingleValue(slo_name, config["metric"], hub_config[hub]["remote_url"], get_bounds(((slo_index)*(3)) , 23 + hub_config[hub]["offset"] , 4 , 3), timeframe_ytd, slo_graphThreshold_SingleValue)) with open("dashboard_tiles.json", "w") as file: json.dump(dashboard_json, file, indent=2) if __name__ == "__main__": main('./slo_parameter.yaml')