feat: count failed units in status
Some checks are pending
Continuous Integration / Checks (push) Waiting to run
Some checks are pending
Continuous Integration / Checks (push) Waiting to run
This commit is contained in:
parent
dbb636e7df
commit
eb81a1fedf
1 changed files with 22 additions and 7 deletions
29
home/status
29
home/status
|
@ -5,6 +5,7 @@ import sys
|
|||
import time
|
||||
import requests
|
||||
import logging
|
||||
import subprocess
|
||||
|
||||
from datetime import datetime
|
||||
|
||||
|
@ -25,7 +26,7 @@ class Cat(Status):
|
|||
catwalk = " " * (cat_width - index) + 1 * "🐈🏳️🌈" + " " * index
|
||||
self.index = (index + 1) % cat_width
|
||||
|
||||
return catwalk
|
||||
return {"full_text": catwalk}
|
||||
|
||||
|
||||
class Space(Status):
|
||||
|
@ -37,7 +38,7 @@ class Space(Status):
|
|||
if self.backoff == 0:
|
||||
self.update()
|
||||
|
||||
return self.c_status
|
||||
return {"full_text": self.c_status}
|
||||
|
||||
def update(self):
|
||||
spacestatus_url = "https://status.stratum0.org/status.json"
|
||||
|
@ -65,12 +66,26 @@ class Battery(Status):
|
|||
|
||||
battery = f"{status} {capacity}%"
|
||||
|
||||
return battery
|
||||
return {"full_text": battery}
|
||||
|
||||
|
||||
class Time(Status):
|
||||
def status(state):
|
||||
return datetime.now().strftime("%Vth %A %H:%M")
|
||||
def status(self):
|
||||
return {"full_text": datetime.now().strftime("%Vth %A %H:%M") }
|
||||
|
||||
|
||||
class FailedUnits(Status):
|
||||
def status(self):
|
||||
proc = subprocess.run(["systemctl", "list-units", "--failed"], capture_output = True)
|
||||
stdout = proc.stdout.decode('utf-8')
|
||||
failed = 0
|
||||
for line in stdout:
|
||||
if 'failed' in line:
|
||||
failed += 1
|
||||
if failed is 0:
|
||||
return {"full_text": f"No failed units"}
|
||||
else:
|
||||
return {"full_text": f"There are {failed} failed units", "color": "#ff0000"}
|
||||
|
||||
|
||||
def print_header():
|
||||
|
@ -94,7 +109,7 @@ def run(interval, widgets):
|
|||
except Exception as e:
|
||||
logger.error(e)
|
||||
if status:
|
||||
body += {"full_text": f"{status}"},
|
||||
body += status,
|
||||
|
||||
print(json.dumps(body), ",", flush=True)
|
||||
|
||||
|
@ -108,6 +123,6 @@ if __name__ == "__main__":
|
|||
# Interval in seconds
|
||||
interval = 1.0
|
||||
|
||||
widgets = [Cat(), Space(), Battery(), Time()]
|
||||
widgets = [Cat(), FailedUnits(), Space(), Battery(), Time()]
|
||||
|
||||
run(interval, widgets)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue