96 lines
3.7 KiB
Python
96 lines
3.7 KiB
Python
# -*- coding: utf-8 -*-
|
|
"""Read-only anomaly inventory — no config/switch changes."""
|
|
from __future__ import annotations
|
|
|
|
import json
|
|
import sys
|
|
import http.cookiejar
|
|
import urllib.request
|
|
|
|
import paramiko
|
|
|
|
sys.stdout.reconfigure(encoding="utf-8", errors="replace")
|
|
|
|
|
|
def call(base, path, opener=None, timeout=40):
|
|
req = urllib.request.Request(f"{base}{path}", headers={"Content-Type": "application/json"})
|
|
op = opener or urllib.request.build_opener()
|
|
with op.open(req, timeout=timeout) as r:
|
|
return json.loads(r.read().decode())
|
|
|
|
|
|
def login(base):
|
|
cj = http.cookiejar.CookieJar()
|
|
op = urllib.request.build_opener(urllib.request.HTTPCookieProcessor(cj))
|
|
data = json.dumps({"username": "hackrobot", "password": "Xiao4669805@"}).encode()
|
|
req = urllib.request.Request(
|
|
f"{base}/api/auth/login", data=data, method="POST", headers={"Content-Type": "application/json"}
|
|
)
|
|
op.open(req, timeout=25)
|
|
return op
|
|
|
|
|
|
def ssh(host, port, user, pw, sudo=False):
|
|
c = paramiko.SSHClient()
|
|
c.set_missing_host_key_policy(paramiko.AutoAddPolicy())
|
|
c.connect(host, port, user, pw, timeout=40, allow_agent=False, look_for_keys=False)
|
|
|
|
def run(cmd, t=60):
|
|
if sudo:
|
|
cmd = f"echo '{pw}' | sudo -S -p '' bash -lc {repr(cmd)}"
|
|
_, o, e = c.exec_command(cmd, timeout=t)
|
|
return (o.read() + e.read()).decode("utf-8", "replace")
|
|
|
|
return c, run
|
|
|
|
|
|
for base in ["https://dylive.nomadro.com", "https://dy.nomadro.com"]:
|
|
print(f"\n===== {base} =====")
|
|
op = login(base)
|
|
h = call(base, "/api/health", op)
|
|
print("health", {
|
|
"yt": (h.get("youtube") or {}).get("ok"),
|
|
"yt_err": (h.get("youtube") or {}).get("error"),
|
|
"pb": (h.get("pocketbase") or {}).get("ok"),
|
|
"pb_err": (h.get("pocketbase") or {}).get("error"),
|
|
"s3": h.get("s3"),
|
|
"ytmon": h.get("youtube_monitor"),
|
|
"shorts_run": (h.get("shorts") or {}).get("running"),
|
|
"monitor": (h.get("monitor") or {}).get("running"),
|
|
})
|
|
try:
|
|
pb = call(base, "/api/pb/health", op)
|
|
print("pb_health", {k: pb.get(k) for k in ("ok", "in_sync", "max_abs_delta")})
|
|
except Exception as ex:
|
|
print("pb_health ERR", ex)
|
|
shorts = call(base, "/api/shorts/status", op)
|
|
print("shorts_switch_observe_only", shorts.get("enabled"), "running", shorts.get("running"), "err", shorts.get("last_error"))
|
|
yt = call(base, "/api/youtube-monitor/status", op)
|
|
print("yt_svc", yt.get("youtube_svc"))
|
|
live = call(base, "/api/youtube/live-map", op, timeout=90)
|
|
print("live", live.get("live_count"), live.get("source"))
|
|
|
|
print("\n===== VPS units =====")
|
|
v, vr = ssh("107.173.30.245", 22, "root", "Xiao4669805")
|
|
print(vr(
|
|
"systemctl is-active douyinweb-api douyinweb-yt douyinweb-pb douyinweb-web; "
|
|
"/opt/douyinWEB/pb/pocketbase --version 2>/dev/null; "
|
|
"curl -sS -m 3 http://127.0.0.1:8092/api/health; echo; "
|
|
"curl -sS -m 3 http://127.0.0.1:8020/health; echo; "
|
|
"grep -n '_pulse\\|youtube_monitor\\|detail=1' /opt/douyinWEB/backend/app/main.py | head -15; "
|
|
"grep -n 'admins/auth\\|_superusers' /opt/douyinWEB/backend/app/pb_sync.py | head -10"
|
|
))
|
|
v.close()
|
|
|
|
print("\n===== PHYS units =====")
|
|
p, pr = ssh("107.173.30.245", 4014, "eric", "4669805", sudo=True)
|
|
print(pr(
|
|
"systemctl is-active douyinweb-api douyinweb-yt douyinweb-pb douyinweb-web douyinweb-s3; "
|
|
"ls -la /opt/douyinWEB/pb/pocketbase 2>/dev/null; file /opt/douyinWEB/pb/pocketbase 2>/dev/null; "
|
|
"/opt/douyinWEB/pb/pocketbase --version 2>/dev/null; "
|
|
"systemctl status douyinweb-pb --no-pager -l | head -20; "
|
|
"curl -sS -m 3 http://127.0.0.1:8092/api/health 2>&1 | head -c 200; echo; "
|
|
"curl -sS -m 3 http://127.0.0.1:8020/health; echo"
|
|
))
|
|
p.close()
|