From d74facded62268d33864816cdeec59eb13c7ff66 Mon Sep 17 00:00:00 2001 From: Frank Elsinga Date: Tue, 4 Jun 2024 05:01:53 +0200 Subject: [PATCH 1/2] removed some monitor drift in terms of imports and documentation --- server/monitor-types/dns.js | 7 +------ server/monitor-types/mongodb.js | 10 ++-------- server/monitor-types/monitor-type.js | 7 +------ server/monitor-types/mqtt.js | 9 ++------- .../real-browser-monitor-type.js | 4 +--- server/monitor-types/tailscale-ping.js | 20 +++---------------- 6 files changed, 10 insertions(+), 47 deletions(-) diff --git a/server/monitor-types/dns.js b/server/monitor-types/dns.js index d4cd02ab5..1a35a99d9 100644 --- a/server/monitor-types/dns.js +++ b/server/monitor-types/dns.js @@ -4,8 +4,7 @@ const dayjs = require("dayjs"); const { dnsResolve } = require("../util-server"); const { R } = require("redbean-node"); -class DnsMonitorType extends MonitorType { - +export class DnsMonitorType extends MonitorType { name = "dns"; /** @@ -50,7 +49,3 @@ class DnsMonitorType extends MonitorType { heartbeat.status = UP; } } - -module.exports = { - DnsMonitorType, -}; diff --git a/server/monitor-types/mongodb.js b/server/monitor-types/mongodb.js index fd3a1dc98..37ad3b460 100644 --- a/server/monitor-types/mongodb.js +++ b/server/monitor-types/mongodb.js @@ -3,8 +3,7 @@ const { UP } = require("../../src/util"); const { MongoClient } = require("mongodb"); const jsonata = require("jsonata"); -class MongodbMonitorType extends MonitorType { - +export class MongodbMonitorType extends MonitorType { name = "mongodb"; /** @@ -49,8 +48,7 @@ class MongodbMonitorType extends MonitorType { * Connect to and run MongoDB command on a MongoDB database * @param {string} connectionString The database connection string * @param {object} command MongoDB command to run on the database - * @returns {Promise<(string[] | object[] | object)>} Response from - * server + * @returns {Promise<(string[] | object[] | object)>} Response from server */ async runMongodbCommand(connectionString, command) { let client = await MongoClient.connect(connectionString); @@ -59,7 +57,3 @@ class MongodbMonitorType extends MonitorType { return result; } } - -module.exports = { - MongodbMonitorType, -}; diff --git a/server/monitor-types/monitor-type.js b/server/monitor-types/monitor-type.js index eb75307b2..c837b63a1 100644 --- a/server/monitor-types/monitor-type.js +++ b/server/monitor-types/monitor-type.js @@ -1,4 +1,4 @@ -class MonitorType { +export class MonitorType { name = undefined; /** @@ -11,9 +11,4 @@ class MonitorType { async check(monitor, heartbeat, server) { throw new Error("You need to override check()"); } - } - -module.exports = { - MonitorType, -}; diff --git a/server/monitor-types/mqtt.js b/server/monitor-types/mqtt.js index 9b2db43d0..2a4c1296c 100644 --- a/server/monitor-types/mqtt.js +++ b/server/monitor-types/mqtt.js @@ -3,16 +3,11 @@ const { log, UP } = require("../../src/util"); const mqtt = require("mqtt"); const jsonata = require("jsonata"); -class MqttMonitorType extends MonitorType { - +export class MqttMonitorType extends MonitorType { name = "mqtt"; /** - * Run the monitoring check on the MQTT monitor - * @param {Monitor} monitor Monitor to check - * @param {Heartbeat} heartbeat Monitor heartbeat to update - * @param {UptimeKumaServer} server Uptime Kuma server - * @returns {Promise} + * @inheritdoc */ async check(monitor, heartbeat, server) { const receivedMessage = await this.mqttAsync(monitor.hostname, monitor.mqttTopic, { diff --git a/server/monitor-types/real-browser-monitor-type.js b/server/monitor-types/real-browser-monitor-type.js index f1219af18..84b06d939 100644 --- a/server/monitor-types/real-browser-monitor-type.js +++ b/server/monitor-types/real-browser-monitor-type.js @@ -228,8 +228,7 @@ async function testRemoteBrowser(remoteBrowserURL) { throw new Error(e.message); } } -class RealBrowserMonitorType extends MonitorType { - +export class RealBrowserMonitorType extends MonitorType { name = "real-browser"; /** @@ -266,7 +265,6 @@ class RealBrowserMonitorType extends MonitorType { } module.exports = { - RealBrowserMonitorType, testChrome, resetChrome, testRemoteBrowser, diff --git a/server/monitor-types/tailscale-ping.js b/server/monitor-types/tailscale-ping.js index 5950cc21c..308ffa436 100644 --- a/server/monitor-types/tailscale-ping.js +++ b/server/monitor-types/tailscale-ping.js @@ -2,23 +2,13 @@ const { MonitorType } = require("./monitor-type"); const { UP } = require("../../src/util"); const childProcessAsync = require("promisify-child-process"); -/** - * A TailscalePing class extends the MonitorType. - * It runs Tailscale ping to monitor the status of a specific node. - */ -class TailscalePing extends MonitorType { - +export class TailscalePing extends MonitorType { name = "tailscale-ping"; /** - * Checks the ping status of the URL associated with the monitor. - * It then parses the Tailscale ping command output to update the heatrbeat. - * @param {object} monitor The monitor object associated with the check. - * @param {object} heartbeat The heartbeat object to update. - * @returns {Promise} - * @throws Error if checking Tailscale ping encounters any error + * @inheritdoc */ - async check(monitor, heartbeat) { + async check(monitor, heartbeat, _server) { try { let tailscaleOutput = await this.runTailscalePing(monitor.hostname, monitor.interval); this.parseTailscaleOutput(tailscaleOutput, heartbeat); @@ -81,7 +71,3 @@ class TailscalePing extends MonitorType { } } } - -module.exports = { - TailscalePing, -}; From b6cd21c71a679ef8374fed0761c844748d7aa174 Mon Sep 17 00:00:00 2001 From: Frank Elsinga Date: Fri, 7 Jun 2024 15:54:28 +0200 Subject: [PATCH 2/2] Removed where I was wrong about imports --- server/monitor-types/dns.js | 6 +++++- server/monitor-types/mongodb.js | 6 +++++- server/monitor-types/monitor-type.js | 6 +++++- server/monitor-types/mqtt.js | 2 +- server/monitor-types/real-browser-monitor-type.js | 4 +++- server/monitor-types/tailscale-ping.js | 6 +++++- 6 files changed, 24 insertions(+), 6 deletions(-) diff --git a/server/monitor-types/dns.js b/server/monitor-types/dns.js index 1a35a99d9..d038b6805 100644 --- a/server/monitor-types/dns.js +++ b/server/monitor-types/dns.js @@ -4,7 +4,7 @@ const dayjs = require("dayjs"); const { dnsResolve } = require("../util-server"); const { R } = require("redbean-node"); -export class DnsMonitorType extends MonitorType { +class DnsMonitorType extends MonitorType { name = "dns"; /** @@ -49,3 +49,7 @@ export class DnsMonitorType extends MonitorType { heartbeat.status = UP; } } + +module.exports = { + DnsMonitorType, +}; diff --git a/server/monitor-types/mongodb.js b/server/monitor-types/mongodb.js index 37ad3b460..73747db9c 100644 --- a/server/monitor-types/mongodb.js +++ b/server/monitor-types/mongodb.js @@ -3,7 +3,7 @@ const { UP } = require("../../src/util"); const { MongoClient } = require("mongodb"); const jsonata = require("jsonata"); -export class MongodbMonitorType extends MonitorType { +class MongodbMonitorType extends MonitorType { name = "mongodb"; /** @@ -57,3 +57,7 @@ export class MongodbMonitorType extends MonitorType { return result; } } + +module.exports = { + MongodbMonitorType, +}; diff --git a/server/monitor-types/monitor-type.js b/server/monitor-types/monitor-type.js index c837b63a1..8290bdd76 100644 --- a/server/monitor-types/monitor-type.js +++ b/server/monitor-types/monitor-type.js @@ -1,4 +1,4 @@ -export class MonitorType { +class MonitorType { name = undefined; /** @@ -12,3 +12,7 @@ export class MonitorType { throw new Error("You need to override check()"); } } + +module.exports = { + MonitorType, +}; diff --git a/server/monitor-types/mqtt.js b/server/monitor-types/mqtt.js index 2a4c1296c..ad734ce8e 100644 --- a/server/monitor-types/mqtt.js +++ b/server/monitor-types/mqtt.js @@ -3,7 +3,7 @@ const { log, UP } = require("../../src/util"); const mqtt = require("mqtt"); const jsonata = require("jsonata"); -export class MqttMonitorType extends MonitorType { +class MqttMonitorType extends MonitorType { name = "mqtt"; /** diff --git a/server/monitor-types/real-browser-monitor-type.js b/server/monitor-types/real-browser-monitor-type.js index 84b06d939..f1219af18 100644 --- a/server/monitor-types/real-browser-monitor-type.js +++ b/server/monitor-types/real-browser-monitor-type.js @@ -228,7 +228,8 @@ async function testRemoteBrowser(remoteBrowserURL) { throw new Error(e.message); } } -export class RealBrowserMonitorType extends MonitorType { +class RealBrowserMonitorType extends MonitorType { + name = "real-browser"; /** @@ -265,6 +266,7 @@ export class RealBrowserMonitorType extends MonitorType { } module.exports = { + RealBrowserMonitorType, testChrome, resetChrome, testRemoteBrowser, diff --git a/server/monitor-types/tailscale-ping.js b/server/monitor-types/tailscale-ping.js index 308ffa436..8537651cd 100644 --- a/server/monitor-types/tailscale-ping.js +++ b/server/monitor-types/tailscale-ping.js @@ -2,7 +2,7 @@ const { MonitorType } = require("./monitor-type"); const { UP } = require("../../src/util"); const childProcessAsync = require("promisify-child-process"); -export class TailscalePing extends MonitorType { +class TailscalePing extends MonitorType { name = "tailscale-ping"; /** @@ -71,3 +71,7 @@ export class TailscalePing extends MonitorType { } } } + +module.exports = { + TailscalePing, +};