Add hardware health and uptime reports

This commit is contained in:
dido committed 2026-09-30 09:46:09 +03:00
1 parent 25162b8a45
commit 4b9a65df75
5 files changed
+547 -3

No files matched your search

+14
View File
@@ -184,6 +184,17 @@ def load_average():
return None
def uptime_info():
try:
seconds = int(float(pathlib.Path("/proc/uptime").read_text(encoding="ascii").split()[0]))
except (OSError, ValueError, IndexError):
return {"seconds": None, "formatted": "Unavailable"}
days, remainder = divmod(seconds, 86400)
hours, remainder = divmod(remainder, 3600)
minutes = remainder // 60
return {"seconds": seconds, "formatted": f"{days}d {hours}h {minutes}m"}
def parse_json_command(command):
output = run(command)
if output is None:
@@ -526,6 +537,7 @@ def collect_report():
network_mounts, mount_note = collect_network_mounts()
return {
"generated_at": datetime.datetime.now().astimezone().isoformat(timespec="seconds"),
"uptime": uptime_info(),
"host": {"hostname": host, "fqdn": fqdn, "domain": domain},
"operating_system": {
"name": os_name,
@@ -567,6 +579,7 @@ def render_text(report):
f" Hostname: {value_or_unavailable(host['hostname'])}",
f" Domain: {value_or_unavailable(host['domain'])}",
f" FQDN: {value_or_unavailable(host['fqdn'])}",
f" Uptime: {value_or_unavailable(report['uptime']['formatted'])}",
"",
"OPERATING SYSTEM",
"-----------------",
@@ -679,6 +692,7 @@ def render_html(report):
f"<dt>Hostname</dt><dd>{esc(host['hostname'])}</dd>",
f"<dt>Domain</dt><dd>{esc(host['domain'])}</dd>",
f"<dt>FQDN</dt><dd>{esc(host['fqdn'])}</dd>",
f"<dt>Uptime</dt><dd>{esc(report['uptime']['formatted'])}</dd>",
f"<dt>Operating system</dt><dd>{esc(os_info['name'])}</dd>",
f"<dt>Version</dt><dd>{esc(os_info['version'])}</dd>",
f"<dt>Architecture</dt><dd>{esc(os_info['architecture'])}</dd>",