139 lines
10 KiB
Python
139 lines
10 KiB
Python
#Library includes functions for tile generation
|
|
from dataExplorerTile import SingleValueTile
|
|
from dataExplorerTile import GraphTile
|
|
from sloHelper import getSloReqTimeSelector
|
|
from sloHelper import getSloReqCountSelector
|
|
from sloHelper import getSloSrvNames
|
|
|
|
#Load coloring thresholds from strings defined in yaml file
|
|
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
|
|
|
|
#Translate row numbers into grid values
|
|
def get_bounds (grid_row, grid_column, tile_columnwidth, row_height):
|
|
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 row_height == 0 else row_height * grid_brick
|
|
bounds = { "top": grid_top, "left": grod_left, "width": grod_width, "height": grod_height }
|
|
return bounds
|
|
#Generate image tile for dashboard
|
|
def createImageTile(config):
|
|
newimage = {}
|
|
newimage["name"] = "Image"
|
|
newimage["tileType"] = "IMAGE"
|
|
newimage["configured"] = "true"
|
|
newimage["bounds"] = {"top": 0,"left": 0, "width":config["visualconfig"]["image_width"],"height":config["visualconfig"]["image_height"]}
|
|
newimage["tileFilter"] = {}
|
|
newimage["image"] = config["visualconfig"]["image_data"]
|
|
return newimage
|
|
#Generate markdown tile for dashboard
|
|
def createMarkdownTile(row, name, markdown, column, width, height):
|
|
newmarkdown = {}
|
|
newmarkdown["name"] = name
|
|
newmarkdown["tileType"] = "MARKDOWN"
|
|
newmarkdown["configured"] = "true"
|
|
newmarkdown["bounds"] = get_bounds(row, column, width, height)
|
|
newmarkdown["markdown"] = markdown
|
|
return newmarkdown
|
|
#Generate header tile for dashboard
|
|
def createHeaderTile(row, name, column, width, height):
|
|
newheader= {}
|
|
newheader["name"] = name
|
|
newheader["tileType"] = "HEADER"
|
|
newheader["configured"] = "true"
|
|
newheader["bounds"] = get_bounds(row, column, width, height)
|
|
return newheader
|
|
#Generate markdown text for SLO description tile
|
|
def createSloDescriptionTile(index, name_short, department, config, docURL,slorelevant,slourls,wall): #TODO
|
|
if(not wall):
|
|
markdown = "___________\n## " + name_short + "\n\n" + department + " [Documentation](" + docURL + ")"
|
|
if(slorelevant):
|
|
markdown = markdown + " [QM-Report] \n"
|
|
else:
|
|
markdown = markdown + " \n"
|
|
for slourl in slourls:
|
|
markdown = markdown + "["+slourl.upper()+"]("+slourls[slourl]+") "
|
|
else:
|
|
markdown = "___________\n## " + name_short + "\n\n" + department
|
|
if(slorelevant):
|
|
markdown = markdown + " [QM-Report] \n"
|
|
else:
|
|
markdown = markdown + " \n"
|
|
return createMarkdownTile(index*config["visualconfig"]["rowheight"],"Markdown",markdown,0,config["visualconfig"]["description_tile_width"],config["visualconfig"]["rowheight"])
|
|
#Generate summed header tiles for all hubs
|
|
def createHeaderTiles(config,wall):
|
|
tiles = []
|
|
if(wall):
|
|
currentColumn = config["visualconfig"]["description_tile_width"]
|
|
for hub in config["hubs"]:
|
|
tiles.append(createMarkdownTile(0,"Header","# "+hub["name"]+"",currentColumn,2*config["visualconfig"]["singlevalue_width_wall"]+config["visualconfig"]["graph_width_wall"],2))
|
|
tiles.append(createHeaderTile(2,config["metadata"]["single_value_header_1"],currentColumn,config["visualconfig"]["singlevalue_width_wall"],1))
|
|
currentColumn = tiles[len(tiles)-1]["bounds"]["left"]/config["visualconfig"]["brick_size"] + tiles[len(tiles)-1]["bounds"]["width"]/config["visualconfig"]["brick_size"]
|
|
tiles.append(createHeaderTile(2,config["metadata"]["graph_header"],currentColumn,config["visualconfig"]["graph_width_wall"],1))
|
|
currentColumn = tiles[len(tiles)-1]["bounds"]["left"]/config["visualconfig"]["brick_size"] + tiles[len(tiles)-1]["bounds"]["width"]/config["visualconfig"]["brick_size"]
|
|
tiles.append(createHeaderTile(2,config["metadata"]["single_value_header_2"],currentColumn,config["visualconfig"]["singlevalue_width_wall"],1))
|
|
currentColumn = tiles[len(tiles)-1]["bounds"]["left"]/config["visualconfig"]["brick_size"] + tiles[len(tiles)-1]["bounds"]["width"]/config["visualconfig"]["brick_size"]+config["visualconfig"]["spacing"]
|
|
else:
|
|
currentColumn = config["visualconfig"]["description_tile_width"]
|
|
for hub in config["hubs"]:
|
|
tiles.append(createMarkdownTile(0,"Header","# "+hub["name"]+"",currentColumn,2*config["visualconfig"]["singlevalue_width"]+config["visualconfig"]["graph_width"],2))
|
|
tiles.append(createHeaderTile(2,config["metadata"]["single_value_header_1"],currentColumn,config["visualconfig"]["singlevalue_width"],1))
|
|
currentColumn = tiles[len(tiles)-1]["bounds"]["left"]/config["visualconfig"]["brick_size"] + tiles[len(tiles)-1]["bounds"]["width"]/config["visualconfig"]["brick_size"]
|
|
tiles.append(createHeaderTile(2,config["metadata"]["graph_header"],currentColumn,config["visualconfig"]["graph_width"],1))
|
|
currentColumn = tiles[len(tiles)-1]["bounds"]["left"]/config["visualconfig"]["brick_size"] + tiles[len(tiles)-1]["bounds"]["width"]/config["visualconfig"]["brick_size"]
|
|
tiles.append(createHeaderTile(2,config["metadata"]["single_value_header_2"],currentColumn,config["visualconfig"]["singlevalue_width"],1))
|
|
currentColumn = tiles[len(tiles)-1]["bounds"]["left"]/config["visualconfig"]["brick_size"] + tiles[len(tiles)-1]["bounds"]["width"]/config["visualconfig"]["brick_size"]+config["visualconfig"]["spacing"]
|
|
return tiles
|
|
|
|
#Create full SLO row
|
|
def createSloTileRow(index, config, wall, sloconfigs,doc):
|
|
tiles = []
|
|
sloUrls = {}
|
|
currentColumn = config["visualconfig"]["description_tile_width"]
|
|
for sloconfig in sloconfigs:
|
|
service_names = getSloSrvNames(sloconfig, doc)
|
|
sloUrls[sloconfig.hub] = sloconfig.slourl
|
|
if sloconfig.tiles_actual and wall:
|
|
tile = SingleValueTile(sloconfig.displayName,get_bounds(index*config["visualconfig"]["rowheight"],currentColumn,config["visualconfig"]["singlevalue_width_wall"],config["visualconfig"]["rowheight"]),config["metadata"]["single_value_timeframe_1"],sloconfig.remoteurl,sloconfig.metric,sloconfig.singlevalue_threshold)
|
|
tiles.append(vars(tile))
|
|
elif sloconfig.tiles_actual:
|
|
tile = SingleValueTile(sloconfig.displayName,get_bounds(index*config["visualconfig"]["rowheight"],currentColumn,config["visualconfig"]["singlevalue_width"],config["visualconfig"]["rowheight"]),config["metadata"]["single_value_timeframe_1"],sloconfig.remoteurl,sloconfig.metric,sloconfig.singlevalue_threshold)
|
|
tiles.append(vars(tile))
|
|
currentColumn = tiles[len(tiles)-1]["bounds"]["left"]/config["visualconfig"]["brick_size"] + tiles[len(tiles)-1]["bounds"]["width"]/config["visualconfig"]["brick_size"]
|
|
if sloconfig.tiles_graph:
|
|
if(sloconfig.custom_traffic):
|
|
traffic_selector = sloconfig.custom_traffic
|
|
else:
|
|
traffic_selector = getSloReqCountSelector(service_names)
|
|
if(sloconfig.custom_latency):
|
|
latency_selector = sloconfig.custom_latency
|
|
else:
|
|
latency_selector = getSloReqTimeSelector(service_names)
|
|
if wall:
|
|
tile = GraphTile(sloconfig.displayName,get_bounds(index*config["visualconfig"]["rowheight"],currentColumn,config["visualconfig"]["graph_width_wall"],config["visualconfig"]["rowheight"]),sloconfig.remoteurl,sloconfig.metric,traffic_selector,latency_selector,sloconfig.graph_threshold,sloconfig.metric,config["visualconfig"]["graph_axis_min"],config["visualconfig"]["graph_axis_max"],config)
|
|
else:
|
|
tile = GraphTile(sloconfig.displayName,get_bounds(index*config["visualconfig"]["rowheight"],currentColumn,config["visualconfig"]["graph_width"],config["visualconfig"]["rowheight"]),sloconfig.remoteurl,sloconfig.metric,traffic_selector,latency_selector,sloconfig.graph_threshold,sloconfig.metric,config["visualconfig"]["graph_axis_min"],config["visualconfig"]["graph_axis_max"],config)
|
|
tiles.append(vars(tile))
|
|
currentColumn = tiles[len(tiles)-1]["bounds"]["left"]/config["visualconfig"]["brick_size"] + tiles[len(tiles)-1]["bounds"]["width"]/config["visualconfig"]["brick_size"]
|
|
if sloconfig.tiles_ytd and wall:
|
|
tile = SingleValueTile(sloconfig.displayName,get_bounds(index*config["visualconfig"]["rowheight"],currentColumn,config["visualconfig"]["singlevalue_width_wall"],config["visualconfig"]["rowheight"]),config["metadata"]["single_value_timeframe_2"],sloconfig.remoteurl,sloconfig.metric,sloconfig.singlevalue_threshold)
|
|
tiles.append(vars(tile))
|
|
elif sloconfig.tiles_ytd:
|
|
tile = SingleValueTile(sloconfig.displayName,get_bounds(index*config["visualconfig"]["rowheight"],currentColumn,config["visualconfig"]["singlevalue_width"],config["visualconfig"]["rowheight"]),config["metadata"]["single_value_timeframe_2"],sloconfig.remoteurl,sloconfig.metric,sloconfig.singlevalue_threshold)
|
|
tiles.append(vars(tile))
|
|
currentColumn = tiles[len(tiles)-1]["bounds"]["left"]/config["visualconfig"]["brick_size"] + tiles[len(tiles)-1]["bounds"]["width"]/config["visualconfig"]["brick_size"]+config["visualconfig"]["spacing"]
|
|
tiles = [createSloDescriptionTile(index,sloconfigs[0].displayName,sloconfigs[0].department,config,sloconfigs[0].docurl,sloconfigs[0].slorelevant,sloUrls,wall)] +tiles
|
|
return tiles
|