Add support for values of Name, Hostname and Status

This commit is contained in:
Lukas 2021-10-09 21:48:28 +02:00
parent edb75808d8
commit 792f3c7c5c
3 changed files with 33 additions and 3 deletions

View File

@ -22,10 +22,40 @@ class SMTP extends NotificationProvider {
} }
// Lets start with default subject // Lets start with default subject
let subject = msg; let subject = msg;
// Our subject cannot end with whitespace it's often raise spam score // Our subject cannot end with whitespace it's often raise spam score
let customsubject = notification.customsubject.trim() let customsubject = notification.customsubject.trim()
// If custom subject is not empty, change subject for notification // 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 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 subject = customsubject
} }

View File

@ -44,8 +44,8 @@
</div> </div>
<div class="mb-3"> <div class="mb-3">
<label for="subject-email" class="form-label">{{ $t("Custom Email subject") }}</label> <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="[Uptime Kuma] Service status has changed"> <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>
<div class="mb-3"> <div class="mb-3">

View File

@ -201,7 +201,7 @@ export default {
secureOptionTLS: "TLS (465)", secureOptionTLS: "TLS (465)",
"Ignore TLS Error": "Ignore TLS Error", "Ignore TLS Error": "Ignore TLS Error",
"From Email": "From Email", "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", "To Email": "To Email",
smtpCC: "CC", smtpCC: "CC",
smtpBCC: "BCC", smtpBCC: "BCC",