From 09d4e2a373fcda279874c11d6ec883bf770d49df Mon Sep 17 00:00:00 2001 From: OG T Date: Tue, 24 Mar 2026 22:11:39 +0800 Subject: [PATCH] =?UTF-8?q?fix(webhooks):=20=E4=BF=AE=E6=AD=A3=20OpenClawD?= =?UTF-8?q?ecision=20=E7=89=A9=E4=BB=B6=E5=B1=AC=E6=80=A7=E5=AD=98?= =?UTF-8?q?=E5=8F=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 原錯誤: 'OpenClawDecision' object has no attribute 'get' 修正: 使用 Pydantic 模型屬性存取 (analysis_result.risk_level.value) Co-Authored-By: Claude Opus 4.5 --- apps/api/src/api/v1/webhooks.py | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/apps/api/src/api/v1/webhooks.py b/apps/api/src/api/v1/webhooks.py index 4303efcc..710fcd1d 100644 --- a/apps/api/src/api/v1/webhooks.py +++ b/apps/api/src/api/v1/webhooks.py @@ -1193,12 +1193,13 @@ async def alertmanager_webhook( analysis_result, ai_provider, raw_response, signoz_metrics, signoz_trace_url = await openclaw.analyze_alert(alert_context) if analysis_result: - risk_level = analysis_result.get("risk_level", "medium") - action = analysis_result.get("action", "OBSERVE") - root_cause = analysis_result.get("root_cause", message) - estimated_downtime = analysis_result.get("estimated_downtime", "~30s") - primary_responsibility = analysis_result.get("primary_responsibility", "COLLAB") - confidence = analysis_result.get("confidence", 0.5) + # analysis_result 是 OpenClawDecision Pydantic 模型 + risk_level = analysis_result.risk_level.value # e.g., "low", "medium", "critical" + action = f"{analysis_result.action_title} | {analysis_result.kubectl_command}" + root_cause = analysis_result.description or message + estimated_downtime = analysis_result.blast_radius.estimated_downtime if analysis_result.blast_radius else "~30s" + primary_responsibility = analysis_result.primary_responsibility.value if hasattr(analysis_result, 'primary_responsibility') and analysis_result.primary_responsibility else "COLLAB" + confidence = analysis_result.confidence # 建立 ApprovalRecord approval = await service.create_approval( @@ -1211,7 +1212,7 @@ async def alertmanager_webhook( "alertname": alertname, "namespace": namespace, "message": message, - "ai_analysis": analysis_result, + "ai_analysis": analysis_result.model_dump(), # 轉換為字典 "ai_provider": ai_provider, }, fingerprint=fingerprint, @@ -1224,7 +1225,7 @@ async def alertmanager_webhook( risk_level=risk_level, resource_name=target_resource, root_cause=root_cause, - suggested_action=action, + suggested_action=analysis_result.suggested_action.value, # 使用 enum value estimated_downtime=estimated_downtime, hit_count=1, primary_responsibility=primary_responsibility,