fix(webhooks): 修正 OpenClawDecision 物件屬性存取
原錯誤: 'OpenClawDecision' object has no attribute 'get' 修正: 使用 Pydantic 模型屬性存取 (analysis_result.risk_level.value) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user