You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
uptime-kuma/server/notification-providers/heii-oncall.js

74 lines
2.4 KiB

11 months ago
const { UP, DOWN, getMonitorRelativeURL } = require("../../src/util");
const { setting } = require("../util-server");
const NotificationProvider = require("./notification-provider");
const axios = require("axios");
const heiiOnCallBaseUrl = "https://heiioncall.com";
11 months ago
class HeiiOnCall extends NotificationProvider {
name = "HeiiOnCall";
/**
* @inheritdoc
*/
async send(notification, msg, monitorJSON = null, heartbeatJSON = null) {
// Payload to Heii On-Call is the entire heartbat JSON
const payload = heartbeatJSON ? heartbeatJSON : {};
if (!heartbeatJSON) {
// Test button was clicked on Notification Setup, trigger the alert as a test
payload["message"] = "Testing UptimeKuma Trigger";
return this.postNotification(notification, "alert", payload);
}
// If we can, add url back to mintor to payload
11 months ago
const baseURL = await setting("primaryBaseURL");
if (baseURL && monitorJSON) {
payload["url"] = baseURL + getMonitorRelativeURL(monitorJSON.id);
}
if (heartbeatJSON.status === DOWN) {
// Monitor is DOWN, alert on Heii On-Call
return this.postNotification(notification, "alert", payload);
}
if (heartbeatJSON.status === UP) {
// Monitor is UP, resolve on Heii On-Call
return this.postNotification(notification, "resolve", payload);
}
}
/**
* Post to Heii On-Call
* @param {BeanModel} notification Message title
* @param {string} action Trigger action (alert, resovle)
11 months ago
* @param {object} payload Data for Heii On-Call
* @returns {Promise<string>} Success message
*/
async postNotification(notification, action, payload) {
const config = {
headers: {
Accept: "application/json",
"Content-Type": "application/json",
Authorization: "Bearer " + notification.heiiOnCallApiKey,
},
};
// Post to Heii On-Call Trigger https://heiioncall.com/docs#manual-triggers
try {
await axios.post(
`${heiiOnCallBaseUrl}/triggers/${notification.heiiOnCallTriggerId}/${action}`,
payload,
config
);
} catch (error) {
this.throwGeneralAxiosError(error);
}
return "Heii On-Call post sent successfully.";
11 months ago
}
}
module.exports = HeiiOnCall;