From e4070b2f86e2bfecff2f73042867e9958460160c Mon Sep 17 00:00:00 2001 From: OG T Date: Thu, 9 Apr 2026 12:29:48 +0800 Subject: [PATCH] =?UTF-8?q?fix(webhooks):=20=E8=A3=9C=20get=5Falert=5Foper?= =?UTF-8?q?ation=5Flog=5Frepository=20import=20=E5=85=A9=E8=99=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit alert_received_log_failed 錯誤原因:alertmanager_webhook 函數內 直接呼叫 get_alert_operation_log_repository() 但未在 local scope import, 導致 NameError 被 except 吞掉,ALERT_RECEIVED 事件無法記錄。 Co-Authored-By: Claude Sonnet 4.6 --- apps/api/src/api/v1/webhooks.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/apps/api/src/api/v1/webhooks.py b/apps/api/src/api/v1/webhooks.py index 9656ddfd..87f70ad3 100644 --- a/apps/api/src/api/v1/webhooks.py +++ b/apps/api/src/api/v1/webhooks.py @@ -1105,6 +1105,7 @@ async def alertmanager_webhook( # Q9: auto_repair flag — Rule=false 強制 HITL(不觸發自動修復背景任務) _can_auto_repair_by_rule = _alert_labels.get("auto_repair", "true").lower() == "true" try: + from src.repositories.alert_operation_log_repository import get_alert_operation_log_repository _op_log = get_alert_operation_log_repository() await _op_log.append( "ALERT_RECEIVED", @@ -1377,6 +1378,7 @@ async def alertmanager_webhook( ) else: # auto_repair=false → 記錄 GUARDRAIL_BLOCKED,不觸發自動修復 + from src.repositories.alert_operation_log_repository import get_alert_operation_log_repository _op_log_rule = get_alert_operation_log_repository() background_tasks.add_task( _op_log_rule.append,