def test_metric_unit_color(expression, perf_string, check_command, result_color): metrics.fixup_unit_info() translated_metrics = metrics.translate_perf_data(perf_string, check_command) reference = { "color": result_color, "unit": translated_metrics.get(expression, {}).get('unit', {}).get('id', '') } assert gt.metric_unit_color(expression, translated_metrics, ['test']) == reference
def test_metric_unit_color(expression, perf_string, check_command, result_color): metrics.fixup_unit_info() translated_metrics = metrics.translate_perf_data(perf_string, check_command) translated_metric = translated_metrics.get(expression) assert translated_metric is not None unit = translated_metric.get("unit") assert unit is not None unit_id = unit.get("id") reference = { "color": result_color, "unit": unit_id, } assert gt.metric_unit_color(expression, translated_metrics, ["test"]) == reference
def test_create_graph_recipe_from_template(): metrics.fixup_unit_info() graph_template = { "metrics": [ ("fs_used", "area"), ("fs_size,fs_used,-#e3fff9", "stack", "Free space"), ("fs_size", "line"), ], "scalars": [ "fs_used:warn", "fs_used:crit", ], "range": (0, "fs_used:max"), "conflicting_metrics": ["fs_free"], } translated_metrics = metrics.translate_perf_data( '/=163651.992188;;;; fs_size=477500.03125;;;; growth=-1280.489081;;;;', "check_mk-df") lq_row = {"site": "", "host_name": "", "service_description": ""} assert gt.create_graph_recipe_from_template( graph_template, translated_metrics, lq_row) == { 'title': 'Used filesystem space', 'metrics': [{ 'unit': 'bytes', 'color': '#00ffc6', 'title': 'Used filesystem space', 'line_type': 'area', 'expression': ('rrd', '', '', '', '_', 'max', 1048576) }, { 'unit': 'bytes', 'color': '#e3fff9', 'title': 'Free space', 'line_type': 'stack', 'expression': ('operator', '-', [('rrd', '', '', '', 'fs_size', 'max', 1048576), ('rrd', '', '', '', '_', 'max', 1048576)]) }, { 'unit': 'bytes', 'color': '#006040', 'title': 'Filesystem size', 'line_type': 'line', 'expression': ('rrd', '', '', '', 'fs_size', 'max', 1048576) }], 'unit': 'bytes', 'explicit_vertical_range': (0.0, None), 'horizontal_rules': [], 'omit_zero_metrics': False, 'consolidation_function': 'max' }
def test_create_graph_recipe_from_template(): metrics.fixup_unit_info() graph_template = { "metrics": [ ("fs_used", "area"), ("fs_size,fs_used,-#e3fff9", "stack", "Free space"), ("fs_size", "line"), ], "scalars": [ "fs_used:warn", "fs_used:crit", ], "range": (0, "fs_used:max"), "conflicting_metrics": ["fs_free"], } translated_metrics = metrics.translate_perf_data( "/=163651.992188;;;; fs_size=477500.03125;;;; growth=-1280.489081;;;;", "check_mk-df") lq_row = {"site": "", "host_name": "", "service_description": ""} assert gt.create_graph_recipe_from_template( graph_template, translated_metrics, lq_row) == { "title": "Used filesystem space", "metrics": [ { "unit": "bytes", "color": "#00ffc6", "title": "Used filesystem space", "line_type": "area", "expression": ("rrd", "", "", "", "_", "max", 1048576), }, { "unit": "bytes", "color": "#e3fff9", "title": "Free space", "line_type": "stack", "expression": ( "operator", "-", [ ("rrd", "", "", "", "fs_size", "max", 1048576), ("rrd", "", "", "", "_", "max", 1048576), ], ), }, { "unit": "bytes", "color": "#006040", "title": "Filesystem size", "line_type": "line", "expression": ("rrd", "", "", "", "fs_size", "max", 1048576), }, ], "unit": "bytes", "explicit_vertical_range": (0.0, None), "horizontal_rules": [], "omit_zero_metrics": False, "consolidation_function": "max", }