From 792f3c7c5c17a2db80e7f9638e272b4607f3d4c6 Mon Sep 17 00:00:00 2001 From: Lukas <35193662+NixNotCastey@users.noreply.github.com> Date: Sat, 9 Oct 2021 21:48:28 +0200 Subject: [PATCH] Add support for values of Name, Hostname and Status --- server/notification-providers/smtp.js | 30 +++++++++++++++++++++++++++ src/components/notifications/SMTP.vue | 4 ++-- src/languages/en.js | 2 +- 3 files changed, 33 insertions(+), 3 deletions(-) diff --git a/server/notification-providers/smtp.js b/server/notification-providers/smtp.js index e5fd53e46..2bbec5848 100644 --- a/server/notification-providers/smtp.js +++ b/server/notification-providers/smtp.js @@ -22,10 +22,40 @@ class SMTP extends NotificationProvider { } // Lets start with default subject let subject = msg; + // Our subject cannot end with whitespace it's often raise spam score let customsubject = notification.customsubject.trim() + // If custom subject is not empty, change subject for notification if (customsubject !== "") { + + // Replace "MACROS" with coresponding variable + let replaceName = new RegExp("{NAME}", "g"); + let replaceHostname = new RegExp("{HOSTNAME}", "g"); + let replaceStatus = new RegExp("{STATUS}", "g"); + + let serviceStatus; + + if (monitorJSON !== null) { + customsubject = customsubject.replace(replaceName,monitorJSON["name"]); + customsubject = customsubject.replace(replaceHostname,monitorJSON["hostname"]); + } else { + // Insert dummy values during test + customsubject = customsubject.replace(replaceName,"Test"); + customsubject = customsubject.replace(replaceHostname,"example.com"); + } + if (heartbeatJSON !== null) { + if (heartbeatJSON["status"] === 0) { + serviceStatus = "🔴 Down" + } else { + serviceStatus = "✅ Up" + } + customsubject = customsubject.replace(replaceStatus,serviceStatus); + } else { + // Insert dummy values during test + customsubject = customsubject.replace(replaceStatus,"TEST"); + } + subject = customsubject } diff --git a/src/components/notifications/SMTP.vue b/src/components/notifications/SMTP.vue index 165d39c67..01bdf8607 100644 --- a/src/components/notifications/SMTP.vue +++ b/src/components/notifications/SMTP.vue @@ -44,8 +44,8 @@