From f32441e2f65827b9263a13f5692fdf247d9a9f61 Mon Sep 17 00:00:00 2001 From: zImPatrick <23613354+zImPatrick@users.noreply.github.com> Date: Mon, 12 Dec 2022 17:58:11 +0100 Subject: [PATCH 1/2] fix discord notification not sending when docker container is down --- server/notification-providers/discord.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/notification-providers/discord.js b/server/notification-providers/discord.js index 28ead7b7a..ac5c8ae84 100644 --- a/server/notification-providers/discord.js +++ b/server/notification-providers/discord.js @@ -64,7 +64,7 @@ class Discord extends NotificationProvider { }, { name: "Error", - value: heartbeatJSON["msg"], + value: heartbeatJSON["msg"] == null ? "N/A" : heartbeatJSON["msg"], }, ], }], From 14fffcf06bbcbf095a71fcdeaca5d3584b0c8173 Mon Sep 17 00:00:00 2001 From: Louis Lam Date: Sat, 24 Dec 2022 14:23:50 +0800 Subject: [PATCH 2/2] Globally fix if heartbeatJSON["msg"] is undefined --- server/model/monitor.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/server/model/monitor.js b/server/model/monitor.js index 6c6ccbcc2..cb60156ca 100644 --- a/server/model/monitor.js +++ b/server/model/monitor.js @@ -1069,7 +1069,13 @@ class Monitor extends BeanModel { for (let notification of notificationList) { try { - await Notification.send(JSON.parse(notification.config), msg, await monitor.toJSON(false), bean.toJSON()); + // Prevent if the msg is undefined, notifications such as Discord cannot send out. + const heartbeatJSON = bean.toJSON(); + if (!heartbeatJSON["msg"]) { + heartbeatJSON["msg"] = ""; + } + + await Notification.send(JSON.parse(notification.config), msg, await monitor.toJSON(false), heartbeatJSON); } catch (e) { log.error("monitor", "Cannot send notification to " + notification.name); log.error("monitor", e);