Add support for values of Name, Hostname and Status

pull/627/head
Lukas 3 years ago
parent edb75808d8
commit 792f3c7c5c

@ -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
}

@ -44,8 +44,8 @@
</div>
<div class="mb-3">
<label for="subject-email" class="form-label">{{ $t("Custom Email subject") }}</label>
<input id="subject-email" v-model="$parent.notification.customsubject" type="text" class="form-control" autocomplete="false" placeholder="[Uptime Kuma] Service status has changed">
<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}">
</div>
<div class="mb-3">

@ -201,7 +201,7 @@ export default {
secureOptionTLS: "TLS (465)",
"Ignore TLS Error": "Ignore TLS Error",
"From Email": "From Email",
"Custom Email subject": "Custom Email Subject (leave blank for default one)",
"Email Subject": "Subject (leave blank for default one)",
"To Email": "To Email",
smtpCC: "CC",
smtpBCC: "BCC",

Loading…
Cancel
Save