32a1885f0d
支持随时暂停/恢复实时监测并保留槽位;TTL 到期自动暂停不占删槽;修复到期竞态导致空槽与唯一约束冲突;探针 parse_error 与中文错误;移除失败 snackbar。
62 lines
2.3 KiB
Python
62 lines
2.3 KiB
Python
"""Chinese user-facing messages for watch probe failures."""
|
||
|
||
from __future__ import annotations
|
||
|
||
_EXACT: dict[str, str] = {
|
||
"parse_error": "探针返回数据无法解析",
|
||
"psutil missing": "子机未安装 psutil(请执行 pip install psutil)",
|
||
"ssh_probe_failed": "SSH 探针脚本执行失败",
|
||
"SSH watch probe failed": "SSH 监测探针失败",
|
||
"SSH probe failed": "SSH 探针失败",
|
||
"timeout": "连接超时",
|
||
"探针失败": "探针失败",
|
||
"无 Agent 且 SSH 探针失败": "无 Agent 且 SSH 探针失败",
|
||
"服务器不存在": "服务器不存在",
|
||
}
|
||
|
||
|
||
def watch_probe_error_zh(error: str | None, *, status: str | None = None) -> str | None:
|
||
"""Map probe error text to Chinese for UI / audit display."""
|
||
if not error:
|
||
if status == "parse_error":
|
||
return "探针返回数据无法解析"
|
||
if status == "ssh_timeout":
|
||
return "SSH 连接超时"
|
||
if status == "ssh_auth":
|
||
return "SSH 认证失败"
|
||
if status == "no_cred":
|
||
return "需要 Agent 或 SSH 凭据"
|
||
if status == "redis_stale":
|
||
return "Agent 心跳已过期"
|
||
if status == "offline":
|
||
return "目标服务器离线或不可达"
|
||
return None
|
||
|
||
text = error.strip()
|
||
if text in _EXACT:
|
||
return _EXACT[text]
|
||
|
||
lower = text.lower()
|
||
if lower.startswith("parse_error"):
|
||
detail = text.split(":", 1)[1].strip() if ":" in text else ""
|
||
if detail in _EXACT:
|
||
return f"探针返回数据无法解析:{_EXACT[detail]}"
|
||
if detail:
|
||
return f"探针返回数据无法解析:{detail}"
|
||
return "探针返回数据无法解析"
|
||
|
||
if "timed out" in lower or lower.endswith("timeout"):
|
||
return f"SSH 连接超时:{text}"
|
||
if "permission denied" in lower or "authentication failed" in lower:
|
||
return f"SSH 认证失败:{text}"
|
||
if "psutil missing" in lower:
|
||
return "子机未安装 psutil(请执行 pip install psutil)"
|
||
if "ssh_probe_failed" in lower or "ssh watch probe failed" in lower:
|
||
return "SSH 探针脚本执行失败"
|
||
|
||
# Already Chinese or mixed — return as-is if contains CJK
|
||
if any("\u4e00" <= ch <= "\u9fff" for ch in text):
|
||
return text
|
||
|
||
return f"探针异常:{text}"
|