From 7f3e585d6dcb0fbcbcd2e5f2fd590c28d5e60833 Mon Sep 17 00:00:00 2001 From: OG T Date: Sun, 12 Apr 2026 19:22:35 +0800 Subject: [PATCH] =?UTF-8?q?fix(webhooks):=20alertmanager=20handler=20?= =?UTF-8?q?=E2=80=94=20alert=5Ftype=20=E8=B6=85=E7=AF=84=E5=9C=8D=E6=94=B9?= =?UTF-8?q?=E7=82=BA=20custom?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit AlertPayload.alert_type 只接受 8 個 Literal 值 ALERTNAME_TO_TYPE 映射回傳 host_cpu/backup_failure 等不在白名單 → ValidationError 修法:凡不在 Literal 白名單的 alert_type 一律 fallback 為 "custom" Co-Authored-By: Claude Sonnet 4.6 --- apps/api/src/api/v1/webhooks.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/apps/api/src/api/v1/webhooks.py b/apps/api/src/api/v1/webhooks.py index e7313538..dc4deef2 100644 --- a/apps/api/src/api/v1/webhooks.py +++ b/apps/api/src/api/v1/webhooks.py @@ -1156,7 +1156,14 @@ async def alertmanager_webhook( ) # I1 整合 ADR-064 Rule Engine 2026-04-11: YAML 規則動態推斷,ALERTNAME_TO_TYPE 為 fallback + # 2026-04-12 ogt: AlertPayload.alert_type 只接受 8 個 Literal,超範圍的改為 "custom" + _ALERT_TYPE_ALLOWED = { + "k8s_node_failure", "k8s_pod_crash", "db_connection_timeout", "service_404", + "high_cpu", "high_memory", "disk_full", "ssl_expiry", "custom", + } alert_type = get_incident_type(alertname) + if alert_type not in _ALERT_TYPE_ALLOWED: + alert_type = "custom" # ADR-073 Phase 2-2: 早期分診 — 在 LLM 前決定 alert_category + notification_type # 2026-04-12 ogt: 防止 HostBackupFailed 等被誤路由到 K8s executor