diff --git a/db/knex_migrations/2025-03-04-0000-ping-advanced-options.js b/db/knex_migrations/2025-03-04-0000-ping-advanced-options.js index 319fb18ef..58b86036a 100644 --- a/db/knex_migrations/2025-03-04-0000-ping-advanced-options.js +++ b/db/knex_migrations/2025-03-04-0000-ping-advanced-options.js @@ -2,7 +2,6 @@ ALTER TABLE monitor ADD ping_count INTEGER default 1 not null; ALTER TABLE monitor ADD ping_numeric BOOLEAN default true not null; ALTER TABLE monitor ADD ping_deadline INTEGER default 10 not null; -ALTER TABLE monitor ADD ping_timeout INTEGER default 2 not null; */ exports.up = function (knex) { // Add new columns to table monitor @@ -11,7 +10,6 @@ exports.up = function (knex) { table.integer("ping_count").defaultTo(1).notNullable(); table.boolean("ping_numeric").defaultTo(true).notNullable(); table.integer("ping_deadline").defaultTo(10).notNullable(); - table.integer("ping_timeout").defaultTo(2).notNullable(); }); }; @@ -22,6 +20,5 @@ exports.down = function (knex) { table.dropColumn("ping_count"); table.dropColumn("ping_numeric"); table.dropColumn("ping_deadline"); - table.dropColumn("ping_timeout"); }); }; diff --git a/server/model/monitor.js b/server/model/monitor.js index 40ca4e384..5f9d08786 100644 --- a/server/model/monitor.js +++ b/server/model/monitor.js @@ -164,7 +164,6 @@ class Monitor extends BeanModel { ping_numeric: this.isPingNumeric(), ping_count: this.ping_count, ping_deadline: this.ping_deadline, - ping_timeout: this.ping_timeout, }; if (includeSensitiveData) { @@ -635,7 +634,7 @@ class Monitor extends BeanModel { bean.status = UP; } else if (this.type === "ping") { - bean.ping = await ping(this.hostname, this.ping_count, "", this.ping_numeric, this.packetSize, this.ping_deadline, this.ping_timeout); + bean.ping = await ping(this.hostname, this.ping_count, "", this.ping_numeric, this.packetSize, this.ping_deadline, this.timeout); bean.msg = ""; bean.status = UP; } else if (this.type === "push") { // Type: Push @@ -1523,16 +1522,25 @@ class Monitor extends BeanModel { throw new Error(`Packet size must be between ${PING_PACKET_SIZE_MIN} and ${PING_PACKET_SIZE_MAX} (default: ${PING_PACKET_SIZE_DEFAULT})`); } - if (this.ping_deadline && (this.ping_deadline < PING_DEADLINE_MIN || this.ping_deadline > PING_DEADLINE_MAX)) { - throw new Error(`Deadline must be between ${PING_DEADLINE_MIN} and ${PING_DEADLINE_MAX} seconds (default: ${PING_DEADLINE_DEFAULT})`); - } + if (this.type === "ping") { + // ping parameters validation + if (this.ping_deadline && (this.ping_deadline < PING_DEADLINE_MIN || this.ping_deadline > PING_DEADLINE_MAX)) { + throw new Error(`Deadline must be between ${PING_DEADLINE_MIN} and ${PING_DEADLINE_MAX} seconds (default: ${PING_DEADLINE_DEFAULT})`); + } - if (this.ping_count && (this.ping_count < PING_COUNT_MIN || this.ping_count > PING_COUNT_MAX)) { - throw new Error(`Echo requests count must be between ${PING_COUNT_MIN} and ${PING_COUNT_MAX} (default: ${PING_COUNT_DEFAULT})`); - } + if (this.ping_count && (this.ping_count < PING_COUNT_MIN || this.ping_count > PING_COUNT_MAX)) { + throw new Error(`Echo requests count must be between ${PING_COUNT_MIN} and ${PING_COUNT_MAX} (default: ${PING_COUNT_DEFAULT})`); + } - if (this.ping_timeout && (this.ping_timeout < PING_TIMEOUT_MIN || this.ping_timeout > PING_TIMEOUT_MAX)) { - throw new Error(`Timeout must be between ${PING_TIMEOUT_MIN} and ${PING_TIMEOUT_MAX} seconds (default: ${PING_TIMEOUT_DEFAULT})`); + if (this.timeout) { + const pingTimeout = Math.round(Number(this.timeout)); + + if (pingTimeout < PING_TIMEOUT_MIN || pingTimeout > PING_TIMEOUT_MAX) { + throw new Error(`Timeout must be between ${PING_TIMEOUT_MIN} and ${PING_TIMEOUT_MAX} seconds (default: ${PING_TIMEOUT_DEFAULT})`); + } + + this.timeout = pingTimeout; + } } } diff --git a/server/server.js b/server/server.js index 38b93acf9..41a730b68 100644 --- a/server/server.js +++ b/server/server.js @@ -879,7 +879,6 @@ let needSetup = false; bean.ping_numeric = monitor.ping_numeric; bean.ping_count = monitor.ping_count; bean.ping_deadline = monitor.ping_deadline; - bean.ping_timeout = monitor.ping_timeout; bean.validate(); diff --git a/src/lang/en.json b/src/lang/en.json index 28bca7d87..9a01491c4 100644 --- a/src/lang/en.json +++ b/src/lang/en.json @@ -1059,5 +1059,6 @@ "pingDeadlineLabel": "Max Duration", "pingDeadlineDescription": "Total time in seconds before ping stops, regardless of packets sent", "pingTimeoutLabel": "Response Timeout", - "pingTimeoutDescription": "Maximum time in seconds to wait for each response" + "pingTimeoutDescription": "Maximum time in seconds to wait for each response", + "pingIntervalAdjusted": "Interval has been adjusted according to deadline, timeout and packet count" } diff --git a/src/pages/EditMonitor.vue b/src/pages/EditMonitor.vue index abc96bdf7..fdd87ff26 100644 --- a/src/pages/EditMonitor.vue +++ b/src/pages/EditMonitor.vue @@ -597,8 +597,11 @@