Browse Source
			
			
			Merge pull request #260 from Thiesjoo/discord-notification
			
				Discord notification updates
			
			
				pull/283/head
			
			
		 
		
			
				
					
						 Louis Lam
					
					4 years ago
						Louis Lam
					
					4 years ago
					
						
							committed by
							
								 GitHub
								GitHub
							
						 
					
				 
				
			 
		 
		
			
				
					
					No known key found for this signature in database
					
						
							GPG Key ID: 4AEE18F83AFDEB23
						
					
				
			
		
		
		
	
		
			
				 1 changed files with 
9 additions and 
3 deletions
			 
			
		 
		
			
				- 
					
					
					 
					server/notification.js
				
				
				
					
						
							
								
									
	
		
			
				
					|  |  | @ -95,12 +95,18 @@ class Notification { | 
			
		
	
		
			
				
					|  |  |  |                     await axios.post(notification.discordWebhookUrl, discordtestdata) | 
			
		
	
		
			
				
					|  |  |  |                     return okMsg; | 
			
		
	
		
			
				
					|  |  |  |                 } | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |                 let url = monitorJSON["url"] === "https://" ? monitorJSON["hostname"] : monitorJSON["url"] | 
			
		
	
		
			
				
					|  |  |  |                 if (monitorJSON["port"]) { | 
			
		
	
		
			
				
					|  |  |  |                     url += ":" + monitorJSON[port]; | 
			
		
	
		
			
				
					|  |  |  |                 } | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |                 // If heartbeatJSON is not null, we go into the normal alerting loop.
 | 
			
		
	
		
			
				
					|  |  |  |                 if (heartbeatJSON["status"] == 0) { | 
			
		
	
		
			
				
					|  |  |  |                     let discorddowndata = { | 
			
		
	
		
			
				
					|  |  |  |                         username: discordDisplayName, | 
			
		
	
		
			
				
					|  |  |  |                         embeds: [{ | 
			
		
	
		
			
				
					|  |  |  |                             title: "❌ One of your services went down. ❌", | 
			
		
	
		
			
				
					|  |  |  |                             title: "❌ Your service " + monitorJSON["name"] + " went down. ❌", | 
			
		
	
		
			
				
					|  |  |  |                             color: 16711680, | 
			
		
	
		
			
				
					|  |  |  |                             timestamp: heartbeatJSON["time"], | 
			
		
	
		
			
				
					|  |  |  |                             fields: [ | 
			
		
	
	
		
			
				
					|  |  | @ -110,7 +116,7 @@ class Notification { | 
			
		
	
		
			
				
					|  |  |  |                                 }, | 
			
		
	
		
			
				
					|  |  |  |                                 { | 
			
		
	
		
			
				
					|  |  |  |                                     name: "Service URL", | 
			
		
	
		
			
				
					|  |  |  |                                     value: monitorJSON["url"], | 
			
		
	
		
			
				
					|  |  |  |                                     value: url, | 
			
		
	
		
			
				
					|  |  |  |                                 }, | 
			
		
	
		
			
				
					|  |  |  |                                 { | 
			
		
	
		
			
				
					|  |  |  |                                     name: "Time (UTC)", | 
			
		
	
	
		
			
				
					|  |  | @ -140,7 +146,7 @@ class Notification { | 
			
		
	
		
			
				
					|  |  |  |                                 }, | 
			
		
	
		
			
				
					|  |  |  |                                 { | 
			
		
	
		
			
				
					|  |  |  |                                     name: "Service URL", | 
			
		
	
		
			
				
					|  |  |  |                                     value: "[Visit Service](" + monitorJSON["url"] + ")", | 
			
		
	
		
			
				
					|  |  |  |                                     value: url.startsWith("http") ? "[Visit Service](" + url + ")" : url, | 
			
		
	
		
			
				
					|  |  |  |                                 }, | 
			
		
	
		
			
				
					|  |  |  |                                 { | 
			
		
	
		
			
				
					|  |  |  |                                     name: "Time (UTC)", | 
			
		
	
	
		
			
				
					|  |  | 
 |