Added Ping packet size #1891

This should fully implement #1891 by adding an extra field to the edit
monitor page and an extra column to the database. The user can now
set the size of the packet to send, it defaults to 56. A maximum limit
of 65500 was chosen to ensure that the total size of the packet does
not exceed the IPv4 maximum packet size and to comply with the limit
imposed by Windows.

Signed-off-by: Matthew Nickson <mnickson@sidingsmedia.com>
pull/1892/head
Matthew Nickson 2 years ago
parent 219b00f660
commit a54e58b4d6
No known key found for this signature in database
GPG Key ID: BF229DCFD4748E05

@ -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;

@ -61,6 +61,7 @@ class Database {
"patch-add-clickable-status-page-link.sql": true,
"patch-add-sqlserver-monitor.sql": true,
"patch-add-other-auth.sql": { parents: [ "patch-monitor-basic-auth.sql" ] },
"patch-ping-packet-size.sql": true,
};
/**

@ -82,6 +82,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,
@ -352,7 +353,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") {
@ -459,7 +460,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");

@ -28,13 +28,13 @@ function Ping(host, options) {
if (util.WIN) {
this._bin = "c:/windows/system32/ping.exe";
this._args = (options.args) ? options.args : [ "-n", "1", "-w", timeout * 1000, host ];
this._args = (options.args) ? options.args : [ "-n", "1", "-w", timeout * 1000, "-l", this._options.size, host ];
this._regmatch = /[><=]([0-9.]+?)ms/;
} else if (util.LIN) {
this._bin = "/bin/ping";
const defaultArgs = [ "-n", "-w", timeout, "-c", "1", host ];
const defaultArgs = [ "-n", "-w", timeout, "-c", "1", "-s", this._options.size, host ];
if (net.isIPv6(host) || options.ipv6) {
defaultArgs.unshift("-6");
@ -51,13 +51,13 @@ function Ping(host, options) {
this._bin = "/sbin/ping";
}
this._args = (options.args) ? options.args : [ "-n", "-t", timeout, "-c", "1", host ];
this._args = (options.args) ? options.args : [ "-n", "-t", timeout, "-c", "1", "-s", this._options.size, host ];
this._regmatch = /=([0-9.]+?) ms/;
} else if (util.BSD) {
this._bin = "/sbin/ping";
const defaultArgs = [ "-n", "-t", timeout, "-c", "1", host ];
const defaultArgs = [ "-n", "-t", timeout, "-c", "1", "-s", this._options.size, host ];
if (net.isIPv6(host) || options.ipv6) {
defaultArgs.unshift("-6");

@ -659,6 +659,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;

@ -70,15 +70,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<number>} 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;
}
@ -89,12 +90,14 @@ 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<number>} 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) => {
const ping = new Ping(hostname, {
ipv6
ipv6,
size
});
ping.send(function (err, ms, stdout) {

@ -536,4 +536,5 @@ export default {
"Domain": "Domain",
"Workstation": "Workstation",
disableCloudflaredNoAuthMsg: "You are in No Auth mode, password is not require.",
"Packet Size": "Packet Size",
};

@ -230,6 +230,12 @@
</div>
</div>
<!-- Ping packet size -->
<div v-if="monitor.type === 'ping'" class="my-3">
<label for="packet-size" class="form-label">{{ $t("Packet Size") }}</label>
<input id="packet-size" v-model="monitor.packetSize" type="number" class="form-control" required min="1" max="65500" step="1">
</div>
<!-- HTTP / Keyword only -->
<template v-if="monitor.type === 'http' || monitor.type === 'keyword' ">
<div class="my-3">
@ -589,6 +595,7 @@ export default {
notificationIDList: {},
ignoreTls: false,
upsideDown: false,
packetSize: 56,
expiryNotification: false,
maxredirects: 10,
accepted_statuscodes: [ "200-299" ],

Loading…
Cancel
Save