mirror of
https://github.com/louislam/uptime-kuma.git
synced 2024-11-23 14:54:05 +00:00
Updated the code to look more like the other notification providers
This commit is contained in:
parent
5a9c3ad353
commit
cc000117ca
1 changed files with 23 additions and 36 deletions
|
@ -10,6 +10,7 @@ class HeiiOnCall extends NotificationProvider {
|
||||||
* @inheritdoc
|
* @inheritdoc
|
||||||
*/
|
*/
|
||||||
async send(notification, msg, monitorJSON = null, heartbeatJSON = null) {
|
async send(notification, msg, monitorJSON = null, heartbeatJSON = null) {
|
||||||
|
const okMsg = "Sent Successfully.";
|
||||||
const payload = heartbeatJSON || {};
|
const payload = heartbeatJSON || {};
|
||||||
|
|
||||||
const baseURL = await setting("primaryBaseURL");
|
const baseURL = await setting("primaryBaseURL");
|
||||||
|
@ -17,34 +18,6 @@ class HeiiOnCall extends NotificationProvider {
|
||||||
payload["url"] = baseURL + getMonitorRelativeURL(monitorJSON.id);
|
payload["url"] = baseURL + getMonitorRelativeURL(monitorJSON.id);
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
|
||||||
if (!heartbeatJSON) {
|
|
||||||
// Testing or general notification like certificate expiry
|
|
||||||
payload["msg"] = msg;
|
|
||||||
return this.postNotification(notification, "alert", payload);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (heartbeatJSON.status === DOWN) {
|
|
||||||
return this.postNotification(notification, "alert", payload);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (heartbeatJSON.status === UP) {
|
|
||||||
return this.postNotification(notification, "resolve", payload);
|
|
||||||
}
|
|
||||||
} catch (error) {
|
|
||||||
this.throwGeneralAxiosError(error);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 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 = {
|
const config = {
|
||||||
headers: {
|
headers: {
|
||||||
Accept: "application/json",
|
Accept: "application/json",
|
||||||
|
@ -52,15 +25,29 @@ class HeiiOnCall extends NotificationProvider {
|
||||||
Authorization: "Bearer " + notification.heiiOnCallApiKey,
|
Authorization: "Bearer " + notification.heiiOnCallApiKey,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const heiiUrl = `https://heiioncall.com/triggers/${notification.heiiOnCallTriggerId}/`;
|
||||||
|
|
||||||
|
// docs https://heiioncall.com/docs#manual-triggers
|
||||||
|
try {
|
||||||
|
if (!heartbeatJSON) {
|
||||||
|
// Testing or general notification like certificate expiry
|
||||||
|
payload["msg"] = msg;
|
||||||
|
await axios.post(heiiUrl + "alert", payload, config);
|
||||||
|
return okMsg;
|
||||||
|
}
|
||||||
|
|
||||||
// Post to Heii On-Call Trigger https://heiioncall.com/docs#manual-triggers
|
if (heartbeatJSON.status === DOWN) {
|
||||||
await axios.post(
|
await axios.post(heiiUrl + "alert", payload, config);
|
||||||
`https://heiioncall.com/triggers/${notification.heiiOnCallTriggerId}/${action}`,
|
return okMsg;
|
||||||
payload,
|
}
|
||||||
config
|
if (heartbeatJSON.status === UP) {
|
||||||
);
|
await axios.post(heiiUrl + "resolve",payload, config);
|
||||||
|
return okMsg;
|
||||||
return "Sent Successfully";
|
}
|
||||||
|
} catch (error) {
|
||||||
|
this.throwGeneralAxiosError(error);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue