feat: 新增内网文件服务器离线监控,升级ERP报表导出插件适配新旧系统差异
1. 新增内网文件服务器心跳上报与离线监控功能:
- 为文件服务器添加周期心跳上报到中心机的能力
- 中心机新增文件服务器状态监控线程,超时自动判离线并钉钉告警管理员
- 新增数据库表存储文件服务器状态,提供管理端API查看在线状态
2. 修复ERP物料收发汇总报表插件:
- 调整插件版本到1.0.9,更新前端配置与UI适配新旧ERP系统
- 重构组织与仓库默认值逻辑,区分新版/旧版ERP的默认配置
- 统一所有场景下显式设置查询组织,移除旧版默认组织的兼容逻辑
- 新增代管仓仓库编码适配旧版系统
3. 优化文件服务器打包脚本路径,更新文档示例命令
This commit is contained in:
@@ -171,3 +171,50 @@ def _send_robot(title: str, text: str) -> None:
|
||||
log.warning("钉钉群通知被拒: %s", body)
|
||||
except Exception as e: # noqa: BLE001 通知失败不阻断业务
|
||||
log.warning("钉钉群通知异常: %s", e)
|
||||
|
||||
|
||||
# ==================== 内网文件服务器离线告警(中心机监控线程触发) ====================
|
||||
def _admin_names() -> list[str]:
|
||||
"""管理员名单(nickname 优先,其次 account),用于离线告警收件人。"""
|
||||
try:
|
||||
from controlplane.core.db import _db
|
||||
with _db() as conn:
|
||||
rows = conn.execute(
|
||||
"SELECT account, nickname FROM accounts WHERE is_admin = 1 ORDER BY id").fetchall()
|
||||
return [(r["nickname"] or r["account"] or "").strip() for r in rows if r]
|
||||
except Exception: # noqa: BLE001 取管理员失败按空处理,回退群机器人
|
||||
log.warning("取管理员名单失败,离线告警回退群机器人")
|
||||
return []
|
||||
|
||||
|
||||
def _work_fileserver_down(host: str, hostname: str, ip: str, last_seen: str) -> None:
|
||||
"""文件服务器离线告警:优先工作通知推给全部管理员,无人送达回退群机器人 webhook。"""
|
||||
title = "内网文件服务器下线告警"
|
||||
content = (
|
||||
f"> 服务:{hostname or '—'}\n\n"
|
||||
f"> 地址:{host}\n\n"
|
||||
f"> IP:{ip or '—'}\n\n"
|
||||
f"> 最后心跳:{last_seen or '—'}\n\n"
|
||||
"> 提示:执行机将无法下载大文件(壳子/Chrome 安装包),请尽快排查进程或网络;"
|
||||
"服务恢复后将自动解除告警")
|
||||
agent_id = (config.DINGTALK_AGENT_ID or "").strip()
|
||||
at = _dingtalk_topapi_token() if agent_id else ""
|
||||
sent_any = False
|
||||
if at:
|
||||
for name in _admin_names():
|
||||
if not name:
|
||||
continue
|
||||
uid = _userid_by_name(at, name)
|
||||
if uid and _send_work_to(at, agent_id, uid, title, content, status="error"):
|
||||
sent_any = True
|
||||
if not sent_any:
|
||||
log.warning("文件服务器离线告警:管理员工作通知均未送达,回退群机器人")
|
||||
if not sent_any:
|
||||
_send_robot(title, content)
|
||||
|
||||
|
||||
def notify_fileserver_down(host: str, hostname: str = "", ip: str = "",
|
||||
last_seen: str = "") -> None:
|
||||
"""内网文件服务器离线告警:推送钉钉给管理员(后台线程,失败不阻断监控)。"""
|
||||
threading.Thread(target=_work_fileserver_down,
|
||||
args=(host, hostname, ip, last_seen), daemon=True).start()
|
||||
|
||||
Reference in New Issue
Block a user