mirror of
https://github.com/louislam/uptime-kuma.git
synced 2025-09-23 22:09:21 +08:00
Add Heii On-Call
This commit is contained in:
68
server/notification-providers/heii-oncall.js
Normal file
68
server/notification-providers/heii-oncall.js
Normal file
@@ -0,0 +1,68 @@
|
||||
const { UP, DOWN, getMonitorRelativeURL } = require("../../src/util");
|
||||
const { setting } = require("../util-server");
|
||||
|
||||
const NotificationProvider = require("./notification-provider");
|
||||
const axios = require("axios");
|
||||
|
||||
const heiiOnCallBaseUrl = "http://192.168.2.1:3005";
|
||||
|
||||
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
|
||||
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)
|
||||
* @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
|
||||
await axios.post(
|
||||
`${heiiOnCallBaseUrl}/triggers/${notification.heiiOnCallTriggerId}/${action}`,
|
||||
payload,
|
||||
config
|
||||
);
|
||||
return "Sent Successfully.";
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = HeiiOnCall;
|
@@ -16,6 +16,7 @@ const Gorush = require("./notification-providers/gorush");
|
||||
const Gotify = require("./notification-providers/gotify");
|
||||
const GrafanaOncall = require("./notification-providers/grafana-oncall");
|
||||
const HomeAssistant = require("./notification-providers/home-assistant");
|
||||
const HeiiOnCall = require("./notification-providers/heii-oncall");
|
||||
const Kook = require("./notification-providers/kook");
|
||||
const Line = require("./notification-providers/line");
|
||||
const LineNotify = require("./notification-providers/linenotify");
|
||||
@@ -56,7 +57,6 @@ const ServerChan = require("./notification-providers/serverchan");
|
||||
const ZohoCliq = require("./notification-providers/zoho-cliq");
|
||||
|
||||
class Notification {
|
||||
|
||||
providerList = {};
|
||||
|
||||
/**
|
||||
@@ -87,6 +87,7 @@ class Notification {
|
||||
new Gotify(),
|
||||
new GrafanaOncall(),
|
||||
new HomeAssistant(),
|
||||
new HeiiOnCall(),
|
||||
new Kook(),
|
||||
new Line(),
|
||||
new LineNotify(),
|
||||
@@ -124,10 +125,10 @@ class Notification {
|
||||
new Webhook(),
|
||||
new WeCom(),
|
||||
new GoAlert(),
|
||||
new ZohoCliq()
|
||||
new ZohoCliq(),
|
||||
];
|
||||
for (let item of list) {
|
||||
if (! item.name) {
|
||||
if (!item.name) {
|
||||
throw new Error("Notification provider without name");
|
||||
}
|
||||
|
||||
@@ -147,9 +148,19 @@ class Notification {
|
||||
* @returns {Promise<string>} Successful msg
|
||||
* @throws Error with fail msg
|
||||
*/
|
||||
static async send(notification, msg, monitorJSON = null, heartbeatJSON = null) {
|
||||
static async send(
|
||||
notification,
|
||||
msg,
|
||||
monitorJSON = null,
|
||||
heartbeatJSON = null
|
||||
) {
|
||||
if (this.providerList[notification.type]) {
|
||||
return this.providerList[notification.type].send(notification, msg, monitorJSON, heartbeatJSON);
|
||||
return this.providerList[notification.type].send(
|
||||
notification,
|
||||
msg,
|
||||
monitorJSON,
|
||||
heartbeatJSON
|
||||
);
|
||||
} else {
|
||||
throw new Error("Notification type is not supported");
|
||||
}
|
||||
@@ -171,10 +182,9 @@ class Notification {
|
||||
userID,
|
||||
]);
|
||||
|
||||
if (! bean) {
|
||||
if (!bean) {
|
||||
throw new Error("notification not found");
|
||||
}
|
||||
|
||||
} else {
|
||||
bean = R.dispense("notification");
|
||||
}
|
||||
@@ -204,7 +214,7 @@ class Notification {
|
||||
userID,
|
||||
]);
|
||||
|
||||
if (! bean) {
|
||||
if (!bean) {
|
||||
throw new Error("notification not found");
|
||||
}
|
||||
|
||||
@@ -220,7 +230,6 @@ class Notification {
|
||||
let exists = commandExistsSync("apprise");
|
||||
return exists;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -231,16 +240,17 @@ class Notification {
|
||||
*/
|
||||
async function applyNotificationEveryMonitor(notificationID, userID) {
|
||||
let monitors = await R.getAll("SELECT id FROM monitor WHERE user_id = ?", [
|
||||
userID
|
||||
userID,
|
||||
]);
|
||||
|
||||
for (let i = 0; i < monitors.length; i++) {
|
||||
let checkNotification = await R.findOne("monitor_notification", " monitor_id = ? AND notification_id = ? ", [
|
||||
monitors[i].id,
|
||||
notificationID,
|
||||
]);
|
||||
let checkNotification = await R.findOne(
|
||||
"monitor_notification",
|
||||
" monitor_id = ? AND notification_id = ? ",
|
||||
[monitors[i].id, notificationID]
|
||||
);
|
||||
|
||||
if (! checkNotification) {
|
||||
if (!checkNotification) {
|
||||
let relation = R.dispense("monitor_notification");
|
||||
relation.monitor_id = monitors[i].id;
|
||||
relation.notification_id = notificationID;
|
||||
|
Reference in New Issue
Block a user