mirror of
https://github.com/louislam/uptime-kuma.git
synced 2024-11-27 16:54:04 +00:00
Apply suggestions from code review
Co-authored-by: Frank Elsinga <frank@elsinga.de>
This commit is contained in:
parent
5dc4bb64d5
commit
b5a73e5ad7
3 changed files with 21 additions and 19 deletions
|
@ -602,9 +602,12 @@ class Monitor extends BeanModel {
|
||||||
|
|
||||||
const { status, response } = await evaluateJsonQuery(data, this.jsonPath, this.jsonPathOperator, this.expectedValue);
|
const { status, response } = await evaluateJsonQuery(data, this.jsonPath, this.jsonPathOperator, this.expectedValue);
|
||||||
|
|
||||||
bean.status = status ? UP : DOWN;
|
if (status) {
|
||||||
bean.msg = `JSON query ${status ? "passes" : "does not pass"} `;
|
bean.status = UP;
|
||||||
bean.msg += `comparison: ${response} ${this.jsonPathOperator} ${this.expectedValue}.`;
|
bean.msg = `JSON query passes (comparing ${response} ${this.jsonPathOperator} ${this.expectedValue})`
|
||||||
|
} else {
|
||||||
|
throw new Error(`JSON query does not pass (comparing ${response} ${this.jsonPathOperator} ${this.expectedValue})`);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -9,17 +9,15 @@ class SNMPMonitorType extends MonitorType {
|
||||||
* @inheritdoc
|
* @inheritdoc
|
||||||
*/
|
*/
|
||||||
async check(monitor, heartbeat, _server) {
|
async check(monitor, heartbeat, _server) {
|
||||||
|
let session;
|
||||||
const options = {
|
try {
|
||||||
|
const sessionOptions = {
|
||||||
port: monitor.port || "161",
|
port: monitor.port || "161",
|
||||||
retries: monitor.maxretries,
|
retries: monitor.maxretries,
|
||||||
timeout: monitor.timeout * 1000,
|
timeout: monitor.timeout * 1000,
|
||||||
version: snmp.Version[monitor.snmpVersion],
|
version: snmp.Version[monitor.snmpVersion],
|
||||||
};
|
};
|
||||||
|
session = snmp.createSession(monitor.hostname, monitor.radiusPassword, sessionOptions);
|
||||||
let session;
|
|
||||||
try {
|
|
||||||
session = snmp.createSession(monitor.hostname, monitor.radiusPassword, options);
|
|
||||||
|
|
||||||
// Handle errors during session creation
|
// Handle errors during session creation
|
||||||
session.on("error", (error) => {
|
session.on("error", (error) => {
|
||||||
|
@ -46,13 +44,14 @@ class SNMPMonitorType extends MonitorType {
|
||||||
|
|
||||||
const { status, response } = 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;
|
if (status) {
|
||||||
heartbeat.msg = `SNMP value ${status ? "passes" : "does not pass"} `;
|
bean.status = UP;
|
||||||
heartbeat.msg += `comparison: ${response} ${monitor.jsonPathOperator} ${monitor.expectedValue}.`;
|
bean.msg = `JSON query passes (comparing ${response} ${this.jsonPathOperator} ${this.expectedValue})`
|
||||||
|
} else {
|
||||||
|
throw new Error(`JSON query does not pass (comparing ${response} ${this.jsonPathOperator} ${this.expectedValue})`);
|
||||||
|
}
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
heartbeat.status = DOWN;
|
throw err;
|
||||||
heartbeat.msg = `Error: ${err.message}`;
|
|
||||||
} finally {
|
} finally {
|
||||||
if (session) {
|
if (session) {
|
||||||
session.close();
|
session.close();
|
||||||
|
|
|
@ -1354,7 +1354,7 @@ message HealthCheckResponse {
|
||||||
|
|
||||||
// Set default SNMP version
|
// Set default SNMP version
|
||||||
if (!this.monitor.snmpVersion) {
|
if (!this.monitor.snmpVersion) {
|
||||||
this.monitor.snmpVersion = "1";
|
this.monitor.snmpVersion = "2c";
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set default jsonPath
|
// Set default jsonPath
|
||||||
|
|
Loading…
Reference in a new issue