From cc000117ca9b8f888c69a31b9c8f2841b79bab7f Mon Sep 17 00:00:00 2001 From: Frank Elsinga Date: Wed, 14 Feb 2024 23:41:35 +0100 Subject: [PATCH] Updated the code to look more like the other notification providers --- server/notification-providers/heii-oncall.js | 49 +++++++------------- 1 file changed, 18 insertions(+), 31 deletions(-) diff --git a/server/notification-providers/heii-oncall.js b/server/notification-providers/heii-oncall.js index 585fa138..87b9e3b3 100644 --- a/server/notification-providers/heii-oncall.js +++ b/server/notification-providers/heii-oncall.js @@ -10,6 +10,7 @@ class HeiiOnCall extends NotificationProvider { * @inheritdoc */ async send(notification, msg, monitorJSON = null, heartbeatJSON = null) { + const okMsg = "Sent Successfully."; const payload = heartbeatJSON || {}; const baseURL = await setting("primaryBaseURL"); @@ -17,50 +18,36 @@ class HeiiOnCall extends NotificationProvider { payload["url"] = baseURL + getMonitorRelativeURL(monitorJSON.id); } + const config = { + headers: { + Accept: "application/json", + "Content-Type": "application/json", + 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; - return this.postNotification(notification, "alert", payload); + await axios.post(heiiUrl + "alert", payload, config); + return okMsg; } if (heartbeatJSON.status === DOWN) { - return this.postNotification(notification, "alert", payload); + await axios.post(heiiUrl + "alert", payload, config); + return okMsg; } - if (heartbeatJSON.status === UP) { - return this.postNotification(notification, "resolve", payload); + await axios.post(heiiUrl + "resolve",payload, config); + return okMsg; } } 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} 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( - `https://heiioncall.com/triggers/${notification.heiiOnCallTriggerId}/${action}`, - payload, - config - ); - - return "Sent Successfully"; } }