Use double curly brackets and sanity check for customSubject

This commit is contained in:
Lukas 2021-10-13 18:05:18 +02:00
parent 330cd6e058
commit 89b34b5748
2 changed files with 15 additions and 11 deletions

View file

@ -21,19 +21,23 @@ class SMTP extends NotificationProvider {
pass: notification.smtpPassword,
};
}
// Lets start with default subject
// Lets start with default subject and empty string for custom one
let subject = msg;
let customSubject = "";
// Our subject cannot end with whitespace it's often raise spam score
let customsubject = notification.customsubject.trim()
// Once I got "Cannot read property 'trim' of undefined", better be safe than sorry
if (notification.customSubject) {
customSubject = notification.customSubject.trim()
}
// If custom subject is not empty, change subject for notification
if (customsubject !== "") {
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 replaceName = new RegExp("{{NAME}}", "g");
let replaceHostname = new RegExp("{{HOSTNAME}}", "g");
let replaceStatus = new RegExp("{{STATUS}}", "g");
// Lets start with dummy values to simplify code
let monitorName = "Test"
@ -50,11 +54,11 @@ class SMTP extends NotificationProvider {
}
// Break replace to one by line for better readability
customsubject = customsubject.replace(replaceStatus, serviceStatus);
customsubject = customsubject.replace(replaceName, monitorName);
customsubject = customsubject.replace(replaceHostname, monitorHostname);
customSubject = customSubject.replace(replaceStatus, serviceStatus);
customSubject = customSubject.replace(replaceName, monitorName);
customSubject = customSubject.replace(replaceHostname, monitorHostname);
subject = customsubject
subject = customSubject
}
let transporter = nodemailer.createTransport(config);

View file

@ -45,7 +45,7 @@
<div class="mb-3">
<label for="subject-email" class="form-label">{{ $t("Email Subject") }}</label>
<input id="subject-email" v-model="$parent.notification.customsubject" type="text" class="form-control" autocomplete="false" placeholder="Service {NAME} on {HOSTNAME} has changed status to {STATUS}">
<input id="subject-email" v-model="$parent.notification.customSubject" type="text" class="form-control" autocomplete="false" placeholder="Service {{NAME}} on {{HOSTNAME}} has changed status to {{STATUS}}">
</div>
<div class="mb-3">