Initial commit from Martins Github

This commit is contained in:
Jake Kasper
2026-04-23 13:50:31 -05:00
parent 488a0d01ef
commit 3228db3097
30 changed files with 4377 additions and 1 deletions

View File

@@ -0,0 +1,29 @@
"""Alertmanager client."""
import httpx
from app.config import ALERTMANAGER_URL
_BASE = ALERTMANAGER_URL.rstrip("/")
async def get_alerts() -> list:
"""Return normalised list of active alerts from Alertmanager."""
try:
async with httpx.AsyncClient(timeout=5) as client:
r = await client.get(f"{_BASE}/api/v2/alerts", params={"active": "true", "silenced": "false"})
r.raise_for_status()
raw = r.json()
except Exception:
return []
alerts = []
for a in raw:
labels = a.get("labels", {})
annotations = a.get("annotations", {})
alerts.append({
"name": labels.get("alertname", "Unknown"),
"severity": labels.get("severity", "warning"),
"instance": labels.get("instance", ""),
"summary": annotations.get("summary", annotations.get("description", "")),
})
return alerts