debug(checkmk): log full host response, add columns param to get state
This commit is contained in:
10
server.ts
10
server.ts
@ -760,22 +760,24 @@ async function startServer() {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
try {
|
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(
|
const hostRes = await fetch(
|
||||||
`${CHECKMK_API_URL}/objects/host/${encodeURIComponent(cmkHost)}`,
|
`${CHECKMK_API_URL}/objects/host/${encodeURIComponent(cmkHost)}?columns=${colParam}`,
|
||||||
{ headers }
|
{ headers }
|
||||||
);
|
);
|
||||||
if (!hostRes.ok) throw new Error(checkmkHttpHint(hostRes.status));
|
if (!hostRes.ok) throw new Error(checkmkHttpHint(hostRes.status));
|
||||||
const hostData = await hostRes.json();
|
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) {
|
if (!loggedFirstExtensions) {
|
||||||
loggedFirstExtensions = true;
|
loggedFirstExtensions = true;
|
||||||
db.prepare('INSERT INTO logs (id, timestamp, type, message) VALUES (?, ?, ?, ?)')
|
db.prepare('INSERT INTO logs (id, timestamp, type, message) VALUES (?, ?, ?, ?)')
|
||||||
.run(uid('log'), now, 'system',
|
.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';
|
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);
|
db.prepare('UPDATE devices SET status = ?, lastCheckedAt = ? WHERE id = ?').run(newStatus, now, dev.id);
|
||||||
if (dev.status !== newStatus) {
|
if (dev.status !== newStatus) {
|
||||||
|
|||||||
Reference in New Issue
Block a user