54 lines
1.8 KiB
Python
Executable File
54 lines
1.8 KiB
Python
Executable File
#!/usr/bin/env python3
|
|
"""Fallback-уведомление: если OpenClaw лёг — сказать семье, что секретарь недоступен."""
|
|
import json
|
|
import os
|
|
import subprocess
|
|
import time
|
|
import urllib.request
|
|
|
|
ROOM = "!puEdcZCc87kKoCm3mX5bbjrTS-Skv2XCZg7JJBKOMw0"
|
|
HS = "http://192.168.1.155:8008"
|
|
STATE = "/var/lib/openclaw-fallback.state"
|
|
|
|
|
|
def send(text):
|
|
tok = open("/root/.matrix-admin-token").read().strip()
|
|
txn = "fb-%d" % int(time.time() * 1000)
|
|
body = json.dumps({"msgtype": "m.text", "body": text}).encode()
|
|
url = "%s/_matrix/client/v3/rooms/%s/send/m.room.message/%s?access_token=%s" % (HS, ROOM, txn, tok)
|
|
r = urllib.request.Request(url, data=body, headers={"Content-Type": "application/json"}, method="PUT")
|
|
with urllib.request.urlopen(r, timeout=20) as resp:
|
|
return resp.status
|
|
|
|
|
|
def healthy():
|
|
try:
|
|
r = subprocess.run(["pct", "exec", "115", "--", "docker", "exec", "openclaw",
|
|
"node", "openclaw.mjs", "health"], capture_output=True, text=True, timeout=20)
|
|
out = (r.stdout or "") + (r.stderr or "")
|
|
return "Agents:" in out
|
|
except Exception:
|
|
return False
|
|
|
|
|
|
def main():
|
|
prev = "up"
|
|
try:
|
|
prev = open(STATE).read().strip()
|
|
except Exception:
|
|
pass
|
|
cur = "up" if healthy() else "down"
|
|
if cur != prev:
|
|
if cur == "down":
|
|
send("⚠️ **Секретарь временно недоступен.** Базовые команды hub-bots работают; "
|
|
"если срочно — напишите @secretary.")
|
|
else:
|
|
send("✅ Секретарь снова на связи.")
|
|
open(STATE, "w").write(cur)
|
|
print("state:", cur)
|
|
return 0
|
|
|
|
|
|
if __name__ == "__main__":
|
|
raise SystemExit(main())
|