[SMTP] change {{HOSTNAME}} to {{HOSTNAME_OR_URL}}, support for http montior type, some UI improvements
This commit is contained in:
		
							parent
							
								
									674b387c95
								
							
						
					
					
						commit
						8338881927
					
				
					 4 changed files with 56 additions and 37 deletions
				
			
		|  | @ -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) { | ||||||
|             // Replace "MACROS" with coresponding variable
 |                 customSubject = notification.customSubject.trim(); | ||||||
|             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" |  | ||||||
|             let monitorHostname = "example.com" |  | ||||||
|             let serviceStatus = "⚠️ Test"; |  | ||||||
| 
 |  | ||||||
|             if (monitorJSON !== null) { |  | ||||||
|                 monitorName = monitorJSON["name"]; |  | ||||||
|                 monitorHostname = monitorJSON["hostname"]; |  | ||||||
|             } |             } | ||||||
| 
 | 
 | ||||||
|             if (heartbeatJSON !== null) { |             // If custom subject is not empty, change subject for notification
 | ||||||
|                 serviceStatus = heartbeatJSON["status"] == DOWN ? "🔴 Down" : "✅ Up"; |             if (customSubject !== "") { | ||||||
|             } |  | ||||||
|              |  | ||||||
|             // 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 |                 // Replace "MACROS" with corresponding variable
 | ||||||
|  |                 let replaceName = new RegExp("{{NAME}}", "g"); | ||||||
|  |                 let replaceHostnameOrURL = new RegExp("{{HOSTNAME_OR_URL}}", "g"); | ||||||
|  |                 let replaceStatus = new RegExp("{{STATUS}}", "g"); | ||||||
|  | 
 | ||||||
|  |                 // Lets start with dummy values to simplify code
 | ||||||
|  |                 let monitorName = "Test"; | ||||||
|  |                 let monitorHostnameOrURL = "testing.hostname"; | ||||||
|  |                 let serviceStatus = "⚠️ Test"; | ||||||
|  | 
 | ||||||
|  |                 if (monitorJSON !== null) { | ||||||
|  |                     monitorName = monitorJSON["name"]; | ||||||
|  | 
 | ||||||
|  |                     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); | ||||||
|  |  | ||||||
|  | @ -43,11 +43,6 @@ | ||||||
|         </div> |         </div> | ||||||
|     </div> |     </div> | ||||||
| 
 | 
 | ||||||
|     <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}}"> |  | ||||||
|     </div> |  | ||||||
| 
 |  | ||||||
|     <div class="mb-3"> |     <div class="mb-3"> | ||||||
|         <label for="to-email" class="form-label">{{ $t("To Email") }}</label> |         <label for="to-email" class="form-label">{{ $t("To Email") }}</label> | ||||||
|         <input id="to-email" v-model="$parent.notification.smtpTo" type="text" class="form-control" autocomplete="false" placeholder="example2@kuma.pet, example3@kuma.pet" :required="!hasRecipient"> |         <input id="to-email" v-model="$parent.notification.smtpTo" type="text" class="form-control" autocomplete="false" placeholder="example2@kuma.pet, example3@kuma.pet" :required="!hasRecipient"> | ||||||
|  | @ -62,6 +57,18 @@ | ||||||
|         <label for="to-bcc" class="form-label">{{ $t("smtpBCC") }}</label> |         <label for="to-bcc" class="form-label">{{ $t("smtpBCC") }}</label> | ||||||
|         <input id="to-bcc" v-model="$parent.notification.smtpBCC" type="text" class="form-control" autocomplete="false" :required="!hasRecipient"> |         <input id="to-bcc" v-model="$parent.notification.smtpBCC" type="text" class="form-control" autocomplete="false" :required="!hasRecipient"> | ||||||
|     </div> |     </div> | ||||||
|  | 
 | ||||||
|  |     <div class="mb-3"> | ||||||
|  |         <label for="subject-email" class="form-label">{{ $t("emailCustomSubject") }}</label> | ||||||
|  |         <input id="subject-email" v-model="$parent.notification.customSubject" type="text" class="form-control" autocomplete="false" placeholder=""> | ||||||
|  |         <div v-pre class="form-text"> | ||||||
|  |             (leave blank for default one)<br /> | ||||||
|  |             {{NAME}}: Service Name<br /> | ||||||
|  |             {{HOSTNAME_OR_URL}}: Hostname or URL<br /> | ||||||
|  |             {{URL}}: URL<br /> | ||||||
|  |             {{STATUS}}: Status<br /> | ||||||
|  |         </div> | ||||||
|  |     </div> | ||||||
| </template> | </template> | ||||||
| 
 | 
 | ||||||
| <script> | <script> | ||||||
|  |  | ||||||
|  | @ -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", | ||||||
|     "Email Subject": "Subject (leave blank for default one)", |     emailCustomSubject: "Custom Subject", | ||||||
|     "To Email": "To Email", |     "To Email": "To Email", | ||||||
|     smtpCC: "CC", |     smtpCC: "CC", | ||||||
|     smtpBCC: "BCC", |     smtpBCC: "BCC", | ||||||
|  |  | ||||||
|  | @ -63,6 +63,7 @@ | ||||||
|                                 </div> |                                 </div> | ||||||
|                             </div> |                             </div> | ||||||
| 
 | 
 | ||||||
|  |                             <!-- Hostname --> | ||||||
|                             <!-- TCP Port / Ping / DNS only --> |                             <!-- TCP Port / Ping / DNS only --> | ||||||
|                             <div v-if="monitor.type === 'port' || monitor.type === 'ping' || monitor.type === 'dns' " class="my-3"> |                             <div v-if="monitor.type === 'port' || monitor.type === 'ping' || monitor.type === 'dns' " class="my-3"> | ||||||
|                                 <label for="hostname" class="form-label">{{ $t("Hostname") }}</label> |                                 <label for="hostname" class="form-label">{{ $t("Hostname") }}</label> | ||||||
|  |  | ||||||
		Loading…
	
		Reference in a new issue