From f059d54349d0b71c297b504e167fd3e7d5844c47 Mon Sep 17 00:00:00 2001 From: Matt Visnovsky Date: Thu, 2 May 2024 15:07:22 -0600 Subject: [PATCH] Use frontend timeout Addresses https://github.com/louislam/uptime-kuma/pull/4717#discussion_r1585616669 --- server/monitor-types/snmp.js | 11 ++++++++--- server/server.js | 1 + src/pages/EditMonitor.vue | 12 +++++++++--- 3 files changed, 18 insertions(+), 6 deletions(-) diff --git a/server/monitor-types/snmp.js b/server/monitor-types/snmp.js index 7b30a6174..dcf02e1c0 100644 --- a/server/monitor-types/snmp.js +++ b/server/monitor-types/snmp.js @@ -13,7 +13,7 @@ class SNMPMonitorType extends MonitorType { const options = { port: monitor.port || "161", retries: monitor.maxretries, - timeout: 1000, + timeout: monitor.timeout * 1000, version: getKey(snmp.Version, monitor.snmpVersion) || snmp.Version2c, }; @@ -91,8 +91,13 @@ class SNMPMonitorType extends MonitorType { session.close(); } catch (err) { - heartbeat.status = DOWN; - heartbeat.msg = `SNMP Error: ${err.message}`; + if (err instanceof snmp.RequestTimedOutError) { + heartbeat.status = DOWN; + heartbeat.msg = `SNMP Error: Timed out after ${monitor.timeout} seconds`; + } else { + heartbeat.status = DOWN; + heartbeat.msg = `SNMP Error: ${err.message}`; + } } } diff --git a/server/server.js b/server/server.js index 206745813..7a147fce6 100644 --- a/server/server.js +++ b/server/server.js @@ -835,6 +835,7 @@ let needSetup = false; bean.snmpOid = monitor.snmpOid; bean.snmpCondition = monitor.snmpCondition; bean.snmpControlValue = monitor.snmpControlValue; + bean.timeout = monitor.timeout; bean.validate(); diff --git a/src/pages/EditMonitor.vue b/src/pages/EditMonitor.vue index a6ae1250b..cf15677cd 100644 --- a/src/pages/EditMonitor.vue +++ b/src/pages/EditMonitor.vue @@ -506,8 +506,8 @@ - -
+ +
@@ -969,7 +969,6 @@ const monitorDefaults = { retryInterval: 60, resendInterval: 0, maxretries: 0, - timeout: 48, notificationIDList: {}, ignoreTls: false, upsideDown: false, @@ -1321,6 +1320,13 @@ message HealthCheckResponse { } } + // Set default timeout + if (this.monitor.type === "snmp") { + this.monitor.timeout = 1; + } else { + this.monitor.timeout = 48; + } + // Set default SNMP version if (!this.monitor.snmpVersion) { this.monitor.snmpVersion = "2c";