mirror of
https://github.com/moan0s/alertbot.git
synced 2024-10-01 06:25:35 -04:00
Merge pull request #5 from pauvos/prom-alert-labels
Handle missing labels of prometheus alerts more gracefully
This commit is contained in:
commit
ab9625ea61
15
alertbot.py
15
alertbot.py
@ -162,14 +162,15 @@ def prometheus_alert_to_markdown(alert_data: dict) -> str:
|
|||||||
:return: Alert as fomatted markdown
|
:return: Alert as fomatted markdown
|
||||||
"""
|
"""
|
||||||
messages = []
|
messages = []
|
||||||
|
known_labels = ['alertname', 'instance', 'job']
|
||||||
for alert in alert_data["alerts"]:
|
for alert in alert_data["alerts"]:
|
||||||
message = (
|
title = alert['annotations']['description'] if hasattr(alert['annotations'], 'description') else alert['annotations']['summary']
|
||||||
f"""**{alert['status']}** {'💚' if alert['status'] == 'resolved' else '🔥'}: {alert['annotations']['description']}
|
message = f"""**{alert['status']}** {'💚' if alert['status'] == 'resolved' else '🔥'}: {title}"""
|
||||||
* **Alertname:** {alert["labels"]['alertname']}
|
for label_name in known_labels:
|
||||||
* **Instance:** {alert["labels"]['instance']}
|
try:
|
||||||
* **Job:** {alert["labels"]['job']}
|
message += "\n* **{0}**: {1}".format(label_name.capitalize(), alert["labels"][label_name])
|
||||||
"""
|
except:
|
||||||
)
|
pass
|
||||||
messages.append(message)
|
messages.append(message)
|
||||||
return messages
|
return messages
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user