mirror of
https://github.com/louislam/uptime-kuma.git
synced 2024-11-27 16:54:04 +00:00
fix ping
This commit is contained in:
parent
e0ae9a9e73
commit
d5149f90b4
3 changed files with 5 additions and 9 deletions
|
@ -11,7 +11,7 @@ const { debug } = require("../src/util");
|
||||||
|
|
||||||
module.exports = Ping;
|
module.exports = Ping;
|
||||||
|
|
||||||
function Ping (host, options) {
|
function Ping(host, options) {
|
||||||
if (!host) {
|
if (!host) {
|
||||||
throw new Error("You must specify a host to ping!");
|
throw new Error("You must specify a host to ping!");
|
||||||
}
|
}
|
||||||
|
@ -106,7 +106,7 @@ Ping.prototype.send = function (callback) {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
function onEnd () {
|
function onEnd() {
|
||||||
let stdout = this.stdout._stdout,
|
let stdout = this.stdout._stdout,
|
||||||
stderr = this.stderr._stderr,
|
stderr = this.stderr._stderr,
|
||||||
ms;
|
ms;
|
||||||
|
@ -122,10 +122,6 @@ Ping.prototype.send = function (callback) {
|
||||||
ms = stdout.match(self._regmatch); // parse out the ##ms response
|
ms = stdout.match(self._regmatch); // parse out the ##ms response
|
||||||
ms = (ms && ms[1]) ? Number(ms[1]) : ms;
|
ms = (ms && ms[1]) ? Number(ms[1]) : ms;
|
||||||
|
|
||||||
if (! ms) {
|
|
||||||
debug(stdout)
|
|
||||||
}
|
|
||||||
|
|
||||||
callback(null, ms, stdout);
|
callback(null, ms, stdout);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
@ -581,7 +581,7 @@ let indexHTML = fs.readFileSync("./dist/index.html").toString();
|
||||||
if (hostname) {
|
if (hostname) {
|
||||||
console.log(`Listening on ${hostname}:${port}`);
|
console.log(`Listening on ${hostname}:${port}`);
|
||||||
} else {
|
} else {
|
||||||
console.log("Listening on ${port}");
|
console.log(`Listening on ${port}`);
|
||||||
}
|
}
|
||||||
startMonitors();
|
startMonitors();
|
||||||
});
|
});
|
||||||
|
|
|
@ -47,11 +47,11 @@ exports.tcping = function (hostname, port) {
|
||||||
|
|
||||||
exports.ping = async (hostname) => {
|
exports.ping = async (hostname) => {
|
||||||
try {
|
try {
|
||||||
await exports.pingAsync(hostname);
|
return await exports.pingAsync(hostname);
|
||||||
} 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")) {
|
||||||
await exports.pingAsync(hostname, true);
|
return await exports.pingAsync(hostname, true);
|
||||||
} else {
|
} else {
|
||||||
throw e;
|
throw e;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue