Add some debugging
This commit is contained in:
parent
bf8110010a
commit
7106564ff0
1 changed files with 13 additions and 2 deletions
|
|
@ -1,3 +1,4 @@
|
||||||
|
import logging
|
||||||
from typing import Any, Dict, List, Tuple
|
from typing import Any, Dict, List, Tuple
|
||||||
|
|
||||||
from fastapi import Request
|
from fastapi import Request
|
||||||
|
|
@ -26,12 +27,15 @@ def prometheus_alert_to_markdown(
|
||||||
"""
|
"""
|
||||||
messages = []
|
messages = []
|
||||||
ignore_labels = ["grafana_folder"]
|
ignore_labels = ["grafana_folder"]
|
||||||
|
|
||||||
|
logging.debug(f"alertmanager payload: {alert_data}")
|
||||||
for alert in alert_data["alerts"]:
|
for alert in alert_data["alerts"]:
|
||||||
title = (
|
title = (
|
||||||
alert["annotations"]["description"]
|
alert["annotations"]["description"]
|
||||||
if hasattr(alert["annotations"], "description")
|
if hasattr(alert["annotations"], "description")
|
||||||
else alert["annotations"]["summary"]
|
else alert["annotations"]["summary"]
|
||||||
)
|
)
|
||||||
|
logging.debug(f"processing alert: '{title}'")
|
||||||
labels = alert.get("labels", {})
|
labels = alert.get("labels", {})
|
||||||
severity = labels.get("severity", "unknown")
|
severity = labels.get("severity", "unknown")
|
||||||
status = alert.get("status", "unknown-status")
|
status = alert.get("status", "unknown-status")
|
||||||
|
|
@ -40,12 +44,19 @@ def prometheus_alert_to_markdown(
|
||||||
else:
|
else:
|
||||||
color = severity_colors.get(severity, COLOR_UNKNOWN)
|
color = severity_colors.get(severity, COLOR_UNKNOWN)
|
||||||
|
|
||||||
generatorURL = alert.get("generatorURL")
|
|
||||||
plain = f"{status.upper()}[{severity}]: {title}"
|
plain = f"{status.upper()}[{severity}]: {title}"
|
||||||
header_str = f"{status.upper()}[{severity}]"
|
header_str = f"{status.upper()}[{severity}]"
|
||||||
formatted = f"<strong><font color={color}>{header_str}</font></strong>: [{title}]({generatorURL})"
|
url = alert.get("generatorURL")
|
||||||
|
if url and url != "":
|
||||||
|
title_linked = f"[{title}]({url})"
|
||||||
|
else:
|
||||||
|
title_linked = title
|
||||||
|
formatted = (
|
||||||
|
f"<strong><font color={color}>{header_str}</font></strong>: {title_linked}"
|
||||||
|
)
|
||||||
label_strings = []
|
label_strings = []
|
||||||
for label_name, label_value in labels.items():
|
for label_name, label_value in labels.items():
|
||||||
|
logging.debug("got label: ", label_name, label_value)
|
||||||
if label_name.startswith("__"):
|
if label_name.startswith("__"):
|
||||||
continue
|
continue
|
||||||
if label_name in ignore_labels:
|
if label_name in ignore_labels:
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue