From 41d32bb9dde554794613df002696841d6dceab1f Mon Sep 17 00:00:00 2001 From: Domenic Horner Date: Sat, 4 Sep 2021 20:08:18 +0800 Subject: [PATCH] Undo parm changes --- server/model/monitor.js | 11 ++++++++++- server/notification.js | 14 +------------- server/server.js | 2 +- 3 files changed, 12 insertions(+), 15 deletions(-) diff --git a/server/model/monitor.js b/server/model/monitor.js index 126d59b1..19f21d92 100644 --- a/server/model/monitor.js +++ b/server/model/monitor.js @@ -270,9 +270,18 @@ class Monitor extends BeanModel { this.id, ]) + let text; + if (bean.status === UP) { + text = "✅ Up" + } else { + text = "🔴 Down" + } + + let msg = `[${this.name}] [${text}] ${bean.msg}`; + for (let notification of notificationList) { try { - await Notification.send(JSON.parse(notification.config), this.name, await this.toJSON(), bean.toJSON()) + await Notification.send(JSON.parse(notification.config), msg, await this.toJSON(), bean.toJSON()) } catch (e) { console.error("Cannot send notification to " + notification.name); console.log(e); diff --git a/server/notification.js b/server/notification.js index beb1ff9d..f78401d9 100644 --- a/server/notification.js +++ b/server/notification.js @@ -17,21 +17,9 @@ class Notification { * @returns {Promise} Successful msg * Throw Error with fail msg */ - static async send(notification, monitorName = null, monitorJSON = null, heartbeatJSON = null) { + static async send(notification, msg, monitorJSON = null, heartbeatJSON = null) { let okMsg = "Sent Successfully. "; - let msg = `[${notification.name}] Testing`; - // heartbeatJSON is only defined if we're not testing - if(heartbeatJSON) { - let text; - if (heartbeatJSON["status"] === UP) { - text = "✅ Up" - } else { - text = "🔴 Down" - } - msg = `[${monitorName}] [${text}] ${heartbeatJSON["msg"]}`; - } - if (notification.type === "telegram") { try { await axios.get(`https://api.telegram.org/bot${notification.telegramBotToken}/sendMessage`, { diff --git a/server/server.js b/server/server.js index 8f4516dc..39191de7 100644 --- a/server/server.js +++ b/server/server.js @@ -552,7 +552,7 @@ let indexHTML = fs.readFileSync("./dist/index.html").toString(); try { checkLogin(socket) - let msg = await Notification.send(notification) + let msg = await Notification.send(notification, notification.name + " Testing") callback({ ok: true,