From 9fca8185a5c71b4b855718df569970bde6291ca4 Mon Sep 17 00:00:00 2001 From: hmo Date: Sun, 19 Jul 2026 08:18:54 +0800 Subject: [PATCH] fix: monitor endpoint checks Windows schtasks via SSH instead of Linux systemd/crontab --- gateway/scripts/dashboard.py | 29 +++++++++++++----------- gateway/scripts/templates/dashboard.html | 2 +- 2 files changed, 17 insertions(+), 14 deletions(-) diff --git a/gateway/scripts/dashboard.py b/gateway/scripts/dashboard.py index c830caa..05b37f9 100644 --- a/gateway/scripts/dashboard.py +++ b/gateway/scripts/dashboard.py @@ -844,22 +844,25 @@ def api_monitor(): status = "error" result["tasks"].append({"name": name, "status": status}) else: - # Linux: 检查 systemd timer(如已部署)或 crontab + # Linux: SSH 到 Windows 查 schtasks + win_host = os.environ.get("WINDOWS_HOST", "192.168.1.16") for name in expected_tasks: try: - r = subprocess.run(["systemctl", "list-timers", "--all", "--no-pager"], - capture_output=True, text=True, timeout=5) - if name in r.stdout: - result["tasks"].append({"name": name, "status": "timer_ok"}) - else: - # 查 crontab - r2 = subprocess.run(["crontab", "-l"], capture_output=True, text=True, timeout=5) - if name in r2.stdout: - result["tasks"].append({"name": name, "status": "cron_ok"}) + r = subprocess.run( + ["ssh", "-o", "StrictHostKeyChecking=no", "-o", "ConnectTimeout=5", + "-o", "BatchMode=yes", f"hmo@{win_host}", + f"schtasks /Query /TN {name} /FO CSV /NH"], + capture_output=True, text=True, timeout=10 + ) + if r.returncode == 0 and name in r.stdout: + if "就绪" in r.stdout or "Ready" in r.stdout or "Running" in r.stdout: + result["tasks"].append({"name": name, "status": "schtasks_ok"}) else: - result["tasks"].append({"name": name, "status": "not_deployed"}) - except: - result["tasks"].append({"name": name, "status": "not_deployed", "note": "无systemd/cron"}) + result["tasks"].append({"name": name, "status": "schtasks_unknown", "raw": r.stdout.strip()}) + else: + result["tasks"].append({"name": name, "status": "not_deployed"}) + except Exception as e: + result["tasks"].append({"name": name, "status": "not_deployed", "note": f"SSH到Windows失败: {str(e)[:60]}"}) return jsonify(result) diff --git a/gateway/scripts/templates/dashboard.html b/gateway/scripts/templates/dashboard.html index fba63a2..cd76590 100644 --- a/gateway/scripts/templates/dashboard.html +++ b/gateway/scripts/templates/dashboard.html @@ -263,7 +263,7 @@ async function fHealth(){try{ h+='

定时任务

'; for(var i=0;i';