fix(alerts): tell informational alerts from real stand-downs by type
This commit is contained in:
+22
-2
@@ -5,6 +5,18 @@ from typing import Any
|
|||||||
|
|
||||||
LEVEL_ICON = {"OK": "✅", "WARNING": "🟠", "CRITICAL": "🔴"}
|
LEVEL_ICON = {"OK": "✅", "WARNING": "🟠", "CRITICAL": "🔴"}
|
||||||
|
|
||||||
|
INFORMATIONAL = frozenset(
|
||||||
|
{
|
||||||
|
"StackImageUpdateAvailable",
|
||||||
|
"DeploymentImageUpdateAvailable",
|
||||||
|
"StackAutoUpdated",
|
||||||
|
"DeploymentAutoUpdated",
|
||||||
|
"ScheduleRun",
|
||||||
|
"Test",
|
||||||
|
"Custom",
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
def _gb(value: Any) -> str: # noqa: ANN401
|
def _gb(value: Any) -> str: # noqa: ANN401
|
||||||
try:
|
try:
|
||||||
@@ -87,12 +99,20 @@ def _describe(kind: str, d: dict) -> tuple[str, list[str]]: # noqa: C901, PLR09
|
|||||||
|
|
||||||
def format_alert(payload: dict) -> str:
|
def format_alert(payload: dict) -> str:
|
||||||
level = str(payload.get("level", "")).upper()
|
level = str(payload.get("level", "")).upper()
|
||||||
resolved = bool(payload.get("resolved")) or level == "OK"
|
|
||||||
data = payload.get("data") or {}
|
data = payload.get("data") or {}
|
||||||
kind = str(data.get("type") or "Unknown")
|
kind = str(data.get("type") or "Unknown")
|
||||||
inner = data.get("data") or {}
|
inner = data.get("data") or {}
|
||||||
|
|
||||||
icon = "✅" if resolved else LEVEL_ICON.get(level, "🔔")
|
informational = kind in INFORMATIONAL
|
||||||
|
resolved = bool(payload.get("resolved")) and not informational
|
||||||
|
|
||||||
|
if informational:
|
||||||
|
icon = "ℹ️"
|
||||||
|
elif resolved:
|
||||||
|
icon = "✅"
|
||||||
|
else:
|
||||||
|
icon = LEVEL_ICON.get(level, "🔔")
|
||||||
|
|
||||||
title, details = _describe(kind, inner if isinstance(inner, dict) else {})
|
title, details = _describe(kind, inner if isinstance(inner, dict) else {})
|
||||||
|
|
||||||
if resolved:
|
if resolved:
|
||||||
|
|||||||
Reference in New Issue
Block a user