"""Network health checks for ensuring the WireGuard tunnel is responsive.""" from __future__ import annotations import subprocess def check_network_tunnel() -> dict[str, str]: """ Ping the Avamposto gateway through the WireGuard tunnel. Returns: A dictionary with key 'status' equal to 'online' when the ping succeeds, otherwise 'offline'. """ try: result = subprocess.run( ["ping", "-c", "3", "10.0.0.1"], stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL, check=False, ) except FileNotFoundError: return {"status": "offline"} if result.returncode == 0: return {"status": "online"} return {"status": "offline"} if __name__ == "__main__": outcome = check_network_tunnel() status = outcome.get("status", "offline") print(f"Tunnel status: {status}") raise SystemExit(0 if status == "online" else 1)