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,7 +66,7 @@ class PingableSystem(System):
return s.returncode == 0, s.stdout.decode(), s.stderr.decode()
def update_state(self):
self.state = SystemState.UNKNOWN
try:
ok, stdout, stderr = self.ping()
if ok:
self.state = SystemState.OK
@ -78,6 +78,9 @@ class PingableSystem(System):
else:
self.state = SystemState.FAILED
self.state_verbose = (stdout + "\n" + stderr).strip("\n\r ")
except Exception as e:
self.state = SystemState.UNKNOWN
self.state_verbose = f"Exception: {str(e)}"
class HTTPServer(System):
@ -89,7 +92,6 @@ class HTTPServer(System):
self.allow_self_signed_cert = allow_self_signed_cert
def update_state(self):
self.state = SystemState.UNKNOWN
try:
r = requests.head(self.url, timeout=1.0, verify=not self.allow_self_signed_cert)
if r.status_code == self.expected_status:
@ -99,4 +101,7 @@ class HTTPServer(System):
self.state_verbose = f"Status {r.status_code} {r.url}"
except requests.ConnectionError as e:
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)}"