[HERMES] Проверка мёртвых целей мониторинга: скрипт + задание 07:15
lint / hygiene (push) Successful in 16s
lint / hygiene (push) Successful in 16s
This commit is contained in:
1 parent
c322f8abf3
commit
fd1a9cafd9
2 files changed
+64
No files matched your search
@@ -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
|
||||
Executable
+59
@@ -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())
|
||||
Reference in new issue
Block a user