From 8e0d8cc3b2fce46b85694e610ef99a39559e2b0d Mon Sep 17 00:00:00 2001 From: Seluard Date: Tue, 26 Mar 2024 20:12:24 +0100 Subject: [PATCH] feat: PoC code with poor naming and quality --- .../2024-03-26-0000-atlassian-statuspage.js | 16 ++++++ server/model/monitor.js | 1 + server/monitor-types/atlassian.js | 53 +++++++++++++++++++ server/uptime-kuma-server.js | 2 + src/pages/EditMonitor.vue | 14 ++++- 5 files changed, 85 insertions(+), 1 deletion(-) create mode 100644 db/knex_migrations/2024-03-26-0000-atlassian-statuspage.js create mode 100644 server/monitor-types/atlassian.js diff --git a/db/knex_migrations/2024-03-26-0000-atlassian-statuspage.js b/db/knex_migrations/2024-03-26-0000-atlassian-statuspage.js new file mode 100644 index 00000000..869c2743 --- /dev/null +++ b/db/knex_migrations/2024-03-26-0000-atlassian-statuspage.js @@ -0,0 +1,16 @@ +exports.up = function (knex) { + // Add new column monitor.mqtt_check_type + return knex.schema + .alterTable("monitor", function (table) { + table.string("component_name", 255); + }); + +}; + +exports.down = function (knex) { + // Drop column monitor.mqtt_check_type + return knex.schema + .alterTable("monitor", function (table) { + table.dropColumn("component_name"); + }); +}; diff --git a/server/model/monitor.js b/server/model/monitor.js index 1667b83a..a345a182 100644 --- a/server/model/monitor.js +++ b/server/model/monitor.js @@ -161,6 +161,7 @@ class Monitor extends BeanModel { kafkaProducerMessage: this.kafkaProducerMessage, screenshot, remote_browser: this.remote_browser, + component_name: this.component_name, }; if (includeSensitiveData) { diff --git a/server/monitor-types/atlassian.js b/server/monitor-types/atlassian.js new file mode 100644 index 00000000..cacd303e --- /dev/null +++ b/server/monitor-types/atlassian.js @@ -0,0 +1,53 @@ +const { MonitorType } = require("./monitor-type"); +const { UP,log, DOWN } = require("../../src/util"); + +/** + * A AtlassianStatusPage class extends the MonitorType. + * It will check Status page API and monitor specific component. + */ +class Atlassian extends MonitorType { + + name = "atlassian"; + + /** + * 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 + */ + async check(monitor, heartbeat) { + try { + log.info("AtlassianStatus",monitor.url); + log.info("AtlassianStatus",monitor.component_name); + const response = (await fetch(monitor.url)); + const body = await response.json(); + // log.debug("AtlassianStatus",body["components"]); + let component_status = new Map(); + for (let index = 0; index < body["components"].length; index++) { + const element = body["components"][index]; + component_status.set(element["name"],element["status"]) + } + log.debug("AtlassianStatus",component_status); + if (component_status.get(monitor.component_name)!= undefined ) { + if (component_status.get(monitor.component_name) === "operational") { + log.debug("AtlassianStatus",component_status.get(monitor.component_name)) + heartbeat.status = UP + }else { + heartbeat.status = DOWN + } + } else { + throw new Error("Component not exist into the status"); + } + + } catch (err) { + // trigger log function somewhere to display a notification or alert to the user (but how?) + throw new Error(`StatusPage check errors: ${err}`); + } + } +} + +module.exports = { + Atlassian, +}; diff --git a/server/uptime-kuma-server.js b/server/uptime-kuma-server.js index bcf497b5..fc6ec275 100644 --- a/server/uptime-kuma-server.js +++ b/server/uptime-kuma-server.js @@ -113,6 +113,7 @@ class UptimeKumaServer { UptimeKumaServer.monitorTypeList["tailscale-ping"] = new TailscalePing(); UptimeKumaServer.monitorTypeList["dns"] = new DnsMonitorType(); UptimeKumaServer.monitorTypeList["mqtt"] = new MqttMonitorType(); + UptimeKumaServer.monitorTypeList["atlassian"] = new Atlassian(); // Allow all CORS origins (polling) in development let cors = undefined; @@ -516,3 +517,4 @@ const { RealBrowserMonitorType } = require("./monitor-types/real-browser-monitor const { TailscalePing } = require("./monitor-types/tailscale-ping"); const { DnsMonitorType } = require("./monitor-types/dns"); const { MqttMonitorType } = require("./monitor-types/mqtt"); +const { Atlassian } = require("./monitor-types/atlassian"); \ No newline at end of file diff --git a/src/pages/EditMonitor.vue b/src/pages/EditMonitor.vue index e9f3ac83..a32c2cc8 100644 --- a/src/pages/EditMonitor.vue +++ b/src/pages/EditMonitor.vue @@ -86,6 +86,11 @@ Tailscale Ping + + + @@ -100,7 +105,7 @@ -
+
@@ -310,6 +315,13 @@
+ + +
+ + +
+