This commit is contained in:
Mark Gregory
2026-10-21 14:54:07 +01:00
parent 8c7b29d50f
commit 578f0218a5
6 changed files with 79 additions and 8 deletions
+10 -1
View File
@@ -2,6 +2,15 @@
"""Read-only JSON adapter for an existing pegasus-health --verbose command."""
import datetime
import json
def system_uptime_seconds():
"""Read Linux kernel uptime without privilege or external commands."""
try:
with open('/proc/uptime', encoding='ascii') as handle:
return max(0, int(float(handle.read().split()[0])))
except (OSError, ValueError, IndexError):
return None
import re
import subprocess
import sys
@@ -56,7 +65,7 @@ def output():
if not checks:
counts['fail'] = max(1, counts['fail'])
overall = 'fail' if counts['fail'] or any(g['status']=='fail' for g in groups) else 'warn' if counts['warn'] or any(g['status']=='warn' for g in groups) else 'ok'
print(json.dumps({'schema':1, 'host':'pegasus', 'generatedAt':datetime.datetime.now(datetime.timezone.utc).isoformat(), 'overall':overall, 'counts':counts,'groups':groups,'checks':checks, 'diagnostics':plain[-24000:], 'commandExitCode':p.returncode}, ensure_ascii=False))
print(json.dumps({'schema':1, 'host':'pegasus', 'uptimeSeconds':system_uptime_seconds(), 'generatedAt':datetime.datetime.now(datetime.timezone.utc).isoformat(), 'overall':overall, 'counts':counts,'groups':groups,'checks':checks, 'diagnostics':plain[-24000:], 'commandExitCode':p.returncode}, ensure_ascii=False))
return {'ok':0,'warn':1,'fail':2}[overall]
if __name__ == '__main__':