get_system_health
Check Domoticz system and hardware gateway health to monitor stability and identify issues.
Instructions
Check the health of the Domoticz system and hardware gateways.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
| result | Yes |
Implementation Reference
- src/domoticz_mcp/server.py:440-479 (handler)The main handler/implementation of the `get_system_health` tool. It queries Domoticz hardware gateways for health status, checks for unresponsive devices (no update in >24h), and returns a JSON response with hardware_health and unresponsive_devices_count.
@mcp.tool() async def get_system_health() -> str: """Check the health of the Domoticz system and hardware gateways.""" async with create_client() as client: hw_resp = await _do_request(client, "GET", f"{DOMOTICZ_API_URL}?type=command¶m=gethardware") hardware = hw_resp.json().get("result", []) health_report = [] for hw in hardware: status = "Online" if hw.get("Enabled") == "true" else "Disabled" health_report.append({ "Name": hw.get("Name"), "Type": hw.get("Type"), "Status": status, "Address": hw.get("Address"), "Port": hw.get("Port") }) # Check for unresponsive devices (last update > 24h) devices = await _get_cached_data(client, _device_cache, f"{DOMOTICZ_API_URL}?type=command¶m=getdevices&filter=all&used=true") now = datetime.now() unresponsive_count = 0 for dev in devices: last_update_str = dev.get("LastUpdate") if last_update_str: try: last_update = datetime.strptime(last_update_str, "%Y-%m-%d %H:%M:%S") if now - last_update > timedelta(hours=24): unresponsive_count += 1 except ValueError: continue return json.dumps({ "status": "OK", "result": { "hardware_health": health_report, "unresponsive_devices_count": unresponsive_count, "recommendation": "Use `get_connectivity_report` for a detailed list of unresponsive devices." if unresponsive_count > 0 else "System looks healthy." } }) - src/domoticz_mcp/server.py:440-440 (registration)The tool is registered via the `@mcp.tool()` decorator on line 440, which is the standard MCP registration mechanism using the FastMCP server instance.
@mcp.tool() - src/domoticz_mcp/server.py:441-441 (schema)The function signature `async def get_system_health() -> str` defines the schema: no input parameters, returns a JSON string.
async def get_system_health() -> str: - src/domoticz_mcp/server.py:296-297 (helper)The `create_client` helper (which returns a `DomoticzClient`) is used by `get_system_health` to obtain an authenticated HTTP client for API calls.
# Custom AsyncClient wrapper that ensures the token is added - src/domoticz_mcp/server.py:346-346 (helper)The `_get_cached_data` helper is used by `get_system_health` to fetch device data with caching support.
async def _get_cached_data(client: "httpx.AsyncClient", cache_obj: Dict[str, Any], api_url: str, key_path: str = "result") -> List[Dict[str, Any]]: