Apply suggestions from code review

Co-authored-by: Frank Elsinga <frank@elsinga.de>
This commit is contained in:
Matt Visnovsky 2024-04-30 17:54:29 -06:00 committed by GitHub
parent b4bd003626
commit ba47aca51f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -6,19 +6,10 @@ class SNMPMonitorType extends MonitorType {
name = "snmp"; name = "snmp";
/** /**
* Checks the SNMP value against the condition and control value. * @inheritdoc
* @param {object} monitor The monitor object associated with the check.
* @param {object} heartbeat The heartbeat object to update.
* @param {object} _server Unused server object.
*/ */
async check(monitor, heartbeat, _server) { 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 = { const options = {
port: monitor.port || '161', port: monitor.port || '161',
retries: monitor.maxretries, retries: monitor.maxretries,
@ -37,7 +28,7 @@ class SNMPMonitorType extends MonitorType {
session.on('error', (error) => { session.on('error', (error) => {
heartbeat.status = DOWN; heartbeat.status = DOWN;
heartbeat.msg = `SNMP: Error creating SNMP session: ${error.message}`; 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) => { const varbinds = await new Promise((resolve, reject) => {
@ -45,7 +36,7 @@ class SNMPMonitorType extends MonitorType {
if (error) { if (error) {
reject(error); reject(error);
} else { } 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); 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}`; 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) { } catch (err) {
heartbeat.status = DOWN; heartbeat.status = DOWN;