feat: PoC code with poor naming and quality
This commit is contained in:
parent
b84fd5eb3a
commit
8e0d8cc3b2
|
@ -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");
|
||||
});
|
||||
};
|
|
@ -161,6 +161,7 @@ class Monitor extends BeanModel {
|
|||
kafkaProducerMessage: this.kafkaProducerMessage,
|
||||
screenshot,
|
||||
remote_browser: this.remote_browser,
|
||||
component_name: this.component_name,
|
||||
};
|
||||
|
||||
if (includeSensitiveData) {
|
||||
|
|
|
@ -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<void>}
|
||||
* @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,
|
||||
};
|
|
@ -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");
|
|
@ -86,6 +86,11 @@
|
|||
Tailscale Ping
|
||||
</option>
|
||||
</optgroup>
|
||||
<optgroup :label="$t('Third Party')">
|
||||
<option value="atlassian">
|
||||
Atlassian Statuspage
|
||||
</option>
|
||||
</optgroup>
|
||||
</select>
|
||||
</div>
|
||||
|
||||
|
@ -100,7 +105,7 @@
|
|||
</div>
|
||||
|
||||
<!-- URL -->
|
||||
<div v-if="monitor.type === 'http' || monitor.type === 'keyword' || monitor.type === 'json-query' || monitor.type === 'real-browser' " class="my-3">
|
||||
<div v-if="monitor.type === 'http' || monitor.type === 'keyword' || monitor.type === 'json-query' || monitor.type === 'real-browser' || monitor.type === 'atlassian'" class="my-3">
|
||||
<label for="url" class="form-label">{{ $t("URL") }}</label>
|
||||
<input id="url" v-model="monitor.url" type="url" class="form-control" pattern="https?://.+" required>
|
||||
</div>
|
||||
|
@ -310,6 +315,13 @@
|
|||
<input id="docker_container" v-model="monitor.docker_container" type="text" class="form-control" required>
|
||||
</div>
|
||||
|
||||
<!-- Third Party -->
|
||||
<!-- Atlassian Status page -->
|
||||
<div v-if="monitor.type === 'atlassian'" class="my-3">
|
||||
<label for="component_name" class="form-label">{{ $t("Component name") }}</label>
|
||||
<input id="component_name" v-model="monitor.component_name" type="text" class="form-control" required>
|
||||
</div>
|
||||
|
||||
<!-- Docker Host -->
|
||||
<!-- For Docker Type -->
|
||||
<div v-if="monitor.type === 'docker'" class="my-3">
|
||||
|
|
Loading…
Reference in New Issue