Skip to content

Commit

Permalink
Use frontend timeout
Browse files Browse the repository at this point in the history
Addresses #4717 (comment)
  • Loading branch information
mattv8 committed May 2, 2024
1 parent d83c2b9 commit f059d54
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 6 deletions.
11 changes: 8 additions & 3 deletions server/monitor-types/snmp.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};

Expand Down Expand Up @@ -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}`;
}
}
}

Expand Down
1 change: 1 addition & 0 deletions server/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down
12 changes: 9 additions & 3 deletions src/pages/EditMonitor.vue
Original file line number Diff line number Diff line change
Expand Up @@ -506,8 +506,8 @@
<input id="retry-interval" v-model="monitor.retryInterval" type="number" class="form-control" required :min="minInterval" step="1">
</div>

<!-- Timeout: HTTP / Keyword only -->
<div v-if="monitor.type === 'http' || monitor.type === 'keyword' || monitor.type === 'json-query'" class="my-3">
<!-- Timeout: HTTP / Keyword / SNMP only -->
<div v-if="monitor.type === 'http' || monitor.type === 'keyword' || monitor.type === 'json-query' || monitor.type === 'snmp'" class="my-3">
<label for="timeout" class="form-label">{{ $t("Request Timeout") }} ({{ $t("timeoutAfter", [ monitor.timeout || clampTimeout(monitor.interval) ]) }})</label>
<input id="timeout" v-model="monitor.timeout" type="number" class="form-control" required min="0" step="0.1">
</div>
Expand Down Expand Up @@ -969,7 +969,6 @@ const monitorDefaults = {
retryInterval: 60,
resendInterval: 0,
maxretries: 0,
timeout: 48,
notificationIDList: {},
ignoreTls: false,
upsideDown: false,
Expand Down Expand Up @@ -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";
Expand Down

0 comments on commit f059d54

Please sign in to comment.