mirror of
https://github.com/louislam/uptime-kuma.git
synced 2024-11-27 08:44:04 +00:00
Variable changes
-Reuse expected_value for snmpControlValue -Create jsonPathOperator for snmpCondition
This commit is contained in:
parent
d25ee8f128
commit
7eee5db4d2
5 changed files with 17 additions and 21 deletions
|
@ -4,8 +4,7 @@ exports.up = function (knex) {
|
|||
table.string("snmp_community_string", 255).defaultTo("public");
|
||||
table.string("snmp_oid").defaultTo(null);
|
||||
table.enum("snmp_version", [ "1", "2c", "3" ]).defaultTo("2c");
|
||||
table.float("snmp_control_value").defaultTo(null);
|
||||
table.string("snmp_condition").defaultTo(null);
|
||||
table.string("json_path_operator").defaultTo(null);
|
||||
});
|
||||
};
|
||||
|
||||
|
@ -14,7 +13,6 @@ exports.down = function (knex) {
|
|||
table.dropColumn("snmp_community_string");
|
||||
table.dropColumn("snmp_oid");
|
||||
table.dropColumn("snmp_version");
|
||||
table.dropColumn("snmp_control_value");
|
||||
table.dropColumn("snmp_condition");
|
||||
table.dropColumn("json_path_operator");
|
||||
});
|
||||
};
|
||||
|
|
|
@ -162,8 +162,7 @@ class Monitor extends BeanModel {
|
|||
screenshot,
|
||||
remote_browser: this.remote_browser,
|
||||
snmpOid: this.snmpOid,
|
||||
snmpCondition: this.snmpCondition,
|
||||
snmpControlValue: this.snmpControlValue,
|
||||
jsonPathOperator: this.jsonPathOperator,
|
||||
snmpVersion: this.snmpVersion,
|
||||
};
|
||||
|
||||
|
|
|
@ -50,16 +50,16 @@ class SNMPMonitorType extends MonitorType {
|
|||
const value = varbinds[0].value;
|
||||
|
||||
// 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);
|
||||
let snmpControlValue = isNaN(monitor.snmpControlValue) ? monitor.snmpControlValue.toString() : parseFloat(monitor.snmpControlValue);
|
||||
const expectedValue = isNaN(monitor.expectedValue) ? monitor.expectedValue.toString() : parseFloat(monitor.expectedValue);
|
||||
let snmpResponse = isNaN(value) ? value.toString() : parseFloat(value);
|
||||
|
||||
let jsonQueryExpression;
|
||||
switch (monitor.snmpCondition) {
|
||||
switch (monitor.jsonPathOperator) {
|
||||
case ">":
|
||||
case ">=":
|
||||
case "<":
|
||||
case "<=":
|
||||
jsonQueryExpression = `$.value ${monitor.snmpCondition} $.control`;
|
||||
jsonQueryExpression = `$.value ${monitor.jsonPathOperator} $.control`;
|
||||
break;
|
||||
case "==":
|
||||
jsonQueryExpression = "$string($.value) = $string($.control)";
|
||||
|
@ -68,13 +68,13 @@ class SNMPMonitorType extends MonitorType {
|
|||
jsonQueryExpression = "$contains($string($.value), $string($.control))";
|
||||
break;
|
||||
default:
|
||||
throw new Error(`Invalid condition ${monitor.snmpCondition}`);
|
||||
throw new Error(`Invalid condition ${monitor.jsonPathOperator}`);
|
||||
}
|
||||
|
||||
const expression = jsonata(jsonQueryExpression);
|
||||
const result = await expression.evaluate({
|
||||
value: snmpValue,
|
||||
control: monitor.snmpControlValue
|
||||
const evaluation = await expression.evaluate({
|
||||
value: snmpResponse,
|
||||
control: expectedValue
|
||||
});
|
||||
heartbeat.status = result ? UP : DOWN;
|
||||
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.snmpVersion = monitor.snmpVersion;
|
||||
bean.snmpOid = monitor.snmpOid;
|
||||
bean.snmpCondition = monitor.snmpCondition;
|
||||
bean.snmpControlValue = monitor.snmpControlValue;
|
||||
bean.jsonPathOperator = monitor.jsonPathOperator;
|
||||
bean.timeout = monitor.timeout;
|
||||
|
||||
bean.validate();
|
||||
|
|
|
@ -280,8 +280,8 @@
|
|||
<div v-if="monitor.type === 'snmp'" class="my-3">
|
||||
<div class="d-flex align-items-start">
|
||||
<div class="me-2">
|
||||
<label for="snmp_condition" class="form-label">{{ $t("Condition") }}</label>
|
||||
<select id="snmp_condition" v-model="monitor.snmpCondition" class="form-select me-3" required>
|
||||
<label for="json_path_operator" class="form-label">{{ $t("Condition") }}</label>
|
||||
<select id="json_path_operator" v-model="monitor.jsonPathOperator" class="form-select me-3" required>
|
||||
<option value=">">></option>
|
||||
<option value=">=">>=</option>
|
||||
<option value="<"><</option>
|
||||
|
@ -291,9 +291,9 @@
|
|||
</select>
|
||||
</div>
|
||||
<div class="flex-grow-1">
|
||||
<label for="snmp_control_value" class="form-label">{{ $t("Control Value") }}</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-else id="snmp_control_value" v-model="monitor.snmpControlValue" type="text" class="form-control" required>
|
||||
<label for="expectedValue" class="form-label">{{ $t("Expected Value (Control)") }}</label>
|
||||
<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="expectedValue" v-model="monitor.expectedValue" type="text" class="form-control" required>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
|
Loading…
Reference in a new issue