30 lines
840 B
Python
30 lines
840 B
Python
# checks.py
|
|
import socket
|
|
|
|
|
|
class SystemChecks:
|
|
|
|
def __init__(self, network_targets, ziti_target):
|
|
self.network_targets = network_targets
|
|
self.ziti_target = ziti_target
|
|
|
|
def check_network_status(self):
|
|
"""Loops through configured network targets and returns True if any succeed."""
|
|
for host, port in self.network_targets:
|
|
if self._tcp_ping(host, int(port), timeout=1.5):
|
|
return True
|
|
return False
|
|
|
|
def check_ziti_status(self):
|
|
"""Probes the configured Ziti target endpoint."""
|
|
if not self.ziti_target:
|
|
return False
|
|
host, port = self.ziti_target
|
|
return self._tcp_ping(host, int(port), timeout=1.0)
|
|
|
|
def _tcp_ping(self, host, port, timeout=1):
|
|
try:
|
|
with socket.create_connection((host, port), timeout=timeout):
|
|
return True
|
|
except OSError:
|
|
return False |