mirror of
https://github.com/louislam/uptime-kuma.git
synced 2024-11-23 23:04:04 +00:00
ES Lint Compliant
This commit is contained in:
parent
ba47aca51f
commit
7459654e11
2 changed files with 20 additions and 14 deletions
|
@ -11,12 +11,18 @@ class SNMPMonitorType extends MonitorType {
|
|||
async check(monitor, heartbeat, _server) {
|
||||
|
||||
const options = {
|
||||
port: monitor.port || '161',
|
||||
port: monitor.port || "161",
|
||||
retries: monitor.maxretries,
|
||||
timeout: 1000,
|
||||
version: getKey(snmp.Version, monitor.snmpVersion) || snmp.Version2c,
|
||||
};
|
||||
|
||||
/**
|
||||
* Retrieves the key from the provided object corresponding to the given value.
|
||||
* @param {object} obj - The object to search.
|
||||
* @param {*} value - The value to search for.
|
||||
* @returns {string|null} - The key associated with the value, or null if not found.
|
||||
*/
|
||||
function getKey(obj, value) {
|
||||
return Object.keys(obj).find(key => obj[key] === value) || null;
|
||||
}
|
||||
|
@ -25,7 +31,7 @@ class SNMPMonitorType extends MonitorType {
|
|||
const session = snmp.createSession(monitor.hostname, monitor.snmpCommunityString, options);
|
||||
|
||||
// Handle errors during session creation
|
||||
session.on('error', (error) => {
|
||||
session.on("error", (error) => {
|
||||
heartbeat.status = DOWN;
|
||||
heartbeat.msg = `SNMP: Error creating SNMP session: ${error.message}`;
|
||||
log.debug("monitor", heartbeat.msg);
|
||||
|
@ -42,27 +48,27 @@ class SNMPMonitorType extends MonitorType {
|
|||
});
|
||||
});
|
||||
|
||||
if (varbinds.length === 0 || getKey(snmp.ObjectType, varbinds[0].type) === 'NoSuchInstance') {
|
||||
if (varbinds.length === 0 || getKey(snmp.ObjectType, varbinds[0].type) === "NoSuchInstance") {
|
||||
throw new Error(`No varbinds returned from SNMP session (OID: ${monitor.snmpOid})`);
|
||||
} else {
|
||||
const value = varbinds[0].value;
|
||||
const numericValue = parseInt(value);
|
||||
const stringValue = value.toString('ascii');
|
||||
const stringValue = value.toString("ascii");
|
||||
|
||||
switch (monitor.snmpCondition) {
|
||||
case '>':
|
||||
case ">":
|
||||
heartbeat.status = numericValue > monitor.snmpControlValue ? UP : DOWN;
|
||||
break;
|
||||
case '>=':
|
||||
case ">=":
|
||||
heartbeat.status = numericValue >= monitor.snmpControlValue ? UP : DOWN;
|
||||
break;
|
||||
case '<':
|
||||
case "<":
|
||||
heartbeat.status = numericValue < monitor.snmpControlValue ? UP : DOWN;
|
||||
break;
|
||||
case '<=':
|
||||
case "<=":
|
||||
heartbeat.status = numericValue <= monitor.snmpControlValue ? UP : DOWN;
|
||||
break;
|
||||
case '==':
|
||||
case "==":
|
||||
if (!isNaN(value) && !isNaN(monitor.snmpControlValue)) {
|
||||
// Both values are numeric, parse them as numbers
|
||||
heartbeat.status = parseFloat(value) === parseFloat(monitor.snmpControlValue) ? UP : DOWN;
|
||||
|
@ -71,7 +77,7 @@ class SNMPMonitorType extends MonitorType {
|
|||
heartbeat.status = value.toString() === monitor.snmpControlValue.toString() ? UP : DOWN;
|
||||
}
|
||||
break;
|
||||
case 'contains':
|
||||
case "contains":
|
||||
heartbeat.status = stringValue.includes(monitor.snmpControlValue) ? UP : DOWN;
|
||||
break;
|
||||
default:
|
||||
|
@ -79,7 +85,7 @@ class SNMPMonitorType extends MonitorType {
|
|||
heartbeat.msg = `Invalid condition: ${monitor.snmpCondition}`;
|
||||
break;
|
||||
}
|
||||
heartbeat.msg = `SNMP value ` + (heartbeat.status ? `passes` : `does not pass`) + ` comparison: ${value.toString('ascii')} ${monitor.snmpCondition} ${monitor.snmpControlValue}`;
|
||||
heartbeat.msg = "SNMP value " + (heartbeat.status ? "passes" : "does not pass") + ` comparison: ${value.toString("ascii")} ${monitor.snmpCondition} ${monitor.snmpControlValue}`;
|
||||
|
||||
}
|
||||
session.close();
|
||||
|
|
Loading…
Reference in a new issue