|
|
@ -1,5 +1,6 @@
|
|
|
|
const https = require("https");
|
|
|
|
const https = require("https");
|
|
|
|
const dayjs = require("dayjs");
|
|
|
|
const dayjs = require("dayjs");
|
|
|
|
|
|
|
|
const mqtt = require("mqtt");
|
|
|
|
const utc = require("dayjs/plugin/utc");
|
|
|
|
const utc = require("dayjs/plugin/utc");
|
|
|
|
let timezone = require("dayjs/plugin/timezone");
|
|
|
|
let timezone = require("dayjs/plugin/timezone");
|
|
|
|
dayjs.extend(utc);
|
|
|
|
dayjs.extend(utc);
|
|
|
@ -7,7 +8,7 @@ dayjs.extend(timezone);
|
|
|
|
const axios = require("axios");
|
|
|
|
const axios = require("axios");
|
|
|
|
const { Prometheus } = require("../prometheus");
|
|
|
|
const { Prometheus } = require("../prometheus");
|
|
|
|
const { debug, UP, DOWN, PENDING, flipStatus, TimeLogger } = require("../../src/util");
|
|
|
|
const { debug, UP, DOWN, PENDING, flipStatus, TimeLogger } = require("../../src/util");
|
|
|
|
const { tcping, ping, dnsResolve, checkCertificate, checkStatusCode, getTotalClientInRoom, setting, errorLog } = require("../util-server");
|
|
|
|
const { tcping, ping, dnsResolve, checkCertificate, checkStatusCode, getTotalClientInRoom, setting, errorLog, mqttAsync } = require("../util-server");
|
|
|
|
const { R } = require("redbean-node");
|
|
|
|
const { R } = require("redbean-node");
|
|
|
|
const { BeanModel } = require("redbean-node/dist/bean-model");
|
|
|
|
const { BeanModel } = require("redbean-node/dist/bean-model");
|
|
|
|
const { Notification } = require("../notification");
|
|
|
|
const { Notification } = require("../notification");
|
|
|
@ -112,7 +113,7 @@ class Monitor extends BeanModel {
|
|
|
|
// undefined if not https
|
|
|
|
// undefined if not https
|
|
|
|
let tlsInfo = undefined;
|
|
|
|
let tlsInfo = undefined;
|
|
|
|
|
|
|
|
|
|
|
|
if (! previousBeat) {
|
|
|
|
if (!previousBeat) {
|
|
|
|
previousBeat = await R.findOne("heartbeat", " monitor_id = ? ORDER BY time DESC", [
|
|
|
|
previousBeat = await R.findOne("heartbeat", " monitor_id = ? ORDER BY time DESC", [
|
|
|
|
this.id,
|
|
|
|
this.id,
|
|
|
|
]);
|
|
|
|
]);
|
|
|
@ -130,7 +131,7 @@ class Monitor extends BeanModel {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Duration
|
|
|
|
// Duration
|
|
|
|
if (! isFirstBeat) {
|
|
|
|
if (!isFirstBeat) {
|
|
|
|
bean.duration = dayjs(bean.time).diff(dayjs(previousBeat.time), "second");
|
|
|
|
bean.duration = dayjs(bean.time).diff(dayjs(previousBeat.time), "second");
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
bean.duration = 0;
|
|
|
|
bean.duration = 0;
|
|
|
@ -153,7 +154,7 @@ class Monitor extends BeanModel {
|
|
|
|
},
|
|
|
|
},
|
|
|
|
httpsAgent: new https.Agent({
|
|
|
|
httpsAgent: new https.Agent({
|
|
|
|
maxCachedSessions: 0, // Use Custom agent to disable session reuse (https://github.com/nodejs/node/issues/3940)
|
|
|
|
maxCachedSessions: 0, // Use Custom agent to disable session reuse (https://github.com/nodejs/node/issues/3940)
|
|
|
|
rejectUnauthorized: ! this.getIgnoreTls(),
|
|
|
|
rejectUnauthorized: !this.getIgnoreTls(),
|
|
|
|
}),
|
|
|
|
}),
|
|
|
|
maxRedirects: this.maxredirects,
|
|
|
|
maxRedirects: this.maxredirects,
|
|
|
|
validateStatus: (status) => {
|
|
|
|
validateStatus: (status) => {
|
|
|
@ -296,7 +297,7 @@ class Monitor extends BeanModel {
|
|
|
|
},
|
|
|
|
},
|
|
|
|
httpsAgent: new https.Agent({
|
|
|
|
httpsAgent: new https.Agent({
|
|
|
|
maxCachedSessions: 0, // Use Custom agent to disable session reuse (https://github.com/nodejs/node/issues/3940)
|
|
|
|
maxCachedSessions: 0, // Use Custom agent to disable session reuse (https://github.com/nodejs/node/issues/3940)
|
|
|
|
rejectUnauthorized: ! this.getIgnoreTls(),
|
|
|
|
rejectUnauthorized: !this.getIgnoreTls(),
|
|
|
|
}),
|
|
|
|
}),
|
|
|
|
maxRedirects: this.maxredirects,
|
|
|
|
maxRedirects: this.maxredirects,
|
|
|
|
validateStatus: (status) => {
|
|
|
|
validateStatus: (status) => {
|
|
|
@ -319,6 +320,14 @@ class Monitor extends BeanModel {
|
|
|
|
throw new Error("Server not found on Steam");
|
|
|
|
throw new Error("Server not found on Steam");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} else if (this.type === "mqtt") {
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
bean.msg = await mqttAsync(this.url, this.topic, this.successMessage);
|
|
|
|
|
|
|
|
bean.status = UP;
|
|
|
|
|
|
|
|
} catch (error) {
|
|
|
|
|
|
|
|
bean.status = DOWN;
|
|
|
|
|
|
|
|
bean.msg = error.message;
|
|
|
|
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
bean.msg = "Unknown Monitor Type";
|
|
|
|
bean.msg = "Unknown Monitor Type";
|
|
|
|
bean.status = PENDING;
|
|
|
|
bean.status = PENDING;
|
|
|
@ -385,7 +394,7 @@ class Monitor extends BeanModel {
|
|
|
|
|
|
|
|
|
|
|
|
previousBeat = bean;
|
|
|
|
previousBeat = bean;
|
|
|
|
|
|
|
|
|
|
|
|
if (! this.isStop) {
|
|
|
|
if (!this.isStop) {
|
|
|
|
|
|
|
|
|
|
|
|
if (demoMode) {
|
|
|
|
if (demoMode) {
|
|
|
|
if (beatInterval < 20) {
|
|
|
|
if (beatInterval < 20) {
|
|
|
@ -407,7 +416,7 @@ class Monitor extends BeanModel {
|
|
|
|
errorLog(e, false);
|
|
|
|
errorLog(e, false);
|
|
|
|
console.error("Please report to https://github.com/louislam/uptime-kuma/issues");
|
|
|
|
console.error("Please report to https://github.com/louislam/uptime-kuma/issues");
|
|
|
|
|
|
|
|
|
|
|
|
if (! this.isStop) {
|
|
|
|
if (!this.isStop) {
|
|
|
|
console.log("Try to restart the monitor");
|
|
|
|
console.log("Try to restart the monitor");
|
|
|
|
this.heartbeatInterval = setTimeout(safeBeat, this.interval * 1000);
|
|
|
|
this.heartbeatInterval = setTimeout(safeBeat, this.interval * 1000);
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -590,7 +599,7 @@ class Monitor extends BeanModel {
|
|
|
|
|
|
|
|
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
// Handle new monitor with only one beat, because the beat's duration = 0
|
|
|
|
// Handle new monitor with only one beat, because the beat's duration = 0
|
|
|
|
let status = parseInt(await R.getCell("SELECT `status` FROM heartbeat WHERE monitor_id = ?", [ monitorID ]));
|
|
|
|
let status = parseInt(await R.getCell("SELECT `status` FROM heartbeat WHERE monitor_id = ?", [monitorID]));
|
|
|
|
|
|
|
|
|
|
|
|
if (status === UP) {
|
|
|
|
if (status === UP) {
|
|
|
|
uptime = 1;
|
|
|
|
uptime = 1;
|
|
|
|