From 7731a1a9af4c3e7c80bbaa49e7b87ada7a601404 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Br=C3=BCckner?= Date: Thu, 4 Jun 2026 15:17:28 +0200 Subject: [PATCH] fix(checkmk): add query filter to monitoring endpoint, precise permission guidance in log --- server.ts | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/server.ts b/server.ts index 61e5576..f93bdc2 100644 --- a/server.ts +++ b/server.ts @@ -741,12 +741,13 @@ async function startServer() { } // Step 2: fetch live monitoring state for all hosts in one call. - // /domain-types/host/collections/all returns monitoring objects with extensions.state - // where 0=UP, 1=DOWN, 2=UNREACHABLE. + // Uses query param to force the collection to return results (some CheckMK versions + // return an empty list without an explicit filter even with full permissions). let hostnameToState: Map; try { + const monQuery = encodeURIComponent(JSON.stringify({ op: '!=', left: 'name', right: '' })); const monRes = await fetch( - `${CHECKMK_API_URL}/domain-types/host/collections/all`, + `${CHECKMK_API_URL}/domain-types/host/collections/all?query=${monQuery}`, { headers } ); if (!monRes.ok) throw new Error(checkmkHttpHint(monRes.status)); @@ -765,9 +766,10 @@ async function startServer() { // so we can identify which field carries the reachability state. db.prepare('INSERT INTO logs (id, timestamp, type, message) VALUES (?, ?, ?, ?)') .run(uid('log'), now, 'system', - 'CheckMK: monitoring collection returned 0 hosts. The automation user may need ' + - '"Use monitoring" permission (Setup → Users → Roles). ' + - 'Attempting per-host fallback via host_config endpoint.'); + 'CheckMK: monitoring collection returned 0 hosts — automation user has no monitoring view access. ' + + 'Fix in CheckMK: Setup → Users → edit automation user → Roles → assign "Administrator" or a role with ' + + '"General Permissions → Use monitoring" and "See all hosts and services" enabled. ' + + 'Alternatively: add the automation user to all relevant Contact Groups.'); const firstHostname = [...ipToHostname.values()][0]; try {