"""Unified diagnostic entry point for the flotta monitoring stack.""" from __future__ import annotations import json from datetime import datetime, timezone from typing import Any, Callable, Dict from backup_health import check_backup_status from docker_health import check_docker_services from hardware_health import check_hardware from logbook_health import check_logbook from network_health import check_network_tunnel from services_health import check_web_services def _run_check(name: str, func: Callable[[], Dict[str, Any]]) -> Dict[str, Any]: """ Execute a diagnostic function and capture unexpected exceptions. Args: name: Human readable check identifier. func: Zero-argument callable returning a dictionary. Returns: The dictionary from the callable, or an error payload when the check fails. """ try: result = func() except Exception as exc: # pragma: no cover - defensive guard. return {"error": f"{name} check failed: {exc}"} if not isinstance(result, dict): return {"error": f"{name} check returned non-dict payload: {type(result).__name__}"} return result def run_full_diagnostics() -> Dict[str, Dict[str, Any]]: """Run all diagnostics and return a structured report.""" return { "hardware": _run_check("hardware", check_hardware), "services": _run_check("docker services", check_docker_services), "web_services": _run_check("web services", check_web_services), "network": _run_check("network tunnel", check_network_tunnel), "backups": _run_check("backup status", check_backup_status), "logbook": _run_check("logbook", check_logbook), "report_timestamp_utc": datetime.now(timezone.utc).isoformat(), } def main() -> None: diagnostics = run_full_diagnostics() print(json.dumps(diagnostics, indent=4, sort_keys=True)) if __name__ == "__main__": main()