2022-09-26 05:16:34 -04:00
|
|
|
const NotificationProvider = require("./notification-provider");
|
|
|
|
const axios = require("axios");
|
2022-09-26 05:30:43 -04:00
|
|
|
const { DOWN } = require("../../src/util");
|
2022-09-26 05:16:34 -04:00
|
|
|
|
|
|
|
class Squadcast extends NotificationProvider {
|
|
|
|
name = "squadcast";
|
|
|
|
|
2023-08-11 03:46:41 -04:00
|
|
|
/**
|
|
|
|
* @inheritdoc
|
|
|
|
*/
|
2022-09-26 05:16:34 -04:00
|
|
|
async send(notification, msg, monitorJSON = null, heartbeatJSON = null) {
|
2024-03-14 09:21:15 -04:00
|
|
|
const okMsg = "Sent Successfully.";
|
2022-09-26 05:16:34 -04:00
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
let config = {};
|
|
|
|
let data = {
|
|
|
|
message: msg,
|
2022-09-26 05:30:43 -04:00
|
|
|
description: "",
|
2022-09-26 05:16:34 -04:00
|
|
|
tags: {},
|
|
|
|
heartbeat: heartbeatJSON,
|
2022-09-26 05:30:43 -04:00
|
|
|
source: "uptime-kuma"
|
|
|
|
};
|
2022-09-26 05:16:34 -04:00
|
|
|
|
|
|
|
if (heartbeatJSON !== null) {
|
|
|
|
data.description = heartbeatJSON["msg"];
|
|
|
|
data.event_id = heartbeatJSON["monitorID"];
|
|
|
|
|
|
|
|
if (heartbeatJSON["status"] === DOWN) {
|
2022-09-26 05:30:43 -04:00
|
|
|
data.message = `${monitorJSON["name"]} is DOWN`;
|
2022-09-26 05:16:34 -04:00
|
|
|
data.status = "trigger";
|
|
|
|
} else {
|
2022-09-26 05:30:43 -04:00
|
|
|
data.message = `${monitorJSON["name"]} is UP`;
|
2022-09-26 05:16:34 -04:00
|
|
|
data.status = "resolve";
|
|
|
|
}
|
|
|
|
|
|
|
|
let address;
|
|
|
|
switch (monitorJSON["type"]) {
|
|
|
|
case "ping":
|
|
|
|
address = monitorJSON["hostname"];
|
|
|
|
break;
|
|
|
|
case "port":
|
|
|
|
case "dns":
|
|
|
|
case "steam":
|
|
|
|
address = monitorJSON["hostname"];
|
|
|
|
if (monitorJSON["port"]) {
|
|
|
|
address += ":" + monitorJSON["port"];
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
address = monitorJSON["url"];
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
data.tags["AlertAddress"] = address;
|
|
|
|
|
|
|
|
monitorJSON["tags"].forEach(tag => {
|
|
|
|
data.tags[tag["name"]] = {
|
|
|
|
value: tag["value"]
|
|
|
|
};
|
|
|
|
if (tag["color"] !== null) {
|
2022-09-26 05:30:43 -04:00
|
|
|
data.tags[tag["name"]]["color"] = tag["color"];
|
2022-09-26 05:16:34 -04:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
await axios.post(notification.squadcastWebhookURL, data, config);
|
|
|
|
return okMsg;
|
|
|
|
|
|
|
|
} catch (error) {
|
|
|
|
this.throwGeneralAxiosError(error);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2022-09-26 05:30:43 -04:00
|
|
|
module.exports = Squadcast;
|