Added Robustness

There are a lot of changes here:
-Fixed a lot of issues encountered during my testing
-JSON path is evaluated BEFORE making comparisons (this was the true intended behavior by @chakflying)
-Variable name changes (cosmetic)
-Added != operator
-Changed jsonQueryDescription (again)
This commit is contained in:
Matt Visnovsky
2024-06-06 18:52:33 -06:00
parent eaa935cba0
commit fdc145bffd
6 changed files with 61 additions and 78 deletions

View File

@@ -44,13 +44,11 @@ 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 { status, evaluation } = await evaluateJsonQuery(value, monitor.jsonPath, monitor.jsonPathOperator, monitor.expectedValue);
const { status, response } = await evaluateJsonQuery(value, monitor.jsonPath, monitor.jsonPathOperator, monitor.expectedValue);
heartbeat.status = status ? UP : DOWN;
heartbeat.msg = `SNMP value ${status ? "passes" : "does not pass"} `;
heartbeat.msg += (monitor.jsonPathOperator === "custom")
? `custom query. Query result: ${evaluation}. Expected Value: ${monitor.expectedValue}.`
: `comparison: ${value.toString()} ${monitor.jsonPathOperator} ${monitor.expectedValue}.`;
heartbeat.msg += `comparison: ${response} ${monitor.jsonPathOperator} ${monitor.expectedValue}.`;
} catch (err) {
heartbeat.status = DOWN;