fix: monitor endpoint checks Windows schtasks via SSH instead of Linux systemd/crontab
This commit is contained in:
@@ -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"})
|
||||
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:
|
||||
# 查 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"})
|
||||
result["tasks"].append({"name": name, "status": "schtasks_unknown", "raw": r.stdout.strip()})
|
||||
else:
|
||||
result["tasks"].append({"name": name, "status": "not_deployed"})
|
||||
except:
|
||||
result["tasks"].append({"name": name, "status": "not_deployed", "note": "无systemd/cron"})
|
||||
except Exception as e:
|
||||
result["tasks"].append({"name": name, "status": "not_deployed", "note": f"SSH到Windows失败: {str(e)[:60]}"})
|
||||
return jsonify(result)
|
||||
|
||||
|
||||
|
||||
@@ -263,7 +263,7 @@ async function fHealth(){try{
|
||||
h+='<div class=section><h2 style=margin-bottom:8px>定时任务</h2>';
|
||||
for(var i=0;i<mD.tasks.length;i++){var t=mD.tasks[i];
|
||||
var m=M[t.name]||{n:t.name};
|
||||
var tk=t.status==='ok'||t.status==='timer_ok'||t.status==='cron_ok';
|
||||
var tk=t.status==='ok'||t.status==='timer_ok'||t.status==='cron_ok'||t.status==='schtasks_ok';
|
||||
var tn=t.status==='not_deployed';
|
||||
h+='<div style="display:flex;align-items:center;gap:8px;padding:4px 8px;margin:2px 0">';
|
||||
h+='<span class="sd '+(tk?'g':tn?'y':'r')+'"></span>';
|
||||
|
||||
Reference in New Issue
Block a user