From ff4259380edf820b38e9c0463617a273e83c5de6 Mon Sep 17 00:00:00 2001 From: LouisLam Date: Sat, 10 Jul 2021 01:15:21 +0800 Subject: [PATCH] do not send notification if first beat is UP --- server/model/monitor.js | 33 ++++++++++++++++++--------------- 1 file changed, 18 insertions(+), 15 deletions(-) diff --git a/server/model/monitor.js b/server/model/monitor.js index 97797e09b..ef6c519e4 100644 --- a/server/model/monitor.js +++ b/server/model/monitor.js @@ -109,26 +109,29 @@ class Monitor extends BeanModel { if (! previousBeat || previousBeat.status !== bean.status) { bean.important = true; - let notificationList = await R.getAll(`SELECT notification.* FROM notification, monitor_notification WHERE monitor_id = ? AND monitor_notification.notification_id = notification.id `, [ - this.id - ]) + // Do not send if first beat is UP + if (previousBeat || bean.status !== 1) { + let notificationList = await R.getAll(`SELECT notification.* FROM notification, monitor_notification WHERE monitor_id = ? AND monitor_notification.notification_id = notification.id `, [ + this.id + ]) - let promiseList = []; + let promiseList = []; - let text; - if (bean.status === 1) { - text = "✅ Up" - } else { - text = "🔴 Down" - } + let text; + if (bean.status === 1) { + text = "✅ Up" + } else { + text = "🔴 Down" + } - let msg = `[${this.name}] [${text}] ${bean.msg}`; + let msg = `[${this.name}] [${text}] ${bean.msg}`; - for(let notification of notificationList) { - promiseList.push(Notification.send(JSON.parse(notification.config), msg, await this.toJSON(), bean.toJSON())); - } + for(let notification of notificationList) { + promiseList.push(Notification.send(JSON.parse(notification.config), msg, await this.toJSON(), bean.toJSON())); + } - await Promise.all(promiseList); + await Promise.all(promiseList); + } } else { bean.important = false;