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.
|
// Step 2: fetch live monitoring state for all hosts in one call.
|
||||||
// /domain-types/host/collections/all returns monitoring objects with extensions.state
|
// Uses query param to force the collection to return results (some CheckMK versions
|
||||||
// where 0=UP, 1=DOWN, 2=UNREACHABLE.
|
// return an empty list without an explicit filter even with full permissions).
|
||||||
let hostnameToState: Map<string, number>;
|
let hostnameToState: Map<string, number>;
|
||||||
try {
|
try {
|
||||||
|
const monQuery = encodeURIComponent(JSON.stringify({ op: '!=', left: 'name', right: '' }));
|
||||||
const monRes = await fetch(
|
const monRes = await fetch(
|
||||||
`${CHECKMK_API_URL}/domain-types/host/collections/all`,
|
`${CHECKMK_API_URL}/domain-types/host/collections/all?query=${monQuery}`,
|
||||||
{ headers }
|
{ headers }
|
||||||
);
|
);
|
||||||
if (!monRes.ok) throw new Error(checkmkHttpHint(monRes.status));
|
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.
|
// 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: monitoring collection returned 0 hosts. The automation user may need ' +
|
'CheckMK: monitoring collection returned 0 hosts — automation user has no monitoring view access. ' +
|
||||||
'"Use monitoring" permission (Setup → Users → Roles). ' +
|
'Fix in CheckMK: Setup → Users → edit automation user → Roles → assign "Administrator" or a role with ' +
|
||||||
'Attempting per-host fallback via host_config endpoint.');
|
'"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];
|
const firstHostname = [...ipToHostname.values()][0];
|
||||||
try {
|
try {
|
||||||
|
|||||||
Reference in New Issue
Block a user