fix(adr075): drift 通知改用 send_drift_card,補齊所有呼叫點
All checks were successful
CD Pipeline / build-and-deploy (push) Successful in 14m13s
All checks were successful
CD Pipeline / build-and-deploy (push) Successful in 14m13s
- drift.py: 移除死碼 send_text(),改由 narrate_and_notify() 統一發卡片 - drift_narrator_service: _send_telegram() 改呼 send_drift_card() 帶四顆按鈕 - webhooks.py /alerts 路徑: 補傳 alert_category 啟用動態按鈕 Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -17,7 +17,6 @@ Drift Narrator Service - Phase 30
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import html
|
||||
from typing import TYPE_CHECKING
|
||||
|
||||
import httpx
|
||||
@@ -224,25 +223,30 @@ class DriftNarratorService:
|
||||
)
|
||||
|
||||
async def _send_telegram(self, report: "DriftReport", narrative: str) -> None:
|
||||
"""推送 Telegram 人話摘要卡"""
|
||||
"""
|
||||
推送 TYPE-4D Config Drift 卡片(ADR-075)
|
||||
|
||||
使用 send_drift_card() 取代舊 send_notification(),呈現結構化格式與操作按鈕。
|
||||
diff_summary = AI 研判(narrative) + 漂移詳情(前 8 筆)
|
||||
approval_id / incident_id 均使用 report_id(無需建立 ApprovalRequest)
|
||||
"""
|
||||
from src.services.telegram_gateway import get_telegram_gateway
|
||||
|
||||
severity_icon = "🔴" if report.high_count > 0 else "🟡"
|
||||
msg = (
|
||||
f"{severity_icon} <b>K8s 配置漂移</b>\n"
|
||||
f"Namespace: <code>{html.escape(report.namespace)}</code>\n"
|
||||
f"HIGH: {report.high_count} | MEDIUM: {report.medium_count}\n"
|
||||
f"\n"
|
||||
f"🤖 <b>AI 研判</b>\n"
|
||||
f"{html.escape(narrative)}\n"
|
||||
f"\n"
|
||||
f"📋 Report: <code>{html.escape(report.report_id)}</code>\n"
|
||||
f"<i>qwen2.5:7b-instruct | 免費本地推理</i>"
|
||||
diff_summary = (
|
||||
f"🤖 AI 研判\n{narrative}\n\n"
|
||||
f"漂移明細(HIGH: {report.high_count} | MEDIUM: {report.medium_count})\n"
|
||||
f"{self._format_drift_summary(report)}"
|
||||
)
|
||||
|
||||
try:
|
||||
tg = get_telegram_gateway()
|
||||
await tg.send_notification(msg[:4096])
|
||||
await tg.send_drift_card(
|
||||
incident_id=report.report_id,
|
||||
approval_id=report.report_id,
|
||||
resource_name=report.namespace,
|
||||
diff_summary=diff_summary[:500],
|
||||
detected_at="",
|
||||
)
|
||||
except Exception as e:
|
||||
logger.warning("drift_narrator_telegram_error", error=str(e))
|
||||
|
||||
|
||||
Reference in New Issue
Block a user