Add actions and more data
This commit is contained in:
parent
4c5a33d72f
commit
63b351771a
2 changed files with 27 additions and 12 deletions
|
|
@ -30,11 +30,9 @@ def prometheus_alert_to_markdown(
|
||||||
|
|
||||||
logging.debug(f"alertmanager payload: {alert_data}")
|
logging.debug(f"alertmanager payload: {alert_data}")
|
||||||
for alert in alert_data["alerts"]:
|
for alert in alert_data["alerts"]:
|
||||||
title = (
|
title = alert["labels"]["alertname"]
|
||||||
alert["annotations"]["description"]
|
summary = alert["annotations"].get("summary")
|
||||||
if hasattr(alert["annotations"], "description")
|
description = alert["annotations"].get("description")
|
||||||
else alert["annotations"]["summary"]
|
|
||||||
)
|
|
||||||
logging.debug(f"processing alert: '{title}'")
|
logging.debug(f"processing alert: '{title}'")
|
||||||
labels = alert.get("labels", {})
|
labels = alert.get("labels", {})
|
||||||
severity = labels.get("severity", "unknown")
|
severity = labels.get("severity", "unknown")
|
||||||
|
|
@ -46,14 +44,12 @@ def prometheus_alert_to_markdown(
|
||||||
|
|
||||||
plain = f"{status.upper()}[{severity}]: {title}"
|
plain = f"{status.upper()}[{severity}]: {title}"
|
||||||
header_str = f"{status.upper()}[{severity}]"
|
header_str = f"{status.upper()}[{severity}]"
|
||||||
url = alert.get("generatorURL")
|
|
||||||
if url and url != "":
|
|
||||||
title_linked = f"[{title}]({url})"
|
|
||||||
else:
|
|
||||||
title_linked = title
|
|
||||||
formatted = (
|
formatted = (
|
||||||
f"<strong><font color={color}>{header_str}</font></strong>: {title_linked}"
|
f"<strong><font color={color}>{header_str}</font></strong>: {title}"
|
||||||
)
|
)
|
||||||
|
if summary:
|
||||||
|
formatted += f" - {summary}"
|
||||||
|
plain += f" - {summary}"
|
||||||
label_strings = []
|
label_strings = []
|
||||||
for label_name, label_value in labels.items():
|
for label_name, label_value in labels.items():
|
||||||
logging.debug(f"got label: {label_name} = {label_value}")
|
logging.debug(f"got label: {label_name} = {label_value}")
|
||||||
|
|
@ -64,7 +60,25 @@ def prometheus_alert_to_markdown(
|
||||||
label_strings.append((f"**{label_name.capitalize()}**: {label_value}"))
|
label_strings.append((f"**{label_name.capitalize()}**: {label_value}"))
|
||||||
labels_final = ", ".join(label_strings)
|
labels_final = ", ".join(label_strings)
|
||||||
plain += f" \n{labels_final}"
|
plain += f" \n{labels_final}"
|
||||||
|
if description:
|
||||||
|
formatted += f"<br/>Description: {description}"
|
||||||
|
plain += f" \n{description}"
|
||||||
|
|
||||||
formatted += f"<br/>{labels_final}"
|
formatted += f"<br/>{labels_final}"
|
||||||
|
generatorURL = alert.get("generatorURL")
|
||||||
|
runbookURL = alert["annotations"].get("runbook_url")
|
||||||
|
dashboardURL = alert.get("dashboardURL")
|
||||||
|
silenceURL = alert.get("silenceURL")
|
||||||
|
actions = []
|
||||||
|
if silenceURL:
|
||||||
|
actions.append(f"[🔕 Mute]({silenceURL})")
|
||||||
|
if runbookURL:
|
||||||
|
actions.append(f"[📗 Runbook]({runbookURL})")
|
||||||
|
if dashboardURL:
|
||||||
|
actions.append(f"[📈 Dashboard]({dashboardURL})")
|
||||||
|
if generatorURL:
|
||||||
|
actions.append(f"[🔍 Inspect]({generatorURL})")
|
||||||
|
formatted += "<br/>" + " | ".join(actions)
|
||||||
messages.append((plain, formatted))
|
messages.append((plain, formatted))
|
||||||
return messages
|
return messages
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -55,11 +55,12 @@ def test_alertmanager():
|
||||||
plain, formatted = r[0]
|
plain, formatted = r[0]
|
||||||
|
|
||||||
print(formatted)
|
print(formatted)
|
||||||
|
|
||||||
assert (
|
assert (
|
||||||
"FIRING" in plain
|
"FIRING" in plain
|
||||||
and "Instance" in plain
|
and "Instance" in plain
|
||||||
and "webserver.example.com" in plain
|
and "webserver.example.com" in plain
|
||||||
and "Instance webserver.example.com down" in plain
|
and "THIS IS A TEST" in plain
|
||||||
and "critical" in plain
|
and "critical" in plain
|
||||||
)
|
)
|
||||||
assert (
|
assert (
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue