Add WeCom machine name for multi-node push labels.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
dekun
2026-07-30 17:28:32 +08:00
parent 021b0d0a22
commit 8ceb521049
6 changed files with 62 additions and 5 deletions
+24 -1
View File
@@ -55,6 +55,18 @@ def wecom_webhook_url() -> str:
return ""
def wecom_machine_name() -> str:
"""多机推送区分用的机器名(设置页 / WECOM_MACHINE_NAME)。"""
s = get_settings()
name = (getattr(s, "wecom_machine_name", None) or "").strip()
if name:
return name[:64]
try:
return (get_db().get_setting("wecom_machine_name", "") or "").strip()[:64]
except Exception:
return ""
def venue_label() -> str | None:
"""实盘时返回「实盘·交易所」;SIM 不展示盘口标签。"""
s = get_settings()
@@ -74,13 +86,21 @@ def venue_label() -> str | None:
def build_markdown(*, tag: str, title: str, lines: list[str] | None = None) -> str:
body = "\n".join(f"> {ln}" if not ln.startswith(">") else ln for ln in (lines or []))
machine = wecom_machine_name()
venue = venue_label()
head = f"## 【{venue}{title}" if venue else f"## {title}"
prefix_parts: list[str] = []
if machine:
prefix_parts.append(f"{machine}")
if venue:
prefix_parts.append(f"{venue}")
head = f"## {''.join(prefix_parts)}{title}"
parts = [
head,
f"> **标识**: `{tag}`",
f"> **时间**: {time.strftime('%Y-%m-%d %H:%M:%S')}",
]
if machine:
parts.append(f"> **机器**: {machine}")
if body:
parts.append("")
parts.append(body)
@@ -216,7 +236,10 @@ def notify_fault(*, title: str, detail: str, dedupe_key: str | None = None) -> N
def notify_test() -> tuple[bool, str]:
venue = venue_label()
machine = wecom_machine_name()
lines = ["企业微信通知已连通。"]
if machine:
lines.append(f"机器名称: **{machine}**")
if venue:
lines.append(f"当前盘口标签: **{venue}**")
content = build_markdown(