Add some debugging

This commit is contained in:
Abel Luck 2024-07-18 15:40:05 +02:00
parent bf8110010a
commit 7106564ff0

View file

@ -1,3 +1,4 @@
import logging
from typing import Any, Dict, List, Tuple
from fastapi import Request
@ -26,12 +27,15 @@ def prometheus_alert_to_markdown(
"""
messages = []
ignore_labels = ["grafana_folder"]
logging.debug(f"alertmanager payload: {alert_data}")
for alert in alert_data["alerts"]:
title = (
alert["annotations"]["description"]
if hasattr(alert["annotations"], "description")
else alert["annotations"]["summary"]
)
logging.debug(f"processing alert: '{title}'")
labels = alert.get("labels", {})
severity = labels.get("severity", "unknown")
status = alert.get("status", "unknown-status")
@ -40,12 +44,19 @@ def prometheus_alert_to_markdown(
else:
color = severity_colors.get(severity, COLOR_UNKNOWN)
generatorURL = alert.get("generatorURL")
plain = f"{status.upper()}[{severity}]: {title}"
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 = []
for label_name, label_value in labels.items():
logging.debug("got label: ", label_name, label_value)
if label_name.startswith("__"):
continue
if label_name in ignore_labels: