def dummy_alert_condition() -> G.AlertCondition: return G.AlertCondition( target=G.Target(), evaluator=G.Evaluator(type=G.EVAL_GT, params=42), timeRange=G.TimeRange(from_time='5m', to_time='now'), operator=G.OP_AND, reducerType=G.RTYPE_AVG, )
def test_graph_panel_alert(): data_source = 'dummy data source' targets = ['dummy_prom_query'] title = 'dummy title' alert = [ G.AlertCondition(G.Target(), G.Evaluator('a', 'b'), G.TimeRange('5', '6'), 'd', 'e') ] thresholds = [ G.GraphThreshold(20.0), G.GraphThreshold(40.2, colorMode="ok") ] graph = G.Graph(data_source, targets, title, thresholds=thresholds, alert=alert) data = graph.to_json_data() assert data['targets'] == targets assert data['datasource'] == data_source assert data['title'] == title assert data['alert'] == alert assert data['thresholds'] == []
def test_alert_thresholds(): some_target_for_alert = G.GraphiteTarget(refId="A", target="foo.bar") graph = G.Graph(title="Graph with alert", targets=[some_target_for_alert], alert=G.Alert(name="alert name", message="alert message", alertConditions=[ G.AlertCondition( some_target_for_alert, timeRange=G.TimeRange("5m", "now"), evaluator=G.GreaterThan(10), reducerType=G.RTYPE_MAX, operator=G.OP_AND) ])) stream = StringIO() _gen.write_dashboard(graph, stream) graph_json = json.loads(stream.getvalue()) print(graph_json.keys()) #threre is a threshold assert graph_json['thresholds'][0] != None