mirror of
https://github.com/louislam/uptime-kuma.git
synced 2024-11-30 18:24:03 +00:00
Merge pull request #1892 from Computroniks/feature/#1891-set-ping-packet-size
Added #1891: Set ping packet size
This commit is contained in:
commit
8816be24d8
7 changed files with 25 additions and 6 deletions
5
db/patch-ping-packet-size.sql
Normal file
5
db/patch-ping-packet-size.sql
Normal file
|
@ -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;
|
|
@ -65,6 +65,7 @@ class Database {
|
||||||
"patch-grpc-monitor.sql": true,
|
"patch-grpc-monitor.sql": true,
|
||||||
"patch-add-radius-monitor.sql": true,
|
"patch-add-radius-monitor.sql": true,
|
||||||
"patch-monitor-add-resend-interval.sql": true,
|
"patch-monitor-add-resend-interval.sql": true,
|
||||||
|
"patch-ping-packet-size.sql": true,
|
||||||
"patch-maintenance-table2.sql": true,
|
"patch-maintenance-table2.sql": true,
|
||||||
"patch-add-gamedig-monitor.sql": true,
|
"patch-add-gamedig-monitor.sql": true,
|
||||||
};
|
};
|
||||||
|
|
|
@ -87,6 +87,7 @@ class Monitor extends BeanModel {
|
||||||
expiryNotification: this.isEnabledExpiryNotification(),
|
expiryNotification: this.isEnabledExpiryNotification(),
|
||||||
ignoreTls: this.getIgnoreTls(),
|
ignoreTls: this.getIgnoreTls(),
|
||||||
upsideDown: this.isUpsideDown(),
|
upsideDown: this.isUpsideDown(),
|
||||||
|
packetSize: this.packetSize,
|
||||||
maxredirects: this.maxredirects,
|
maxredirects: this.maxredirects,
|
||||||
accepted_statuscodes: this.getAcceptedStatuscodes(),
|
accepted_statuscodes: this.getAcceptedStatuscodes(),
|
||||||
dns_resolve_type: this.dns_resolve_type,
|
dns_resolve_type: this.dns_resolve_type,
|
||||||
|
@ -375,7 +376,7 @@ class Monitor extends BeanModel {
|
||||||
bean.status = UP;
|
bean.status = UP;
|
||||||
|
|
||||||
} else if (this.type === "ping") {
|
} else if (this.type === "ping") {
|
||||||
bean.ping = await ping(this.hostname);
|
bean.ping = await ping(this.hostname, this.packetSize);
|
||||||
bean.msg = "";
|
bean.msg = "";
|
||||||
bean.status = UP;
|
bean.status = UP;
|
||||||
} else if (this.type === "dns") {
|
} else if (this.type === "dns") {
|
||||||
|
@ -485,7 +486,7 @@ class Monitor extends BeanModel {
|
||||||
bean.msg = res.data.response.servers[0].name;
|
bean.msg = res.data.response.servers[0].name;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
bean.ping = await ping(this.hostname);
|
bean.ping = await ping(this.hostname, this.packetSize);
|
||||||
} catch (_) { }
|
} catch (_) { }
|
||||||
} else {
|
} else {
|
||||||
throw new Error("Server not found on Steam");
|
throw new Error("Server not found on Steam");
|
||||||
|
|
|
@ -696,6 +696,7 @@ let needSetup = false;
|
||||||
bean.ignoreTls = monitor.ignoreTls;
|
bean.ignoreTls = monitor.ignoreTls;
|
||||||
bean.expiryNotification = monitor.expiryNotification;
|
bean.expiryNotification = monitor.expiryNotification;
|
||||||
bean.upsideDown = monitor.upsideDown;
|
bean.upsideDown = monitor.upsideDown;
|
||||||
|
bean.packetSize = monitor.packetSize;
|
||||||
bean.maxredirects = monitor.maxredirects;
|
bean.maxredirects = monitor.maxredirects;
|
||||||
bean.accepted_statuscodes_json = JSON.stringify(monitor.accepted_statuscodes);
|
bean.accepted_statuscodes_json = JSON.stringify(monitor.accepted_statuscodes);
|
||||||
bean.dns_resolve_type = monitor.dns_resolve_type;
|
bean.dns_resolve_type = monitor.dns_resolve_type;
|
||||||
|
|
|
@ -79,15 +79,16 @@ exports.tcping = function (hostname, port) {
|
||||||
/**
|
/**
|
||||||
* Ping the specified machine
|
* Ping the specified machine
|
||||||
* @param {string} hostname Hostname / address of 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
|
* @returns {Promise<number>} Time for ping in ms rounded to nearest integer
|
||||||
*/
|
*/
|
||||||
exports.ping = async (hostname) => {
|
exports.ping = async (hostname, size = 56) => {
|
||||||
try {
|
try {
|
||||||
return await exports.pingAsync(hostname);
|
return await exports.pingAsync(hostname, false, size);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
// If the host cannot be resolved, try again with ipv6
|
// If the host cannot be resolved, try again with ipv6
|
||||||
if (e.message.includes("service not known")) {
|
if (e.message.includes("service not known")) {
|
||||||
return await exports.pingAsync(hostname, true);
|
return await exports.pingAsync(hostname, true, size);
|
||||||
} else {
|
} else {
|
||||||
throw e;
|
throw e;
|
||||||
}
|
}
|
||||||
|
@ -98,14 +99,16 @@ exports.ping = async (hostname) => {
|
||||||
* Ping the specified machine
|
* Ping the specified machine
|
||||||
* @param {string} hostname Hostname / address of machine to ping
|
* @param {string} hostname Hostname / address of machine to ping
|
||||||
* @param {boolean} ipv6 Should IPv6 be used?
|
* @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
|
* @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) => {
|
return new Promise((resolve, reject) => {
|
||||||
ping.promise.probe(hostname, {
|
ping.promise.probe(hostname, {
|
||||||
v6: ipv6,
|
v6: ipv6,
|
||||||
min_reply: 1,
|
min_reply: 1,
|
||||||
deadline: 10,
|
deadline: 10,
|
||||||
|
packetSize: size,
|
||||||
}).then((res) => {
|
}).then((res) => {
|
||||||
// If ping failed, it will set field to unknown
|
// If ping failed, it will set field to unknown
|
||||||
if (res.alive) {
|
if (res.alive) {
|
||||||
|
|
|
@ -358,6 +358,7 @@
|
||||||
"Docker Hosts": "Docker Hosts",
|
"Docker Hosts": "Docker Hosts",
|
||||||
"Domain": "Domain",
|
"Domain": "Domain",
|
||||||
"Workstation": "Workstation",
|
"Workstation": "Workstation",
|
||||||
|
"Packet Size": "Packet Size",
|
||||||
"telegram": "Telegram",
|
"telegram": "Telegram",
|
||||||
"ZohoCliq": "ZohoCliq",
|
"ZohoCliq": "ZohoCliq",
|
||||||
"Bot Token": "Bot Token",
|
"Bot Token": "Bot Token",
|
||||||
|
|
|
@ -365,6 +365,12 @@
|
||||||
</div>
|
</div>
|
||||||
</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 -->
|
<!-- HTTP / Keyword only -->
|
||||||
<template v-if="monitor.type === 'http' || monitor.type === 'keyword' || monitor.type === 'grpc-keyword' ">
|
<template v-if="monitor.type === 'http' || monitor.type === 'keyword' || monitor.type === 'grpc-keyword' ">
|
||||||
<div class="my-3">
|
<div class="my-3">
|
||||||
|
@ -842,6 +848,7 @@ message HealthCheckResponse {
|
||||||
notificationIDList: {},
|
notificationIDList: {},
|
||||||
ignoreTls: false,
|
ignoreTls: false,
|
||||||
upsideDown: false,
|
upsideDown: false,
|
||||||
|
packetSize: 56,
|
||||||
expiryNotification: false,
|
expiryNotification: false,
|
||||||
maxredirects: 10,
|
maxredirects: 10,
|
||||||
accepted_statuscodes: [ "200-299" ],
|
accepted_statuscodes: [ "200-299" ],
|
||||||
|
|
Loading…
Reference in a new issue