#!/usr/bin/env python3 import sys, json try: data = json.load(sys.stdin) if "status" not in data or not isinstance(data["status"], dict): print("ERROR: Invalid health check response. Missing 'status' key.") sys.exit(1) all_ok = True for engine, status in data["status"].items(): if status != "ok": print(f"ERROR: Engine '{engine}' has status '{status}'.") all_ok = False if all_ok: print("Health check PASSED. All engines are ok.") sys.exit(0) else: print("Health check FAILED.") sys.exit(1) except json.JSONDecodeError: print("ERROR: Failed to decode JSON from health endpoint.") sys.exit(1) except Exception as e: print(f"An unexpected error occurred: {e}") sys.exit(1)