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

61 lines
1.7 KiB
JavaScript
Raw Normal View History

const NotificationProvider = require("./notification-provider");
const axios = require("axios");
2022-09-26 09:30:43 +00:00
const { DOWN } = require("../../src/util");
class Squadcast extends NotificationProvider {
name = "squadcast";
/**
* @inheritdoc
*/
async send(notification, msg, monitorJSON = null, heartbeatJSON = null) {
const okMsg = "Sent Successfully.";
try {
let config = {};
let data = {
message: msg,
2022-09-26 09:30:43 +00:00
description: "",
tags: {},
heartbeat: heartbeatJSON,
2022-09-26 09:30:43 +00:00
source: "uptime-kuma"
};
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`;
data.status = "trigger";
} else {
2022-09-26 09:30:43 +00:00
data.message = `${monitorJSON["name"]} is UP`;
data.status = "resolve";
}
data.tags["AlertAddress"] = this.extractAdress(monitorJSON);
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"];
}
});
}
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;