mirror of
https://github.com/louislam/uptime-kuma.git
synced 2024-11-27 08:44:04 +00:00
Ensure SNMP session is closed properly
Addresses https://github.com/louislam/uptime-kuma/pull/4717#discussion_r1589858252 Co-Authored-By: Frank Elsinga <frank.elsinga@tum.de>
This commit is contained in:
parent
f4842ead68
commit
2b5d100cd3
1 changed files with 6 additions and 3 deletions
|
@ -17,8 +17,9 @@ class SNMPMonitorType extends MonitorType {
|
|||
version: parseInt(monitor.snmpVersion),
|
||||
};
|
||||
|
||||
let session;
|
||||
try {
|
||||
const session = snmp.createSession(monitor.hostname, monitor.snmpCommunityString, options);
|
||||
session = snmp.createSession(monitor.hostname, monitor.snmpCommunityString, options);
|
||||
|
||||
// Handle errors during session creation
|
||||
session.on("error", (error) => {
|
||||
|
@ -77,11 +78,13 @@ class SNMPMonitorType extends MonitorType {
|
|||
}
|
||||
heartbeat.msg = "SNMP value " + (heartbeat.status ? "passes" : "does not pass") + ` comparison: ${value.toString()} ${monitor.snmpCondition} ${snmpControlValue}`;
|
||||
|
||||
session.close();
|
||||
|
||||
} catch (err) {
|
||||
heartbeat.status = DOWN;
|
||||
heartbeat.msg = `SNMP Error: ${err.message}`;
|
||||
} finally {
|
||||
if (session) {
|
||||
session.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue