Discord enhancements
This commit is contained in:
		
							parent
							
								
									8350bff629
								
							
						
					
					
						commit
						9ade9af1e2
					
				
					 1 changed files with 64 additions and 14 deletions
				
			
		|  | @ -83,41 +83,91 @@ class Notification { | ||||||
|             return await Notification.smtp(notification, msg) |             return await Notification.smtp(notification, msg) | ||||||
| 
 | 
 | ||||||
|         } else if (notification.type === "discord") { |         } else if (notification.type === "discord") { | ||||||
|  |             let kumaURL = notification.discorduptimekumaUrl || "https://github.com/louislam/uptime-kuma"; | ||||||
|  |             let dashboardURL = notification.discorduptimekumaUrl + '/dashboard/' + monitorJSON["id"]; | ||||||
|             try { |             try { | ||||||
|                 // If heartbeatJSON is null, assume we're testing.
 |                 // If heartbeatJSON is null, assume we're testing.
 | ||||||
|                 if (heartbeatJSON == null) { |                 if (heartbeatJSON == null) { | ||||||
|                     let data = { |                     let discordtestdata = { | ||||||
|                         username: "Uptime-Kuma", |                         username: "Uptime Kuma", | ||||||
|                         content: msg, |                         content: msg, | ||||||
|                     } |                     } | ||||||
|                     await axios.post(notification.discordWebhookUrl, data) |                     await axios.post(notification.discordWebhookUrl, discordtestdata) | ||||||
|                     return okMsg; |                     return okMsg; | ||||||
|                 } |                 } | ||||||
|                 // If heartbeatJSON is not null, we go into the normal alerting loop.
 |                 // If heartbeatJSON is not null, we go into the normal alerting loop.
 | ||||||
|                 if (heartbeatJSON["status"] == 0) { |                 if (heartbeatJSON["status"] == 0) { | ||||||
|                     var alertColor = "16711680"; |                     let discorddowndata = { | ||||||
|                 } else if (heartbeatJSON["status"] == 1) { |                     username: "Uptime Kuma", | ||||||
|                     var alertColor = "65280"; |  | ||||||
|                 } |  | ||||||
|                 let data = { |  | ||||||
|                     username: "Uptime-Kuma", |  | ||||||
|                     embeds: [{ |                     embeds: [{ | ||||||
|                         title: "Uptime-Kuma Alert", |                         title: "❌ One of your services went down. ❌", | ||||||
|                         color: alertColor, |                         color: 16711680, | ||||||
|  |                         timestamp: heartbeatJSON["time"], | ||||||
|                         fields: [ |                         fields: [ | ||||||
|  |                             { | ||||||
|  |                                 name: "Service Name", | ||||||
|  |                                 value: monitorJSON["name"], | ||||||
|  |                             }, | ||||||
|  |                             { | ||||||
|  |                                 name: "Service URL", | ||||||
|  |                                 value: monitorJSON["url"], | ||||||
|  |                             }, | ||||||
|                             { |                             { | ||||||
|                                 name: "Time (UTC)", |                                 name: "Time (UTC)", | ||||||
|                                 value: heartbeatJSON["time"], |                                 value: heartbeatJSON["time"], | ||||||
|                             }, |                             }, | ||||||
|                             { |                             { | ||||||
|                                 name: "Message", |                                 name: "Error", | ||||||
|                                 value: msg, |                                 value: heartbeatJSON["msg"], | ||||||
|  |                             }, | ||||||
|  |                             { | ||||||
|  |                                 name: "Visit Service Dashboard", | ||||||
|  |                                 value: "[Visit Dashboard]("+ dashboardURL + ")", | ||||||
|  |                             }, | ||||||
|  |                             { | ||||||
|  |                                 name: "Visit Uptime Kuma", | ||||||
|  |                                 value: "[Visit]("+ kumaURL +")", | ||||||
|                             }, |                             }, | ||||||
|                         ], |                         ], | ||||||
|                     }], |                     }], | ||||||
|                 } |                 } | ||||||
|                 await axios.post(notification.discordWebhookUrl, data) |                 await axios.post(notification.discordWebhookUrl, discorddowndata) | ||||||
|                 return okMsg; |                 return okMsg; | ||||||
|  |                      | ||||||
|  |                 } else if (heartbeatJSON["status"] == 1) { | ||||||
|  |                     let discordupdata = { | ||||||
|  |                     username: "Uptime Kuma", | ||||||
|  |                     embeds: [{ | ||||||
|  |                         title: "✅ Your service " +  monitorJSON["name"] + " is up! ✅", | ||||||
|  |                         color: 65280, | ||||||
|  |                         timestamp: heartbeatJSON["time"], | ||||||
|  |                         fields: [ | ||||||
|  |                             { | ||||||
|  |                                 name: "Service Name", | ||||||
|  |                                 value: monitorJSON["name"], | ||||||
|  |                             }, | ||||||
|  |                             { | ||||||
|  |                                 name: "Service URL", | ||||||
|  |                                 value: "[Visit Service]("+ monitorJSON["url"] +")", | ||||||
|  |                             }, | ||||||
|  |                             { | ||||||
|  |                                 name: "Time (UTC)", | ||||||
|  |                                 value: heartbeatJSON["time"], | ||||||
|  |                             }, | ||||||
|  |                             { | ||||||
|  |                                 name: "Ping", | ||||||
|  |                                 value: heartbeatJSON["ping"] + "ms", | ||||||
|  |                             }, | ||||||
|  |                             { | ||||||
|  |                                 name: "Visit Uptime Kuma", | ||||||
|  |                                 value: "[Visit]("+ kumaURL +")", | ||||||
|  |                             }, | ||||||
|  |                         ], | ||||||
|  |                     }], | ||||||
|  |                 } | ||||||
|  |                 await axios.post(notification.discordWebhookUrl, discordupdata) | ||||||
|  |                 return okMsg; | ||||||
|  |                 } | ||||||
|             } catch (error) { |             } catch (error) { | ||||||
|                 throwGeneralAxiosError(error) |                 throwGeneralAxiosError(error) | ||||||
|             } |             } | ||||||
|  |  | ||||||
		Loading…
	
		Reference in a new issue