Set the Unknown state after something went wrong instead of setting it in advance, this fixes a bug where the UI shows the Unknown state for all systems until it refreshs again

This commit is contained in:
ChaoticByte 2025-02-24 23:06:32 +01:00
parent fa2d10198f
commit f3cdff4d38
No known key found for this signature in database

View file

@ -66,18 +66,21 @@ class PingableSystem(System):
return s.returncode == 0, s.stdout.decode(), s.stderr.decode() return s.returncode == 0, s.stdout.decode(), s.stderr.decode()
def update_state(self): def update_state(self):
self.state = SystemState.UNKNOWN try:
ok, stdout, stderr = self.ping() ok, stdout, stderr = self.ping()
if ok: if ok:
self.state = SystemState.OK self.state = SystemState.OK
p_matches = ping_time_regex.findall(stdout) p_matches = ping_time_regex.findall(stdout)
if len(p_matches) > 0: if len(p_matches) > 0:
self.state_verbose = f"Ping: {p_matches[0]}" self.state_verbose = f"Ping: {p_matches[0]}"
else:
self.state_verbose = stdout.strip("\n\r ")
else: else:
self.state_verbose = stdout.strip("\n\r ") self.state = SystemState.FAILED
else: self.state_verbose = (stdout + "\n" + stderr).strip("\n\r ")
self.state = SystemState.FAILED except Exception as e:
self.state_verbose = (stdout + "\n" + stderr).strip("\n\r ") self.state = SystemState.UNKNOWN
self.state_verbose = f"Exception: {str(e)}"
class HTTPServer(System): class HTTPServer(System):
@ -89,7 +92,6 @@ class HTTPServer(System):
self.allow_self_signed_cert = allow_self_signed_cert self.allow_self_signed_cert = allow_self_signed_cert
def update_state(self): def update_state(self):
self.state = SystemState.UNKNOWN
try: try:
r = requests.head(self.url, timeout=1.0, verify=not self.allow_self_signed_cert) r = requests.head(self.url, timeout=1.0, verify=not self.allow_self_signed_cert)
if r.status_code == self.expected_status: if r.status_code == self.expected_status:
@ -99,4 +101,7 @@ class HTTPServer(System):
self.state_verbose = f"Status {r.status_code} {r.url}" self.state_verbose = f"Status {r.status_code} {r.url}"
except requests.ConnectionError as e: except requests.ConnectionError as e:
self.state = SystemState.FAILED self.state = SystemState.FAILED
self.state_verbose = f"Connection failed: {str(e)}"
except Exception as e:
self.state = SystemState.UNKNOWN
self.state_verbose = f"Exception: {str(e)}" self.state_verbose = f"Exception: {str(e)}"