fix(checkmk): detect empty monitoring collection, log permission hint + host_config probe
This commit is contained in:
28
server.ts
28
server.ts
@ -758,12 +758,32 @@ async function startServer() {
|
|||||||
if (name !== undefined && state !== undefined) hostnameToState.set(name, state);
|
if (name !== undefined && state !== undefined) hostnameToState.set(name, state);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Diagnostic: log a sample so mismatches between config and monitoring IDs are visible
|
if (hostnameToState.size === 0 && ipToHostname.size > 0) {
|
||||||
const cfgSample = [...ipToHostname.values()].slice(0, 3).join(', ');
|
// Monitoring collection empty despite config hosts existing.
|
||||||
const monSample = [...hostnameToState.keys()].slice(0, 3).join(', ');
|
// Likely cause: automation user lacks "Use monitoring" permission in CheckMK.
|
||||||
|
// Falling back: probe one host via /objects/host_config/{name} and log its raw extensions
|
||||||
|
// so we can identify which field carries the reachability state.
|
||||||
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 diagnostic — config hosts (${ipToHostname.size}): [${cfgSample}] | monitoring hosts (${hostnameToState.size}): [${monSample}]`);
|
'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.');
|
||||||
|
|
||||||
|
const firstHostname = [...ipToHostname.values()][0];
|
||||||
|
try {
|
||||||
|
const probeRes = await fetch(
|
||||||
|
`${CHECKMK_API_URL}/objects/host_config/${encodeURIComponent(firstHostname)}`,
|
||||||
|
{ headers }
|
||||||
|
);
|
||||||
|
if (probeRes.ok) {
|
||||||
|
const probeData = await probeRes.json();
|
||||||
|
const extJson = JSON.stringify(probeData?.extensions ?? {}).substring(0, 400);
|
||||||
|
db.prepare('INSERT INTO logs (id, timestamp, type, message) VALUES (?, ?, ?, ?)')
|
||||||
|
.run(uid('log'), now, 'system',
|
||||||
|
`CheckMK probe extensions for "${firstHostname}": ${extJson}`);
|
||||||
|
}
|
||||||
|
} catch { /* probe is best-effort */ }
|
||||||
|
}
|
||||||
} catch (err: any) {
|
} catch (err: any) {
|
||||||
const msg = `CheckMK sync failed — could not fetch monitoring states: ${err?.message ?? err}`;
|
const msg = `CheckMK sync failed — could not fetch monitoring states: ${err?.message ?? err}`;
|
||||||
console.error('[CheckMK]', msg);
|
console.error('[CheckMK]', msg);
|
||||||
|
|||||||
Reference in New Issue
Block a user