@ -23,42 +23,53 @@ class SMTP extends NotificationProvider {
}
}
// Lets start with default subject and empty string for custom one
// Lets start with default subject and empty string for custom one
let subject = msg ;
let subject = msg ;
let customSubject = "" ;
// Our subject cannot end with whitespace it's often raise spam score
// Change the subject if:
// Once I got "Cannot read property 'trim' of undefined", better be safe than sorry
// - The msg ends with "Testing" or
if ( notification . customSubject ) {
// - Actual Up/Down Notification
customSubject = notification . customSubject . trim ( )
if ( ( monitorJSON && heartbeatJSON ) || msg . endsWith ( "Testing" ) ) {
}
let customSubject = "" ;
// If custom subject is not empty, change subject for notification
// Our subject cannot end with whitespace it's often raise spam score
if ( customSubject !== "" ) {
// Once I got "Cannot read property 'trim' of undefined", better be safe than sorry
if ( notification . customSubject ) {
customSubject = notification . customSubject . trim ( ) ;
}
// Replace "MACROS" with coresponding variable
// If custom subject is not empty, change subject for notification
let replaceName = new RegExp ( "{{NAME}}" , "g" ) ;
if ( customSubject !== "" ) {
let replaceHostname = new RegExp ( "{{HOSTNAME}}" , "g" ) ;
let replaceStatus = new RegExp ( "{{STATUS}}" , "g" ) ;
// Lets start with dummy values to simplify cod e
// Replace "MACROS" with corresponding variable
let monitorName = "Test"
let replaceName = new RegExp ( "{{NAME}}" , "g" ) ;
let monitorHostname = "example.com"
let replaceHostnameOrURL = new RegExp ( "{{HOSTNAME_OR_URL}}" , "g" ) ;
let serviceStatus = "⚠️ Test" ;
let replaceStatus = new RegExp ( "{{STATUS}}" , "g" ) ;
if ( monitorJSON !== null ) {
// Lets start with dummy values to simplify code
monitorName = monitorJSON [ "name" ] ;
let monitorName = "Test" ;
monitorHostname = monitorJSON [ " hostname"] ;
let monitorHostname OrURL = " testing. hostname";
}
let serviceStatus = "⚠️ Test" ;
if ( heartbeatJSON !== null ) {
if ( monitorJSON !== null ) {
serviceStatus = heartbeatJSON [ "status" ] == DOWN ? "🔴 Down" : "✅ Up" ;
monitorName = monitorJSON [ "name" ] ;
}
// Break replace to one by line for better readability
customSubject = customSubject . replace ( replaceStatus , serviceStatus ) ;
customSubject = customSubject . replace ( replaceName , monitorName ) ;
customSubject = customSubject . replace ( replaceHostname , monitorHostname ) ;
subject = customSubject
if ( monitorJSON [ "type" ] === "http" || monitorJSON [ "type" ] === "keyword" ) {
monitorHostnameOrURL = monitorJSON [ "url" ] ;
} else {
monitorHostnameOrURL = monitorJSON [ "hostname" ] ;
}
}
if ( heartbeatJSON !== null ) {
serviceStatus = ( heartbeatJSON [ "status" ] === DOWN ) ? "🔴 Down" : "✅ Up" ;
}
// Break replace to one by line for better readability
customSubject = customSubject . replace ( replaceStatus , serviceStatus ) ;
customSubject = customSubject . replace ( replaceName , monitorName ) ;
customSubject = customSubject . replace ( replaceHostnameOrURL , monitorHostnameOrURL ) ;
subject = customSubject ;
}
}
}
let transporter = nodemailer . createTransport ( config ) ;
let transporter = nodemailer . createTransport ( config ) ;