From 069aad8284b3f43dfacaff95609826522465f762 Mon Sep 17 00:00:00 2001 From: Roman Buryan Date: Mon, 23 Nov 2026 19:58:25 +0300 Subject: [PATCH] [VPN] Add CF/VPN selfcheck and retry tunnel URL sync --- ops/scripts/cf_tunnel_sync.py | 13 ++++++++++++- ops/scripts/selfcheck_platform.py | 30 +++++++++++++++++++++++++++++- 2 files changed, 41 insertions(+), 2 deletions(-) diff --git a/ops/scripts/cf_tunnel_sync.py b/ops/scripts/cf_tunnel_sync.py index 7521cec..6b265ac 100755 --- a/ops/scripts/cf_tunnel_sync.py +++ b/ops/scripts/cf_tunnel_sync.py @@ -47,6 +47,17 @@ def get_url(): return m.group(0) if m else "" + +def get_url_retry(attempts=3): + for i in range(attempts): + u = get_url() + if u: + return u + if i + 1 < attempts: + time.sleep(5) + return "" + + def get_uuid(): try: u = open(UUID_FILE, encoding="utf-8").read().strip() @@ -131,7 +142,7 @@ def notify(title, text, priority="high"): def main(): dry = "--dry-run" in sys.argv - url = get_url() + url = get_url_retry() if not url: notify("CF-туннель", "Не удалось получить URL туннеля с VDS (WG).", "high") print("URL не получен") diff --git a/ops/scripts/selfcheck_platform.py b/ops/scripts/selfcheck_platform.py index 40ed82f..6b7b2a8 100755 --- a/ops/scripts/selfcheck_platform.py +++ b/ops/scripts/selfcheck_platform.py @@ -258,12 +258,40 @@ def check_tool_gateway(): ok = active == "active" and '"ok": true' in health add("Tool Gateway", ok, "active=%s health=%s" % (active, health[:60])) + +def check_vpn_cf(): + """Последняя health-проба VPN + совпадение CF-профиля с cf-host.txt.""" + lastp = "/var/lib/vpn-health/last.json" + try: + last = json.load(open(lastp, encoding="utf-8")) + except Exception as e: + return add("VPN/CF", False, "нет %s: %s" % (lastp, str(e)[:80])) + cf = last.get("cf") or {} + cf_ok = bool(cf.get("ok")) and cf.get("code") in (400, 404, 426) + host = (last.get("cf_host") or "").strip() + try: + want = open("/root/buryan-infra/ops/vpn/cf-host.txt", encoding="utf-8").read().strip() + except Exception: + want = "" + prof = "/root/buryan-infra/ops/vpn/build/profiles/vpn-akadmin.json" + addr = "" + try: + d = json.load(open(prof, encoding="utf-8")) + ob = next((o for o in d.get("outbounds", []) if o.get("tag") == "proxy-cf"), None) + addr = ((ob or {}).get("settings", {}).get("vnext") or [{}])[0].get("address", "") + except Exception: + pass + ok = cf_ok and host == want and addr == want.replace("https://", "") + add("VPN/CF", ok, "cf=%s code=%s host=%s profile=%s" % + (cf.get("ok"), cf.get("code"), host[-35:], addr[-35:])) + + def main(): print("Самопроверка платформы", date.today().isoformat()) checks = [check_units, check_services, check_bots, check_matrix_sso, check_ollama, check_n8n, check_digests, check_reports, check_registry, check_cron_dots, check_tasks, check_approvals, check_hermes, check_errors, check_disk, - check_lvm, check_pg_conn, check_tool_gateway] + check_lvm, check_pg_conn, check_tool_gateway, check_vpn_cf] for fn in checks: try: fn()