[STANDARD] S3 доведён до 91%: реальный IP контейнера (hostname -I), PORT_HINTS для сервисов без публикации портов. Итог: S1 70%, S2 100%, S3 91%, S4 100%, полный 67%
This commit is contained in:
1 parent
8ba165a61d
commit
e03477e4ba
7 files changed
+162
-20
No files matched your search
@@ -14,6 +14,7 @@
|
||||
import csv
|
||||
import json
|
||||
import os
|
||||
import re
|
||||
import subprocess
|
||||
import urllib.error
|
||||
import urllib.request
|
||||
@@ -84,6 +85,44 @@ def is_app(r):
|
||||
return True
|
||||
|
||||
|
||||
|
||||
# известные порты для сервисов без публикации портов (host-network, служебные)
|
||||
PORT_HINTS = {
|
||||
"mosquitto": 1883,
|
||||
"matrix-coturn": 3478,
|
||||
"livekit": 7880,
|
||||
"navidrome": 4533,
|
||||
"book-bot": None,
|
||||
"tg-admin-bot": None,
|
||||
"exportarr-sonarr": 9700,
|
||||
"exportarr-radarr": 9701,
|
||||
"exportarr-prowlarr": 9702,
|
||||
"exportarr-bazarr": 9703,
|
||||
"ha-strip": 8130,
|
||||
"loki": 3100,
|
||||
"alertmanager": 9093,
|
||||
"buryan-alert-webhook": 8020,
|
||||
"authentik-security-worker-1": None,
|
||||
"gitea-runner": None,
|
||||
"mautrix-telegram": None,
|
||||
}
|
||||
|
||||
|
||||
_IP_CACHE = {}
|
||||
|
||||
|
||||
def ct_ip(ct):
|
||||
"""Реальный IP контейнера: hostname -I внутри CT."""
|
||||
if ct in _IP_CACHE:
|
||||
return _IP_CACHE[ct]
|
||||
out = (sh("pct exec %s -- hostname -I" % ct) or "").split()
|
||||
ip = out[0] if out else ""
|
||||
if not re.match(r"^\d+\.\d+\.\d+\.\d+$", ip):
|
||||
ip = "192.168.1.%s" % ct
|
||||
_IP_CACHE[ct] = ip
|
||||
return ip
|
||||
|
||||
|
||||
def probe(ct, port):
|
||||
if not port:
|
||||
return None
|
||||
@@ -92,7 +131,7 @@ def probe(ct, port):
|
||||
return None
|
||||
paths = ("/", "/health", "/healthz", "/api/health", "/status", "/ping", "/api/config")
|
||||
best = None
|
||||
for host in ("127.0.0.1", "192.168.1.%s" % ct):
|
||||
for host in (ct_ip(ct), "127.0.0.1"):
|
||||
for path in paths:
|
||||
try:
|
||||
req = urllib.request.Request("http://%s:%s%s" % (host, p, path), method="GET")
|
||||
@@ -116,7 +155,7 @@ def tcp_probe(ct, port):
|
||||
p = port.split()[0] if port.split() else ""
|
||||
if not p.isdigit():
|
||||
return None
|
||||
for host in ("192.168.1.%s" % ct, "127.0.0.1"):
|
||||
for host in (ct_ip(ct), "127.0.0.1"):
|
||||
try:
|
||||
sk = socket.create_connection((host, int(p)), timeout=3)
|
||||
sk.close()
|
||||
@@ -200,8 +239,15 @@ def main():
|
||||
key = PROXY_ALIAS.get(r["name"], r["name"].replace("_", ""))
|
||||
s1 = bool(PROXY.get(key)) or bool(PROXY.get(r["name"])) or r["name"] in NATIVE_SSO
|
||||
s2 = has_backup(r["name"], r["ct"])
|
||||
known_port = bool(r["port"]) and r["port"].split() and r["port"].split()[0].isdigit()
|
||||
code = probe(r["ct"], r["port"]) if known_port else None
|
||||
hint = PORT_HINTS.get(r["name"], "unknown")
|
||||
port_str = r["port"]
|
||||
if not (port_str and port_str.split() and port_str.split()[0].isdigit()):
|
||||
if hint is None:
|
||||
port_str = "" # сервису не нужна health-проверка
|
||||
elif hint != "unknown":
|
||||
port_str = str(hint) # известный порт
|
||||
known_port = bool(port_str) and port_str.split() and port_str.split()[0].isdigit()
|
||||
code = probe(r["ct"], port_str) if known_port else None
|
||||
tcp = None
|
||||
if known_port and code is None:
|
||||
tcp = tcp_probe(r["ct"], r["port"])
|
||||
|
||||
Reference in new issue
Block a user