fix(awooop): persist signal metadata and auto-repair prestate
This commit is contained in:
@@ -17,35 +17,7 @@ sys.path.insert(0, "/app")
|
||||
from sqlalchemy import text
|
||||
|
||||
from src.db.base import get_db_context
|
||||
|
||||
|
||||
def _classify_alert(alertname: str, severity: str) -> tuple[str, str]:
|
||||
"""Python 版分類邏輯,與 classify_alert_early() 保持一致 (ADR-075 更新)"""
|
||||
alertname_lower = alertname.lower()
|
||||
if alertname in ("ConfigurationDrift", "KubeConfigDrift"):
|
||||
return "config_drift", "TYPE-4D"
|
||||
if severity in ("info", "none"):
|
||||
return "info", "TYPE-1"
|
||||
if "watchdog" in alertname_lower or alertname in ("Heartbeat",):
|
||||
return "backup", "TYPE-1"
|
||||
# ADR-075 新增: SecOps 優先
|
||||
if any(alertname.startswith(p) for p in ("UnauthorizedSSH", "KubeAudit", "CVECritical", "WAFAttack", "PodAbnormal", "SecurityBreach")):
|
||||
return "secops", "TYPE-5S"
|
||||
# ADR-075 新增: Flywheel/META
|
||||
if alertname in ("AutoRepairLowSuccessRate", "PermanentFixRequired") or any(
|
||||
alertname.startswith(p) for p in ("Flywheel", "MCPProvider", "OllamaDown", "NemotronDown")
|
||||
):
|
||||
return "flywheel_health", "TYPE-8M"
|
||||
# ADR-075 新增: Business/FinOps
|
||||
if any(alertname.startswith(p) for p in ("AITokenCost", "GeminiAPIError", "SLOBurn", "APIErrorBudget", "MomoScraper", "ScraperSuccess")):
|
||||
return "business", "TYPE-6B"
|
||||
if alertname.startswith(("Docker", "Host")):
|
||||
return "infrastructure", "TYPE-3"
|
||||
if alertname.startswith(("Kube", "Pod", "Deploy", "Node", "Velero", "ArgoCD")):
|
||||
return "kubernetes", "TYPE-3"
|
||||
if alertname.startswith(("Postgres", "Redis")):
|
||||
return "database", "TYPE-3"
|
||||
return "general", "TYPE-3"
|
||||
from src.services.incident_service import classify_alert_early
|
||||
|
||||
|
||||
async def main() -> None:
|
||||
@@ -95,9 +67,10 @@ async def main() -> None:
|
||||
|
||||
updated = 0
|
||||
for row in rows:
|
||||
alert_category, notification_type = _classify_alert(
|
||||
alert_category, notification_type = classify_alert_early(
|
||||
alertname=row.alertname or "",
|
||||
severity=row.severity or "warning",
|
||||
labels={},
|
||||
)
|
||||
await db.execute(text("""
|
||||
UPDATE incidents
|
||||
@@ -123,7 +96,7 @@ async def main() -> None:
|
||||
FROM incidents
|
||||
"""))
|
||||
f = final_r.fetchone()
|
||||
print(f"\n最終 NULL 統計:")
|
||||
print("\n最終 NULL 統計:")
|
||||
print(f" alertname NULL: {f.alertname_null}")
|
||||
print(f" notification_type NULL: {f.notification_type_null}")
|
||||
print(f" alert_category NULL: {f.alert_category_null}")
|
||||
|
||||
Reference in New Issue
Block a user