2022-09-26 09:16:34 +00:00
|
|
|
const NotificationProvider = require("./notification-provider");
|
|
|
|
const axios = require("axios");
|
2022-09-26 09:30:43 +00:00
|
|
|
const { DOWN } = require("../../src/util");
|
2022-09-26 09:16:34 +00:00
|
|
|
|
|
|
|
class Squadcast extends NotificationProvider {
|
|
|
|
|
|
|
|
name = "squadcast";
|
|
|
|
|
|
|
|
async send(notification, msg, monitorJSON = null, heartbeatJSON = null) {
|
|
|
|
let okMsg = "Sent Successfully.";
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
let config = {};
|
|
|
|
let data = {
|
|
|
|
message: msg,
|
2022-09-26 09:30:43 +00:00
|
|
|
description: "",
|
2022-09-26 09:16:34 +00:00
|
|
|
tags: {},
|
|
|
|
heartbeat: heartbeatJSON,
|
2022-09-26 09:30:43 +00:00
|
|
|
source: "uptime-kuma"
|
|
|
|
};
|
2022-09-26 09:16:34 +00:00
|
|
|
|
|
|
|
if (heartbeatJSON !== null) {
|
|
|
|
data.description = heartbeatJSON["msg"];
|
|
|
|
data.event_id = heartbeatJSON["monitorID"];
|
|
|
|
|
|
|
|
if (heartbeatJSON["status"] === DOWN) {
|
2022-09-26 09:30:43 +00:00
|
|
|
data.message = `${monitorJSON["name"]} is DOWN`;
|
2022-09-26 09:16:34 +00:00
|
|
|
data.status = "trigger";
|
|
|
|
} else {
|
2022-09-26 09:30:43 +00:00
|
|
|
data.message = `${monitorJSON["name"]} is UP`;
|
2022-09-26 09:16:34 +00: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 09:30:43 +00:00
|
|
|
data.tags[tag["name"]]["color"] = tag["color"];
|
2022-09-26 09:16:34 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
await axios.post(notification.squadcastWebhookURL, data, config);
|
|
|
|
return okMsg;
|
|
|
|
|
|
|
|
} catch (error) {
|
|
|
|
this.throwGeneralAxiosError(error);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2022-09-26 09:30:43 +00:00
|
|
|
module.exports = Squadcast;
|