feat(alert_helper): notify同时写broadcast_messages(deploy_guard等告警进统一消息源)

This commit is contained in:
xxm
2026-08-22 10:18:25 +08:00
parent 2cc8341dcb
commit fb5a1adcec
+15
View File
@@ -113,6 +113,21 @@ def notify(category, body, level=INFO):
body = "\n".join(lines[:ACTION_MAX_LINES]) + f"\n…(共{len(lines)}行)"
prefix = f"🚨【MoFin·{category}"
# 写入 broadcast_messages(统一消息源,告警类)
try:
from messenger import _classify, DB
import sqlite3 as _sq3
from datetime import datetime as _dt
_cat = "system_error" if level == ACTION else _classify(category, body)
_conn = _sq3.connect(DB, timeout=30)
_conn.execute(
"INSERT INTO broadcast_messages (ts, category, title, content, source) VALUES (?,?,?,?,?)",
(_dt.now().isoformat(), _cat, f"MoFin·{category}", body, category))
_conn.commit()
_conn.close()
except Exception:
pass
try:
_send(f"{prefix}\n{body}")
except Exception as e: