From 4386d0afadc93dd3db6201663a069b882bdab7aa Mon Sep 17 00:00:00 2001 From: Matt Visnovsky Date: Sun, 5 May 2024 15:47:43 -0600 Subject: [PATCH] Apply suggestions from code review Addresses: -https://github.com/louislam/uptime-kuma/pull/4717#discussion_r1589805237 -https://github.com/louislam/uptime-kuma/pull/4717#discussion_r1589806199 -https://github.com/louislam/uptime-kuma/pull/4717#discussion_r1589853470 -https://github.com/louislam/uptime-kuma/pull/4717#discussion_r1589854032 --- server/monitor-types/snmp.js | 6 ++---- src/pages/EditMonitor.vue | 6 ++++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/server/monitor-types/snmp.js b/server/monitor-types/snmp.js index ea9c3a85c..24537fce3 100644 --- a/server/monitor-types/snmp.js +++ b/server/monitor-types/snmp.js @@ -25,9 +25,7 @@ class SNMPMonitorType extends MonitorType { // Handle errors during session creation session.on("error", (error) => { - heartbeat.status = DOWN; - heartbeat.msg = `SNMP: Error creating SNMP session: ${error.message}`; - log.debug("monitor", heartbeat.msg); + throw new Error(`Error creating SNMP session: ${error.message}`); }); const varbinds = await new Promise((resolve, reject) => { @@ -35,11 +33,11 @@ class SNMPMonitorType extends MonitorType { if (error) { reject(error); } else { - log.debug("monitor", `SNMP: Received varbinds (Type=${getKey(snmp.ObjectType, varbinds[0].type)}): ${varbinds[0].value}`); resolve(varbinds); } }); }); + log.debug("monitor", `SNMP: Received varbinds (Type=${getKey(snmp.ObjectType, varbinds[0].type)}): ${varbinds[0].value}`); // Verify if any varbinds were returned from the SNMP session or if the varbind type indicates a non-existent instance. // The `getKey` method retrieves the key associated with the varbind type from the snmp.ObjectType object. diff --git a/src/pages/EditMonitor.vue b/src/pages/EditMonitor.vue index cf15677cd..0f73c7535 100644 --- a/src/pages/EditMonitor.vue +++ b/src/pages/EditMonitor.vue @@ -1320,11 +1320,13 @@ message HealthCheckResponse { } } - // Set default timeout + // Set a default timeout of 1 second for SNMP monitors when querying a single OID. + // Since we're only querying a single OID, a shorter timeout is sufficient to ensure timely responses + // without unnecessary delays. This helps keep the monitoring process lightweight and efficient. if (this.monitor.type === "snmp") { this.monitor.timeout = 1; } else { - this.monitor.timeout = 48; + this.monitor.timeout = 48; // Default timeout for other monitor types } // Set default SNMP version