Development
This commit is contained in:
parent
885e5ec3ca
commit
65c5b61ca7
2 changed files with 29 additions and 6 deletions
|
|
@ -5,7 +5,7 @@ Reads config.json, checks services, configuration files, and logs, then writes
|
|||
.health JSON. Imported by core.py; also runnable standalone.
|
||||
|
||||
Public API:
|
||||
run_and_write(data) -> dict run all checks, write .health, return dict
|
||||
run_and_write(data) -> (bool, dict) run all checks, write .health, return (all_healthy, status)
|
||||
print_table(status: dict) render the CLI service table from status dict
|
||||
"""
|
||||
import hashlib
|
||||
|
|
@ -711,7 +711,7 @@ def _next_blocklist_update():
|
|||
# ===================================================================
|
||||
|
||||
def run_and_write(data):
|
||||
"""Run all checks, write .health atomically, return the status dict."""
|
||||
"""Run all checks, write .health atomically, return (all_healthy, status_dict)."""
|
||||
status = {
|
||||
"checked_at": datetime.now().strftime("%Y-%m-%dT%H:%M:%S"),
|
||||
"services": check_services(data),
|
||||
|
|
@ -722,7 +722,12 @@ def run_and_write(data):
|
|||
tmp = HEALTH_FILE.with_suffix(".tmp")
|
||||
tmp.write_text(json.dumps(status, indent=2))
|
||||
tmp.replace(HEALTH_FILE)
|
||||
return status
|
||||
healthy = all(
|
||||
item.get('status') != 'problem'
|
||||
for section in ('services', 'configurations', 'logs')
|
||||
for item in status.get(section, [])
|
||||
)
|
||||
return healthy, status
|
||||
|
||||
|
||||
def print_table(status):
|
||||
|
|
@ -797,5 +802,5 @@ if __name__ == "__main__":
|
|||
except Exception as ex:
|
||||
print(f"Error loading {CONFIG_FILE}: {ex}", file=sys.stderr)
|
||||
sys.exit(1)
|
||||
status = run_and_write(data)
|
||||
_, status = run_and_write(data)
|
||||
print_table(status)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue