From fd1a9cafd9711a85bb3b24e2aa50b8226585dbe3 Mon Sep 17 00:00:00 2001 From: Roman Buryan Date: Wed, 28 Oct 2026 12:55:10 +0300 Subject: [PATCH] =?UTF-8?q?[HERMES]=20=D0=9F=D1=80=D0=BE=D0=B2=D0=B5=D1=80?= =?UTF-8?q?=D0=BA=D0=B0=20=D0=BC=D1=91=D1=80=D1=82=D0=B2=D1=8B=D1=85=20?= =?UTF-8?q?=D1=86=D0=B5=D0=BB=D0=B5=D0=B9=20=D0=BC=D0=BE=D0=BD=D0=B8=D1=82?= =?UTF-8?q?=D0=BE=D1=80=D0=B8=D0=BD=D0=B3=D0=B0:=20=D1=81=D0=BA=D1=80?= =?UTF-8?q?=D0=B8=D0=BF=D1=82=20+=20=D0=B7=D0=B0=D0=B4=D0=B0=D0=BD=D0=B8?= =?UTF-8?q?=D0=B5=2007:15?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ops/hermes/jobs.yaml | 5 +++ ops/scripts/audit-targets.py | 59 ++++++++++++++++++++++++++++++++++++ 2 files changed, 64 insertions(+) create mode 100755 ops/scripts/audit-targets.py diff --git a/ops/hermes/jobs.yaml b/ops/hermes/jobs.yaml index 15d89e5..ad9b270 100644 --- a/ops/hermes/jobs.yaml +++ b/ops/hermes/jobs.yaml @@ -53,3 +53,8 @@ swarm-watchdog: every_seconds: 60 timeout: 120 retries: 0 +audit-targets: + command: /usr/bin/python3 /opt/buryan-hub/scripts/audit-targets.py + daily_at: "07:15" + timeout: 300 + retries: 0 diff --git a/ops/scripts/audit-targets.py b/ops/scripts/audit-targets.py new file mode 100755 index 0000000..c9ee299 --- /dev/null +++ b/ops/scripts/audit-targets.py @@ -0,0 +1,59 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- +"""Ищет МЁРТВЫЕ цели мониторинга. + +Мёртвая цель = адрес упомянут в проверках/реестрах, но не отвечает вовсе (код 000). +Именно так выглядит «порт съехал»: служба жива, а проверка смотрит на старый порт +(реальный случай: n8n 5678 в копии check-services, при живом 5680). + +Любой ответ (200/401/404/500) считается живым: важно, что хост и порт на месте. +""" +import concurrent.futures as cf +import os +import re +import subprocess +import sys + +SRC = [ + "/opt/buryan-hub/scripts/check-services.sh", + "/opt/hub-core/reconcile.py", + "/opt/hub-core/selfheal.py", + "/opt/hub-core/services.yaml", +] + +# Известные и намеренно отключённые адреса — впишите сюда с датой и причиной +ALLOW_DEAD = set() + + +def collect(): + urls = {} + for p in SRC: + if not os.path.exists(p): + continue + t = open(p, encoding="utf-8", errors="ignore").read() + for m in re.finditer(r"https?://[A-Za-z0-9_.\-]+(?::\d+)?[^\s\"')<>]*", t): + urls.setdefault(m.group(0).rstrip(".,;"), os.path.basename(p)) + return urls + + +def probe(u): + r = subprocess.run(["curl", "-s", "-o", "/dev/null", "-w", "%{http_code}", + "-k", "--max-time", "6", u], capture_output=True, text=True) + return u, (r.stdout.strip() or "000") + + +def main(): + urls = collect() + dead = [] + with cf.ThreadPoolExecutor(max_workers=24) as ex: + for u, code in ex.map(probe, sorted(urls)): + if code == "000" and u not in ALLOW_DEAD: + dead.append(u) + print("проверено адресов: %d, мёртвых: %d" % (len(urls), len(dead))) + for u in dead: + print(" мёртв:", u) + return 1 if dead else 0 + + +if __name__ == "__main__": + sys.exit(main())