Also return result of the evaluation

-Maximum compatibility with @chakflying's existing json-query monitor code.
This commit is contained in:
Matt Visnovsky
2024-06-06 10:09:35 -06:00
parent 10d3188dd3
commit eaa935cba0
4 changed files with 33 additions and 23 deletions

View File

@@ -609,13 +609,13 @@ class Monitor extends BeanModel {
}
}
const result = await evaluateJsonQuery(data, this.jsonPath, this.jsonPathOperator, this.expectedValue);
const { status, evaluation } = await evaluateJsonQuery(data, this.jsonPath, this.jsonPathOperator, this.expectedValue);
if (result) {
if (status) {
bean.msg += ", expected value is found";
bean.status = UP;
} else {
throw new Error(`${bean.msg}, but value is not equal to expected value, value was: [${result}]`);
throw new Error(`${bean.msg}, but value is not equal to expected value, value was: [${evaluation}]`);
}
}

View File

@@ -44,12 +44,12 @@ class SNMPMonitorType extends MonitorType {
// We restrict querying to one OID per monitor, therefore `varbinds[0]` will always contain the value we're interested in.
const value = varbinds[0].value;
const result = await evaluateJsonQuery(value, monitor.jsonPath, monitor.jsonPathOperator, monitor.expectedValue);
const { status, evaluation } = await evaluateJsonQuery(value, monitor.jsonPath, monitor.jsonPathOperator, monitor.expectedValue);
heartbeat.status = result ? UP : DOWN;
heartbeat.msg = `SNMP value ${result ? "passes" : "does not pass"} `;
heartbeat.status = status ? UP : DOWN;
heartbeat.msg = `SNMP value ${status ? "passes" : "does not pass"} `;
heartbeat.msg += (monitor.jsonPathOperator === "custom")
? `custom query. Query result: ${result}. Expected Value: ${monitor.expectedValue}.`
? `custom query. Query result: ${evaluation}. Expected Value: ${monitor.expectedValue}.`
: `comparison: ${value.toString()} ${monitor.jsonPathOperator} ${monitor.expectedValue}.`;
} catch (err) {