Generate silence url for prom alertmanager alerts
This commit is contained in:
parent
63b351771a
commit
301c3220f5
2 changed files with 8 additions and 0 deletions
|
|
@ -29,7 +29,9 @@ def prometheus_alert_to_markdown(
|
||||||
ignore_labels = ["grafana_folder"]
|
ignore_labels = ["grafana_folder"]
|
||||||
|
|
||||||
logging.debug(f"alertmanager payload: {alert_data}")
|
logging.debug(f"alertmanager payload: {alert_data}")
|
||||||
|
externalURL = alert_data.get("externalURL")
|
||||||
for alert in alert_data["alerts"]:
|
for alert in alert_data["alerts"]:
|
||||||
|
alertname = alert["labels"]["alertname"]
|
||||||
title = alert["labels"]["alertname"]
|
title = alert["labels"]["alertname"]
|
||||||
summary = alert["annotations"].get("summary")
|
summary = alert["annotations"].get("summary")
|
||||||
description = alert["annotations"].get("description")
|
description = alert["annotations"].get("description")
|
||||||
|
|
@ -70,6 +72,10 @@ def prometheus_alert_to_markdown(
|
||||||
dashboardURL = alert.get("dashboardURL")
|
dashboardURL = alert.get("dashboardURL")
|
||||||
silenceURL = alert.get("silenceURL")
|
silenceURL = alert.get("silenceURL")
|
||||||
actions = []
|
actions = []
|
||||||
|
if not silenceURL and externalURL:
|
||||||
|
silence_filter = f"alertname%3D%22{alertname}%22"
|
||||||
|
silence_filter = "{" + silence_filter + "}"
|
||||||
|
silenceURL = f"{externalURL}/#/silences/new?filter={silence_filter}"
|
||||||
if silenceURL:
|
if silenceURL:
|
||||||
actions.append(f"[🔕 Mute]({silenceURL})")
|
actions.append(f"[🔕 Mute]({silenceURL})")
|
||||||
if runbookURL:
|
if runbookURL:
|
||||||
|
|
|
||||||
|
|
@ -69,4 +69,6 @@ def test_alertmanager():
|
||||||
and "webserver.example.com" in formatted
|
and "webserver.example.com" in formatted
|
||||||
and "Instance webserver.example.com down" in formatted
|
and "Instance webserver.example.com down" in formatted
|
||||||
and "critical" in formatted
|
and "critical" in formatted
|
||||||
|
and "https://alert.example/#/silences/new?filter={alertname%3D%22InstanceDown%22}"
|
||||||
|
in formatted
|
||||||
)
|
)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue