Files
memory-gateway/plugins/memory-gateway-agent/scripts/health.py

33 lines
1.1 KiB
Python

#!/usr/bin/env python3
from __future__ import annotations
import json
import sys
import urllib.error
import urllib.request
from pathlib import Path
PLUGIN_ROOT = Path(__file__).resolve().parents[1]
if str(PLUGIN_ROOT) not in sys.path:
sys.path.insert(0, str(PLUGIN_ROOT))
from memory_gateway_plugin.config import load_config
from memory_gateway_plugin.output import dumps_safe, summarize_data
def main() -> None:
config = load_config()
request = urllib.request.Request(config.gateway_url.rstrip("/") + "/health", method="GET")
if config.api_key:
request.add_header("X-API-Key", config.api_key)
try:
with urllib.request.urlopen(request, timeout=config.timeout) as response:
payload = json.loads(response.read().decode("utf-8"))
print(dumps_safe({"ok": True, "endpoint": "/health", "status_code": getattr(response, "status", 200), "data": summarize_data(payload)}))
except urllib.error.URLError as exc:
print(dumps_safe({"ok": False, "endpoint": "/health", "status_code": None, "error": str(exc)[:300]}))
if __name__ == "__main__":
main()