fix(webhooks): alertmanager handler — alert_type 超範圍改為 custom
Some checks failed
CD Pipeline / build-and-deploy (push) Has been cancelled

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 <noreply@anthropic.com>
This commit is contained in:
OG T
2026-04-12 19:22:35 +08:00
parent edb97fd29b
commit 7f3e585d6d

View File

@@ -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