fix(checkmk): add query filter to monitoring endpoint, precise permission guidance in log
This commit is contained in:
14
server.ts
14
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<string, number>;
|
||||
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 {
|
||||
|
||||
Reference in New Issue
Block a user