From ba47aca51fd4e398b54763e3a71a8f95c028b0a7 Mon Sep 17 00:00:00 2001 From: Matt Visnovsky Date: Tue, 30 Apr 2024 17:54:29 -0600 Subject: [PATCH] Apply suggestions from code review Co-authored-by: Frank Elsinga --- server/monitor-types/snmp.js | 17 ++++------------- 1 file changed, 4 insertions(+), 13 deletions(-) diff --git a/server/monitor-types/snmp.js b/server/monitor-types/snmp.js index 2fa397161..49835dd9c 100644 --- a/server/monitor-types/snmp.js +++ b/server/monitor-types/snmp.js @@ -6,19 +6,10 @@ class SNMPMonitorType extends MonitorType { name = "snmp"; /** - * Checks the SNMP value against the condition and control value. - * @param {object} monitor The monitor object associated with the check. - * @param {object} heartbeat The heartbeat object to update. - * @param {object} _server Unused server object. + * @inheritdoc */ async check(monitor, heartbeat, _server) { - log.debug("monitor", `SNMP: Community String: ${monitor.snmpCommunityString}`); - log.debug("monitor", `SNMP: OID: ${monitor.snmpOid}`); - log.debug("monitor", `SNMP: Version: ${monitor.snmpVersion}`); - log.debug("monitor", `SNMP: Condition: ${monitor.snmpCondition}`); - log.debug("monitor", `SNMP: Control Value: ${monitor.snmpControlValue}`); - const options = { port: monitor.port || '161', retries: monitor.maxretries, @@ -37,7 +28,7 @@ class SNMPMonitorType extends MonitorType { session.on('error', (error) => { heartbeat.status = DOWN; heartbeat.msg = `SNMP: Error creating SNMP session: ${error.message}`; - log.debug("monitor", `SNMP: ${heartbeat.msg}`); + log.debug("monitor", heartbeat.msg); }); const varbinds = await new Promise((resolve, reject) => { @@ -45,7 +36,7 @@ class SNMPMonitorType extends MonitorType { if (error) { reject(error); } else { - log.debug("monitor", `SNMP: Received varbinds: Type: ${getKey(snmp.ObjectType, varbinds[0].type)}, Value: ${varbinds[0].value}`); // Log the received varbinds for debugging + log.debug("monitor", `SNMP: Received varbinds (Type=${getKey(snmp.ObjectType, varbinds[0].type)}): ${varbinds[0].value}`); resolve(varbinds); } }); @@ -91,7 +82,7 @@ class SNMPMonitorType extends MonitorType { heartbeat.msg = `SNMP value ` + (heartbeat.status ? `passes` : `does not pass`) + ` comparison: ${value.toString('ascii')} ${monitor.snmpCondition} ${monitor.snmpControlValue}`; } - session.close(); // Close the session after use + session.close(); } catch (err) { heartbeat.status = DOWN;