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
|
Converts a prometheus alert json to markdown
|
||||||
"""
|
"""
|
||||||
messages = []
|
messages = []
|
||||||
known_labels = ["alertname", "instance", "job"]
|
ignore_labels = ["grafana_folder", "alertname"]
|
||||||
for alert in alert_data["alerts"]:
|
for alert in alert_data["alerts"]:
|
||||||
title = (
|
title = (
|
||||||
alert["annotations"]["description"]
|
alert["annotations"]["description"]
|
||||||
|
|
@ -34,17 +34,13 @@ def prometheus_alert_to_markdown(
|
||||||
plain = f"{status}: {title}"
|
plain = f"{status}: {title}"
|
||||||
header_str = f"{status.upper()}[{status}]"
|
header_str = f"{status.upper()}[{status}]"
|
||||||
formatted = f"<strong><font color={color}>{header_str}</font></strong>: [{title}]({generatorURL})"
|
formatted = f"<strong><font color={color}>{header_str}</font></strong>: [{title}]({generatorURL})"
|
||||||
for label_name in known_labels:
|
for label_name, label_value in alert["labels"].items():
|
||||||
try:
|
if label_name.startswith("__"):
|
||||||
plain += "\n* **{0}**: {1}".format(
|
continue
|
||||||
label_name.capitalize(), alert["labels"][label_name]
|
if label_name in ignore_labels:
|
||||||
)
|
continue
|
||||||
formatted += "\n* **{0}**: {1}".format(
|
plain += "\n* **{0}**: {1}".format(label_name.capitalize(), label_value)
|
||||||
label_name.capitalize(), alert["labels"][label_name]
|
formatted += "\n* **{0}**: {1}".format(label_name.capitalize(), label_value)
|
||||||
)
|
|
||||||
except Exception as e:
|
|
||||||
logging.error("error parsing labels", exc_info=e)
|
|
||||||
pass
|
|
||||||
messages.append((plain, formatted))
|
messages.append((plain, formatted))
|
||||||
return messages
|
return messages
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue