diff --git a/server.ts b/server.ts index a3b2338..1b1254e 100644 --- a/server.ts +++ b/server.ts @@ -760,22 +760,24 @@ async function startServer() { continue; } try { + // Request explicit columns so CheckMK includes monitoring state in the response. + const colParam = encodeURIComponent(JSON.stringify(['name', 'state', 'has_been_checked'])); const hostRes = await fetch( - `${CHECKMK_API_URL}/objects/host/${encodeURIComponent(cmkHost)}`, + `${CHECKMK_API_URL}/objects/host/${encodeURIComponent(cmkHost)}?columns=${colParam}`, { headers } ); if (!hostRes.ok) throw new Error(checkmkHttpHint(hostRes.status)); const hostData = await hostRes.json(); - // Log raw extensions once so the state field path can be verified. + // Log full raw response once so we can see all available fields and paths. if (!loggedFirstExtensions) { loggedFirstExtensions = true; db.prepare('INSERT INTO logs (id, timestamp, type, message) VALUES (?, ?, ?, ?)') .run(uid('log'), now, 'system', - `CheckMK per-host raw extensions for "${cmkHost}": ${JSON.stringify(hostData?.extensions ?? hostData).substring(0, 400)}`); + `CheckMK per-host full response for "${cmkHost}": ${JSON.stringify(hostData).substring(0, 600)}`); } - const state: number = hostData?.extensions?.state ?? -1; + const state: number = hostData?.extensions?.state ?? hostData?.state ?? -1; const newStatus = state === 0 ? 'online' : state === 1 || state === 2 ? 'offline' : 'unknown'; db.prepare('UPDATE devices SET status = ?, lastCheckedAt = ? WHERE id = ?').run(newStatus, now, dev.id); if (dev.status !== newStatus) {