From 9c8dde095115bf63ae91bbeff73dcab5da9bd7a0 Mon Sep 17 00:00:00 2001 From: OG T Date: Sun, 12 Apr 2026 21:02:55 +0800 Subject: [PATCH] =?UTF-8?q?fix(telegram):=20=E4=BF=AE=E5=BE=A9=20Incident?= =?UTF-8?q?=20=E7=84=A1=20title=20=E6=AC=84=E4=BD=8D=E5=B0=8E=E8=87=B4?= =?UTF-8?q?=E6=89=80=E6=9C=89=20Telegram=20=E6=8E=A8=E9=80=81=E5=A4=B1?= =?UTF-8?q?=E6=95=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 根因: _push_decision_to_telegram() 有兩處引用 incident.title, 但 Incident model 從來沒有此欄位,導致所有告警卡片推送都 拋 AttributeError,事件在 telegram_decision_push_failed 靜默失敗。 修法: - line 188: message 改用 signal annotation summary/description/alert_name - line 249: TYPE-1 title 改用 alertname label / signal.alert_name 影響: 自從 decision_manager 加入這兩行以來,所有 Telegram 通知都沒發出 (包含 TYPE-1 資訊通知和 TYPE-3 審批卡) Co-Authored-By: Claude Sonnet 4.6 --- apps/api/src/services/decision_manager.py | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/apps/api/src/services/decision_manager.py b/apps/api/src/services/decision_manager.py index 4ae43b85..fe7ac1af 100644 --- a/apps/api/src/services/decision_manager.py +++ b/apps/api/src/services/decision_manager.py @@ -182,10 +182,16 @@ async def _push_decision_to_telegram( try: from src.services.alert_rule_engine import match_rule as _match_rule _labels = incident.signals[0].labels if incident.signals else {} + # 2026-04-12 ogt: Incident 沒有 title 欄位,用 signal annotation summary + _sig_msg = ( + incident.signals[0].annotations.get("summary", "") or + incident.signals[0].annotations.get("description", "") or + incident.signals[0].alert_name + ) if incident.signals else "" _rule_resp = _match_rule({ "labels": _labels, "alert_type": _labels.get("alertname", target), - "message": incident.title or "", + "message": _sig_msg, "target_resource": target, "namespace": incident.signals[0].labels.get("namespace", "awoooi-prod") if incident.signals else "awoooi-prod", "severity": risk_level, @@ -244,9 +250,14 @@ async def _push_decision_to_telegram( if _notif_type == NotificationType.TYPE_1: # 純資訊通知 — 無按鈕 + # 2026-04-12 ogt: Incident 沒有 title 欄位,用 alertname + _info_title = ( + incident.signals[0].labels.get("alertname", "") or + incident.signals[0].alert_name + ) if incident.signals else "告警通知" tg_result = await gateway.send_info_notification( incident_id=incident.incident_id, - title=incident.title or "告警通知", + title=_info_title or "告警通知", message=reasoning[:200] if reasoning else description[:200], alertname=incident.signals[0].labels.get("alertname", "") if incident.signals else "", severity="info",