# -*- coding: utf-8 -*- """Full web business health snapshot on server.""" import json import paramiko HOST = "107.173.30.245" c = paramiko.SSHClient() c.set_missing_host_key_policy(paramiko.AutoAddPolicy()) c.connect(HOST, 22, "root", "Xiao4669805", timeout=30, allow_agent=False, look_for_keys=False) SCRIPT = r""" import json, subprocess, urllib.request, ssl ctx = ssl.create_default_context() SITES = [ ("dylive.nomadro.com/login", "DouyinWEB"), ("dylive.nomadro.com/api/health", "DouyinWEB API"), ("nomadro.live/", "TikTok Promo"), ("x.nomadro.com/", "XAuto"), ("wx.nomadro.com/", "HackRobot"), ("book.nomadro.com/", "Robook"), ("nomadro.com/", "Nomadro"), ("portal.nomadro.com/", "Nomadro Portal"), ("umami.nomadro.com/api/heartbeat", "Umami"), ("ntfy.nomadro.com/v1/health", "ntfy"), ("s3.nomadro.com/", "S3"), ] SERVICES = [ "caddy", "douyinweb-api", "douyinweb-web", "douyinweb-pb", "tiktok-promo-backend", "tiktok-promo-web", "xauto-web", "hackrobot-web", "pocketbase", "robook-web", ] print("=== systemd ===") for svc in SERVICES: r = subprocess.run(["systemctl", "is-active", svc], capture_output=True, text=True) st = (r.stdout or r.stderr or "").strip() mark = "OK" if st == "active" else ("SKIP" if st == "inactive" else "FAIL") print(f"{mark}\t{svc}\t{st}") print("\n=== docker ===") r = subprocess.run(["docker", "ps", "--format", "{{.Names}}\t{{.Status}}"], capture_output=True, text=True) for line in (r.stdout or "").strip().splitlines(): name, _, status = line.partition("\t") ok = "Up" in status print(("OK" if ok else "FAIL") + "\t" + name + "\t" + status) print("\n=== HTTPS probe ===") for path, label in SITES: url = "https://" + path try: req = urllib.request.Request(url, method="GET", headers={"User-Agent": "healthcheck/1.0"}) with urllib.request.urlopen(req, timeout=15, context=ctx) as resp: code = resp.status mark = "OK" if code < 500 else "FAIL" print(f"{mark}\t{label}\tHTTP {code}\t{url}") except Exception as e: err = str(e)[:80] print(f"FAIL\t{label}\t{err}\t{url}") print("\n=== DouyinWEB workers ===") try: with urllib.request.urlopen("http://127.0.0.1:8014/api/health", timeout=10) as resp: data = json.loads(resp.read().decode()) for k in ("monitor", "yt_monitor", "shorts", "tiktok", "x_clips", "yt_long"): v = data.get(k) or {} if isinstance(v, dict): running = v.get("running", v.get("enabled", "?")) err = (v.get("last_error") or "")[:60] print(f" {k}: running={running} err={err}") else: print(f" {k}: {v}") print(" s3:", data.get("s3")) except Exception as e: print(" health error:", e) print("\n=== kv flags ===") import sqlite3 conn = sqlite3.connect("/opt/douyinWEB/backend/data/monitor.db") for key in ("monitor_enabled", "shorts_enabled", "yt_long_enabled", "tiktok_enabled", "yt_monitor_enabled"): row = conn.execute("SELECT value FROM kv_settings WHERE key=?", (key,)).fetchone() print(f" {key}={row[0] if row else '?'}") row = conn.execute("SELECT COUNT(*) FROM shorts_channels WHERE enabled=1 AND oauth_ok=1").fetchone() bad = conn.execute("SELECT COUNT(*) FROM shorts_channels WHERE enabled=1 AND (oauth_ok IS NULL OR oauth_ok=0)").fetchone() print(f" shorts_oauth: ok={row[0]} bad={bad[0]}") conn.close() """ sftp = c.open_sftp() with sftp.file("/tmp/web_health.py", "w") as f: f.write(SCRIPT) sftp.close() _, o, e = c.exec_command("python3 /tmp/web_health.py", timeout=180) print(o.read().decode("utf-8", "replace")) err = e.read().decode("utf-8", "replace").strip() if err: print("STDERR:", err[:500]) c.close()