Separate error cases for SNMP varbind returns

This commit is contained in:
Matt Visnovsky 2024-05-06 14:06:40 -06:00
parent c68b1c6274
commit e9b52eb0e7

View file

@ -36,10 +36,14 @@ class SNMPMonitorType extends MonitorType {
});
log.debug("monitor", `SNMP: Received varbinds (Type: ${snmp.ObjectType[varbinds[0].type]} Value: ${varbinds[0].value}`);
// Verify if any varbinds were returned from the SNMP session or if the varbind type indicates a non-existent instance.
if (varbinds.length === 0 || varbinds[0].type === snmp.ObjectType.NoSuchInstance) {
// Verify if any varbinds were returned from the SNMP session.
if (varbinds.length === 0) {
throw new Error(`No varbinds returned from SNMP session (OID: ${monitor.snmpOid})`);
}
// Check if the varbind type indicates a non-existent instance.
if (varbinds[0].type === snmp.ObjectType.NoSuchInstance) {
throw new Error(`The SNMP query was successful but no varbinds returned for OID: ${monitor.snmpOid}`);
}
// We restrict querying to one OID per monitor, therefore `varbinds[0]` will always contain the value we're interested in.