uptime-kuma/server/notification-providers/squadcast.js

77 lines
2.3 KiB
JavaScript
Raw Normal View History

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