mirror of
https://github.com/louislam/uptime-kuma.git
synced 2024-12-26 22:19:43 -08:00
Variable changes
-Reuse expected_value for snmpControlValue -Create jsonPathOperator for snmpCondition
This commit is contained in:
parent
d25ee8f128
commit
7eee5db4d2
|
@ -4,8 +4,7 @@ exports.up = function (knex) {
|
||||||
table.string("snmp_community_string", 255).defaultTo("public");
|
table.string("snmp_community_string", 255).defaultTo("public");
|
||||||
table.string("snmp_oid").defaultTo(null);
|
table.string("snmp_oid").defaultTo(null);
|
||||||
table.enum("snmp_version", [ "1", "2c", "3" ]).defaultTo("2c");
|
table.enum("snmp_version", [ "1", "2c", "3" ]).defaultTo("2c");
|
||||||
table.float("snmp_control_value").defaultTo(null);
|
table.string("json_path_operator").defaultTo(null);
|
||||||
table.string("snmp_condition").defaultTo(null);
|
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -14,7 +13,6 @@ exports.down = function (knex) {
|
||||||
table.dropColumn("snmp_community_string");
|
table.dropColumn("snmp_community_string");
|
||||||
table.dropColumn("snmp_oid");
|
table.dropColumn("snmp_oid");
|
||||||
table.dropColumn("snmp_version");
|
table.dropColumn("snmp_version");
|
||||||
table.dropColumn("snmp_control_value");
|
table.dropColumn("json_path_operator");
|
||||||
table.dropColumn("snmp_condition");
|
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
|
@ -162,8 +162,7 @@ class Monitor extends BeanModel {
|
||||||
screenshot,
|
screenshot,
|
||||||
remote_browser: this.remote_browser,
|
remote_browser: this.remote_browser,
|
||||||
snmpOid: this.snmpOid,
|
snmpOid: this.snmpOid,
|
||||||
snmpCondition: this.snmpCondition,
|
jsonPathOperator: this.jsonPathOperator,
|
||||||
snmpControlValue: this.snmpControlValue,
|
|
||||||
snmpVersion: this.snmpVersion,
|
snmpVersion: this.snmpVersion,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -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}`;
|
||||||
|
|
|
@ -832,8 +832,7 @@ let needSetup = false;
|
||||||
bean.remote_browser = monitor.remote_browser;
|
bean.remote_browser = monitor.remote_browser;
|
||||||
bean.snmpVersion = monitor.snmpVersion;
|
bean.snmpVersion = monitor.snmpVersion;
|
||||||
bean.snmpOid = monitor.snmpOid;
|
bean.snmpOid = monitor.snmpOid;
|
||||||
bean.snmpCondition = monitor.snmpCondition;
|
bean.jsonPathOperator = monitor.jsonPathOperator;
|
||||||
bean.snmpControlValue = monitor.snmpControlValue;
|
|
||||||
bean.timeout = monitor.timeout;
|
bean.timeout = monitor.timeout;
|
||||||
|
|
||||||
bean.validate();
|
bean.validate();
|
||||||
|
|
|
@ -280,8 +280,8 @@
|
||||||
<div v-if="monitor.type === 'snmp'" class="my-3">
|
<div v-if="monitor.type === 'snmp'" class="my-3">
|
||||||
<div class="d-flex align-items-start">
|
<div class="d-flex align-items-start">
|
||||||
<div class="me-2">
|
<div class="me-2">
|
||||||
<label for="snmp_condition" class="form-label">{{ $t("Condition") }}</label>
|
<label for="json_path_operator" class="form-label">{{ $t("Condition") }}</label>
|
||||||
<select id="snmp_condition" v-model="monitor.snmpCondition" class="form-select me-3" required>
|
<select id="json_path_operator" v-model="monitor.jsonPathOperator" class="form-select me-3" required>
|
||||||
<option value=">">></option>
|
<option value=">">></option>
|
||||||
<option value=">=">>=</option>
|
<option value=">=">>=</option>
|
||||||
<option value="<"><</option>
|
<option value="<"><</option>
|
||||||
|
@ -291,9 +291,9 @@
|
||||||
</select>
|
</select>
|
||||||
</div>
|
</div>
|
||||||
<div class="flex-grow-1">
|
<div class="flex-grow-1">
|
||||||
<label for="snmp_control_value" class="form-label">{{ $t("Control Value") }}</label>
|
<label for="expectedValue" class="form-label">{{ $t("Expected Value (Control)") }}</label>
|
||||||
<input v-if="monitor.snmpCondition !== 'contains' && monitor.snmpCondition !== '=='" id="snmp_control_value" v-model="monitor.snmpControlValue" type="number" class="form-control" required step=".01">
|
<input v-if="monitor.jsonPathOperator !== 'contains' && monitor.jsonPathOperator !== '==' && monitor.jsonPathOperator !== 'custom'" id="expectedValue" v-model="monitor.expectedValue" type="number" class="form-control" required step=".01">
|
||||||
<input v-else id="snmp_control_value" v-model="monitor.snmpControlValue" type="text" class="form-control" required>
|
<input v-else id="expectedValue" v-model="monitor.expectedValue" type="text" class="form-control" required>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
Loading…
Reference in a new issue