diff --git a/db/patch-ping-packet-size.sql b/db/patch-ping-packet-size.sql new file mode 100644 index 000000000..d65ec8ed8 --- /dev/null +++ b/db/patch-ping-packet-size.sql @@ -0,0 +1,5 @@ +-- You should not modify if this have pushed to Github, unless it does serious wrong with the db. +BEGIN TRANSACTION; +ALTER TABLE monitor + ADD packet_size INTEGER DEFAULT 56 NOT NULL; +COMMIT; diff --git a/server/database.js b/server/database.js index 3b4b88f90..5ca88cac5 100644 --- a/server/database.js +++ b/server/database.js @@ -65,6 +65,7 @@ class Database { "patch-grpc-monitor.sql": true, "patch-add-radius-monitor.sql": true, "patch-monitor-add-resend-interval.sql": true, + "patch-ping-packet-size.sql": true, "patch-maintenance-table2.sql": true, "patch-add-gamedig-monitor.sql": true, }; diff --git a/server/model/monitor.js b/server/model/monitor.js index 57d4a17ca..e06c15e2a 100644 --- a/server/model/monitor.js +++ b/server/model/monitor.js @@ -87,6 +87,7 @@ class Monitor extends BeanModel { expiryNotification: this.isEnabledExpiryNotification(), ignoreTls: this.getIgnoreTls(), upsideDown: this.isUpsideDown(), + packetSize: this.packetSize, maxredirects: this.maxredirects, accepted_statuscodes: this.getAcceptedStatuscodes(), dns_resolve_type: this.dns_resolve_type, @@ -375,7 +376,7 @@ class Monitor extends BeanModel { bean.status = UP; } else if (this.type === "ping") { - bean.ping = await ping(this.hostname); + bean.ping = await ping(this.hostname, this.packetSize); bean.msg = ""; bean.status = UP; } else if (this.type === "dns") { @@ -485,7 +486,7 @@ class Monitor extends BeanModel { bean.msg = res.data.response.servers[0].name; try { - bean.ping = await ping(this.hostname); + bean.ping = await ping(this.hostname, this.packetSize); } catch (_) { } } else { throw new Error("Server not found on Steam"); diff --git a/server/server.js b/server/server.js index 432196954..9c18fcd1d 100644 --- a/server/server.js +++ b/server/server.js @@ -696,6 +696,7 @@ let needSetup = false; bean.ignoreTls = monitor.ignoreTls; bean.expiryNotification = monitor.expiryNotification; bean.upsideDown = monitor.upsideDown; + bean.packetSize = monitor.packetSize; bean.maxredirects = monitor.maxredirects; bean.accepted_statuscodes_json = JSON.stringify(monitor.accepted_statuscodes); bean.dns_resolve_type = monitor.dns_resolve_type; diff --git a/server/util-server.js b/server/util-server.js index 4519b0837..a2f1aa466 100644 --- a/server/util-server.js +++ b/server/util-server.js @@ -79,15 +79,16 @@ exports.tcping = function (hostname, port) { /** * Ping the specified machine * @param {string} hostname Hostname / address of machine + * @param {number} [size=56] Size of packet to send * @returns {Promise} Time for ping in ms rounded to nearest integer */ -exports.ping = async (hostname) => { +exports.ping = async (hostname, size = 56) => { try { - return await exports.pingAsync(hostname); + return await exports.pingAsync(hostname, false, size); } catch (e) { // If the host cannot be resolved, try again with ipv6 if (e.message.includes("service not known")) { - return await exports.pingAsync(hostname, true); + return await exports.pingAsync(hostname, true, size); } else { throw e; } @@ -98,14 +99,16 @@ exports.ping = async (hostname) => { * Ping the specified machine * @param {string} hostname Hostname / address of machine to ping * @param {boolean} ipv6 Should IPv6 be used? + * @param {number} [size = 56] Size of ping packet to send * @returns {Promise} Time for ping in ms rounded to nearest integer */ -exports.pingAsync = function (hostname, ipv6 = false) { +exports.pingAsync = function (hostname, ipv6 = false, size = 56) { return new Promise((resolve, reject) => { ping.promise.probe(hostname, { v6: ipv6, min_reply: 1, deadline: 10, + packetSize: size, }).then((res) => { // If ping failed, it will set field to unknown if (res.alive) { diff --git a/src/lang/en.json b/src/lang/en.json index a36a12187..14ba725fd 100644 --- a/src/lang/en.json +++ b/src/lang/en.json @@ -358,6 +358,7 @@ "Docker Hosts": "Docker Hosts", "Domain": "Domain", "Workstation": "Workstation", + "Packet Size": "Packet Size", "telegram": "Telegram", "ZohoCliq": "ZohoCliq", "Bot Token": "Bot Token", diff --git a/src/pages/EditMonitor.vue b/src/pages/EditMonitor.vue index 16ecb887b..50e97bab8 100644 --- a/src/pages/EditMonitor.vue +++ b/src/pages/EditMonitor.vue @@ -365,6 +365,12 @@ + +
+ + +
+