From e9b52eb0e7f2133bd273a365d1ee061eaeeb6d4d Mon Sep 17 00:00:00 2001 From: Matt Visnovsky Date: Mon, 6 May 2024 14:06:40 -0600 Subject: [PATCH] Separate error cases for SNMP varbind returns --- server/monitor-types/snmp.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/server/monitor-types/snmp.js b/server/monitor-types/snmp.js index 3a734d2cf..f660df538 100644 --- a/server/monitor-types/snmp.js +++ b/server/monitor-types/snmp.js @@ -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.