From 928db87af444c9bf44a8cc76463ec5b6c5cd4f22 Mon Sep 17 00:00:00 2001 From: Mohse Morad Date: Wed, 4 Dec 2024 15:17:43 +0200 Subject: [PATCH] Add default promethues generator url to simulation --- playbooks/robusta_playbooks/alerts_integration.py | 3 ++- playbooks/robusta_playbooks/prometheus_simulation.py | 4 +++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/playbooks/robusta_playbooks/alerts_integration.py b/playbooks/robusta_playbooks/alerts_integration.py index 238c5304d..11f8e9007 100644 --- a/playbooks/robusta_playbooks/alerts_integration.py +++ b/playbooks/robusta_playbooks/alerts_integration.py @@ -215,7 +215,8 @@ def default_enricher(alert: PrometheusKubernetesAlert, params: DefaultEnricherPa By default, this enricher is last in the processing order, so it will be added to all alerts, that aren't silenced. """ - alert.add_link(Link(url=alert.alert.generatorURL, name="View Graph", type=LinkType.PROMETHEUS_GENERATOR_URL)) + if alert.alert.generatorURL: + alert.add_link(Link(url=alert.alert.generatorURL, name="View Graph", type=LinkType.PROMETHEUS_GENERATOR_URL)) labels = alert.alert.labels alert.add_enrichment( diff --git a/playbooks/robusta_playbooks/prometheus_simulation.py b/playbooks/robusta_playbooks/prometheus_simulation.py index 2be1becf0..2391948f1 100644 --- a/playbooks/robusta_playbooks/prometheus_simulation.py +++ b/playbooks/robusta_playbooks/prometheus_simulation.py @@ -11,6 +11,8 @@ from robusta.utils.error_codes import ActionException, ErrorCodes from robusta.utils.silence_utils import AlertManagerParams, gen_alertmanager_headers, get_alertmanager_url +FALLBACK_PROMETHUES_GENERATOR_URL = "http://localhost:9090/graph?g0.expr=up%7Bjob%3D%22apiserver%22%7D&g0.tab=0&g0.stacked=0&g0.show_exemplars=0&g0.range_input=1h" + def parse_by_operator(pairs: str, operator: str) -> Dict[str, str]: if not pairs: @@ -61,7 +63,7 @@ class PrometheusAlertParams(ActionParams): severity: str = "error" description: str = "simulated prometheus alert" summary: Optional[str] - generator_url = "" + generator_url = FALLBACK_PROMETHUES_GENERATOR_URL runbook_url: Optional[str] = "" fingerprint: Optional[str] = "" labels: Optional[str] = None