alertmanager: attach all labels except some
This commit is contained in:
parent
cd072d9e1b
commit
a7dc5b7177
1 changed files with 8 additions and 12 deletions
|
|
@ -14,7 +14,7 @@ def prometheus_alert_to_markdown(
|
|||
Converts a prometheus alert json to markdown
|
||||
"""
|
||||
messages = []
|
||||
known_labels = ["alertname", "instance", "job"]
|
||||
ignore_labels = ["grafana_folder", "alertname"]
|
||||
for alert in alert_data["alerts"]:
|
||||
title = (
|
||||
alert["annotations"]["description"]
|
||||
|
|
@ -34,17 +34,13 @@ def prometheus_alert_to_markdown(
|
|||
plain = f"{status}: {title}"
|
||||
header_str = f"{status.upper()}[{status}]"
|
||||
formatted = f"<strong><font color={color}>{header_str}</font></strong>: [{title}]({generatorURL})"
|
||||
for label_name in known_labels:
|
||||
try:
|
||||
plain += "\n* **{0}**: {1}".format(
|
||||
label_name.capitalize(), alert["labels"][label_name]
|
||||
)
|
||||
formatted += "\n* **{0}**: {1}".format(
|
||||
label_name.capitalize(), alert["labels"][label_name]
|
||||
)
|
||||
except Exception as e:
|
||||
logging.error("error parsing labels", exc_info=e)
|
||||
pass
|
||||
for label_name, label_value in alert["labels"].items():
|
||||
if label_name.startswith("__"):
|
||||
continue
|
||||
if label_name in ignore_labels:
|
||||
continue
|
||||
plain += "\n* **{0}**: {1}".format(label_name.capitalize(), label_value)
|
||||
formatted += "\n* **{0}**: {1}".format(label_name.capitalize(), label_value)
|
||||
messages.append((plain, formatted))
|
||||
return messages
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue