douyinWEB/scripts/_audit_post_smoke.py
2026-09-13 22:10:49 -05:00

72 lines
2.8 KiB
Python

#!/usr/bin/env python3
"""Post-audit smoke: dy + dylive health, neko chrome, relay flags."""
from __future__ import annotations
import json
import sys
import time
import urllib.request
from http.cookiejar import CookieJar
import ssl
import paramiko
sys.stdout.reconfigure(encoding="utf-8", errors="replace")
CTX = ssl.create_default_context()
def ssh(host: str):
c = paramiko.SSHClient()
c.set_missing_host_key_policy(paramiko.AutoAddPolicy())
c.connect(host, 22, "root", "Xiao4669805", timeout=40, allow_agent=False, look_for_keys=False, banner_timeout=120)
return c
def run(c, cmd: str) -> str:
_i, o, e = c.exec_command(cmd, timeout=90)
return (o.read() + e.read()).decode("utf-8", "replace")
for label, host in (("dylive", "107.173.30.245"), ("dy", "108.174.50.68")):
print(f"\n## {label}", flush=True)
c = ssh(host)
print(run(c, r"""
set +e
free -m | head -2
systemctl is-active douyinweb-api douyinweb-web
curl -sS -m 10 -o /dev/null -w 'health:%{http_code}\n' http://127.0.0.1:8014/api/health
curl -sS -m 10 -o /dev/null -w 'youtube:%{http_code}\n' http://127.0.0.1:4015/youtube
docker ps --filter name=douyinweb-neko --format '{{.Names}} {{.Status}}' | sort -V
for n in $(docker ps --filter name=douyinweb-neko --format '{{.Names}}'); do
st=$(docker exec "$n" supervisorctl status google-chrome 2>/dev/null | awk '{print $1,$2}')
del=$(docker exec "$n" sh -c 'grep -c "//deleted" /proc/self/mountinfo' 2>/dev/null || echo 0)
echo "$n chrome=[$st] deleted_mount_hits=$del"
done
cd /opt/douyinWEB/backend
./.venv/bin/python - <<'PY'
from app import db
cfg=db.get_settings_map()
print('relay_enabled', cfg.get('youtube_relay_enabled'))
print('time_slot', cfg.get('youtube_relay_time_slot_mode'))
print('exclusive', cfg.get('youtube_relay_exclusive_live'))
PY
grep -n 'paused_exclusive' /opt/douyinWEB/backend/app/youtube_relay_status.py | head -2
grep -n 'time_slot_mode on but no time_slot' /opt/douyinWEB/backend/app/youtube_relay_pipeline.py | head -1
"""), flush=True)
c.close()
print("\n## public", flush=True)
for base in ("https://dylive.nomadro.com", "https://dy.nomadro.live"):
try:
jar = CookieJar()
opener = urllib.request.build_opener(urllib.request.HTTPCookieProcessor(jar), urllib.request.HTTPSHandler(context=CTX))
req = urllib.request.Request(f"{base}/api/auth/login", data=json.dumps({"username":"hackrobot","password":"Xiao4669805@"}).encode(), headers={"Content-Type":"application/json"}, method="POST")
with opener.open(req, timeout=20) as r:
print(base, "login", r.status, flush=True)
with opener.open(urllib.request.Request(f"{base}/api/health"), timeout=15) as r:
print(base, "health", r.status, flush=True)
except Exception as e:
print(base, "ERR", e, flush=True)
print("SMOKE_DONE", flush=True)