|
|
@ -50,16 +50,16 @@ class SNMPMonitorType extends MonitorType {
|
|
|
|
const value = varbinds[0].value;
|
|
|
|
const value = varbinds[0].value;
|
|
|
|
|
|
|
|
|
|
|
|
// Check if inputs are numeric. If not, re-parse as strings. This ensures comparisons are handled correctly.
|
|
|
|
// Check if inputs are numeric. If not, re-parse as strings. This ensures comparisons are handled correctly.
|
|
|
|
let snmpValue = isNaN(value) ? value.toString() : parseFloat(value);
|
|
|
|
const expectedValue = isNaN(monitor.expectedValue) ? monitor.expectedValue.toString() : parseFloat(monitor.expectedValue);
|
|
|
|
let snmpControlValue = isNaN(monitor.snmpControlValue) ? monitor.snmpControlValue.toString() : parseFloat(monitor.snmpControlValue);
|
|
|
|
let snmpResponse = isNaN(value) ? value.toString() : parseFloat(value);
|
|
|
|
|
|
|
|
|
|
|
|
let jsonQueryExpression;
|
|
|
|
let jsonQueryExpression;
|
|
|
|
switch (monitor.snmpCondition) {
|
|
|
|
switch (monitor.jsonPathOperator) {
|
|
|
|
case ">":
|
|
|
|
case ">":
|
|
|
|
case ">=":
|
|
|
|
case ">=":
|
|
|
|
case "<":
|
|
|
|
case "<":
|
|
|
|
case "<=":
|
|
|
|
case "<=":
|
|
|
|
jsonQueryExpression = `$.value ${monitor.snmpCondition} $.control`;
|
|
|
|
jsonQueryExpression = `$.value ${monitor.jsonPathOperator} $.control`;
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
case "==":
|
|
|
|
case "==":
|
|
|
|
jsonQueryExpression = "$string($.value) = $string($.control)";
|
|
|
|
jsonQueryExpression = "$string($.value) = $string($.control)";
|
|
|
@ -68,13 +68,13 @@ class SNMPMonitorType extends MonitorType {
|
|
|
|
jsonQueryExpression = "$contains($string($.value), $string($.control))";
|
|
|
|
jsonQueryExpression = "$contains($string($.value), $string($.control))";
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
default:
|
|
|
|
throw new Error(`Invalid condition ${monitor.snmpCondition}`);
|
|
|
|
throw new Error(`Invalid condition ${monitor.jsonPathOperator}`);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const expression = jsonata(jsonQueryExpression);
|
|
|
|
const expression = jsonata(jsonQueryExpression);
|
|
|
|
const result = await expression.evaluate({
|
|
|
|
const evaluation = await expression.evaluate({
|
|
|
|
value: snmpValue,
|
|
|
|
value: snmpResponse,
|
|
|
|
control: monitor.snmpControlValue
|
|
|
|
control: expectedValue
|
|
|
|
});
|
|
|
|
});
|
|
|
|
heartbeat.status = result ? UP : DOWN;
|
|
|
|
heartbeat.status = result ? UP : DOWN;
|
|
|
|
heartbeat.msg = `SNMP value ${result ? "passes" : "does not pass"} comparison: ${snmpValue} ${monitor.snmpCondition} ${snmpControlValue}`;
|
|
|
|
heartbeat.msg = `SNMP value ${result ? "passes" : "does not pass"} comparison: ${snmpValue} ${monitor.snmpCondition} ${snmpControlValue}`;
|
|
|
|