Network monitor: hub, probes, Docker and native installers
Hub (FastAPI + no-build web UI): - Network health: live probe/target matrix, status strips, incidents - Probes: add (with install command), rename, remove, latency and throughput charts - Clients merged from AdGuard, DHCP, query log and probe ARP tables; names, categories, suspicious flag, notes, per-client DNS requests - Query log, domain detail (clients, related subdomains), blocked domains via the AdGuard Home /control API Probe: tests peers (ping, HTTP, throughput), gateway, LAN and public DNS, internet URLs and an optional VPS; buffers results while the hub is down. Gateway and ARP from /proc/net on Linux, route/arp on macOS. Install: install.sh (hub) and install-probe.sh (generated from it), each in docker mode (compose; default on Linux hosts) or native mode (venv + systemd or launchd; default on macOS and in LXC). Both modes deploy with an update command that checks the new commit and rolls back on failure. CLAUDE.md carries shared context for Claude Code sessions on each machine. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
commit
54a765510a
63 changed files with 6464 additions and 0 deletions
69
app/hub/settings.py
Normal file
69
app/hub/settings.py
Normal file
|
|
@ -0,0 +1,69 @@
|
|||
"""Hub settings, read from the environment (.env) on each call so tests can change them."""
|
||||
|
||||
import os
|
||||
from dataclasses import dataclass
|
||||
from urllib.parse import urlparse
|
||||
|
||||
DEFAULT_PROBE_INSTALL_URL = "https://git.neilbantoc.dev/services/network-monitor/raw/branch/main/install-probe.sh"
|
||||
|
||||
|
||||
def _list(name: str, default: str) -> list[str]:
|
||||
return [x.strip() for x in os.environ.get(name, default).split(",") if x.strip()]
|
||||
|
||||
|
||||
def _num(name: str, default: float) -> float:
|
||||
try:
|
||||
return float(os.environ.get(name, "") or default)
|
||||
except ValueError:
|
||||
return default
|
||||
|
||||
|
||||
@dataclass(frozen=True)
|
||||
class Settings:
|
||||
ui_password: str
|
||||
adguard_url: str
|
||||
adguard_username: str
|
||||
adguard_password: str
|
||||
probe_interval: int
|
||||
retention_days: float
|
||||
dns_servers: list[str]
|
||||
lan_dns_servers: list[str]
|
||||
dns_query_name: str
|
||||
wan_http_urls: list[str]
|
||||
vps_url: str
|
||||
slow_lan_ms: float
|
||||
slow_wan_ms: float
|
||||
slow_dns_ms: float
|
||||
throughput_every: int
|
||||
throughput_bytes: int
|
||||
probe_install_url: str
|
||||
hub_public_url: str
|
||||
|
||||
@property
|
||||
def adguard_configured(self) -> bool:
|
||||
return bool(self.adguard_url)
|
||||
|
||||
|
||||
def get() -> Settings:
|
||||
adguard_url = os.environ.get("ADGUARD_URL", "").strip().rstrip("/")
|
||||
lan_default = urlparse(adguard_url).hostname or "" if adguard_url else ""
|
||||
return Settings(
|
||||
ui_password=os.environ.get("UI_PASSWORD", ""),
|
||||
adguard_url=adguard_url,
|
||||
adguard_username=os.environ.get("ADGUARD_USERNAME", ""),
|
||||
adguard_password=os.environ.get("ADGUARD_PASSWORD", ""),
|
||||
probe_interval=max(5, int(_num("PROBE_INTERVAL", 30))),
|
||||
retention_days=max(1.0, _num("RETENTION_DAYS", 14)),
|
||||
dns_servers=_list("DNS_SERVERS", "1.1.1.1,8.8.8.8,9.9.9.9"),
|
||||
lan_dns_servers=_list("LAN_DNS_SERVERS", lan_default),
|
||||
dns_query_name=os.environ.get("DNS_QUERY_NAME", "example.com").strip() or "example.com",
|
||||
wan_http_urls=_list("WAN_HTTP_URLS", "http://connectivitycheck.gstatic.com/generate_204"),
|
||||
vps_url=os.environ.get("VPS_URL", "").strip().rstrip("/"),
|
||||
slow_lan_ms=_num("SLOW_LAN_MS", 100),
|
||||
slow_wan_ms=_num("SLOW_WAN_MS", 200),
|
||||
slow_dns_ms=_num("SLOW_DNS_MS", 250),
|
||||
throughput_every=max(0, int(_num("THROUGHPUT_EVERY", 10))),
|
||||
throughput_bytes=int(min(_num("THROUGHPUT_BYTES", 4_000_000), 50_000_000)),
|
||||
probe_install_url=os.environ.get("PROBE_INSTALL_URL", DEFAULT_PROBE_INSTALL_URL).strip(),
|
||||
hub_public_url=os.environ.get("HUB_PUBLIC_URL", "").strip().rstrip("/"),
|
||||
)
|
||||
Loading…
Add table
Add a link
Reference in a new issue