hacktoberfestdockerwebappuptime-monitoringuptimesocket-iosingle-page-appselfhostedself-hostedresponsivemonitoringwebsocket
		
		
		
		
			You can not select more than 25 topics
			Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
		
		
		
		
		
			
		
			
				
					
					
						
							123 lines
						
					
					
						
							4.9 KiB
						
					
					
				
			
		
		
		
			
			
			
				
					
				
				
					
				
			
		
		
	
	
							123 lines
						
					
					
						
							4.9 KiB
						
					
					
				| const NotificationProvider = require("./notification-provider"); | |
| const axios = require("axios"); | |
| const { DOWN, UP } = require("../../src/util"); | |
| 
 | |
| class Mattermost extends NotificationProvider { | |
| 
 | |
|     name = "mattermost"; | |
| 
 | |
|     async send(notification, msg, monitorJSON = null, heartbeatJSON = null) { | |
|         let okMsg = "Sent Successfully."; | |
|         try { | |
|             const mattermostUserName = notification.mattermostusername || "Uptime Kuma"; | |
|             // If heartbeatJSON is null, assume we're testing. | |
|             if (heartbeatJSON == null) { | |
|                 let mattermostTestData = { | |
|                     username: mattermostUserName, | |
|                     text: msg, | |
|                 } | |
|                 await axios.post(notification.mattermostWebhookUrl, mattermostTestData) | |
|                 return okMsg; | |
|             } | |
| 
 | |
|             const mattermostChannel = notification.mattermostchannel; | |
|             const mattermostIconEmoji = notification.mattermosticonemo; | |
|             const mattermostIconUrl = notification.mattermosticonurl; | |
| 
 | |
|             if (heartbeatJSON["status"] == DOWN) { | |
|                 let mattermostdowndata = { | |
|                     username: mattermostUserName, | |
|                     text: "Uptime Kuma Alert", | |
|                     channel: mattermostChannel, | |
|                     icon_emoji: mattermostIconEmoji, | |
|                     icon_url: mattermostIconUrl, | |
|                     attachments: [ | |
|                         { | |
|                             fallback: | |
|                                 "Your " + | |
|                                 monitorJSON["name"] + | |
|                                 " service went down.", | |
|                             color: "#FF0000", | |
|                             title: | |
|                                 "❌ " + | |
|                                 monitorJSON["name"] + | |
|                                 " service went down. ❌", | |
|                             title_link: monitorJSON["url"], | |
|                             fields: [ | |
|                                 { | |
|                                     short: true, | |
|                                     title: "Service Name", | |
|                                     value: monitorJSON["name"], | |
|                                 }, | |
|                                 { | |
|                                     short: true, | |
|                                     title: "Time (UTC)", | |
|                                     value: heartbeatJSON["time"], | |
|                                 }, | |
|                                 { | |
|                                     short: false, | |
|                                     title: "Error", | |
|                                     value: heartbeatJSON["msg"], | |
|                                 }, | |
|                             ], | |
|                         }, | |
|                     ], | |
|                 }; | |
|                 await axios.post( | |
|                     notification.mattermostWebhookUrl, | |
|                     mattermostdowndata | |
|                 ); | |
|                 return okMsg; | |
|             } else if (heartbeatJSON["status"] == UP) { | |
|                 let mattermostupdata = { | |
|                     username: mattermostUserName, | |
|                     text: "Uptime Kuma Alert", | |
|                     channel: mattermostChannel, | |
|                     icon_emoji: mattermostIconEmoji, | |
|                     icon_url: mattermostIconUrl, | |
|                     attachments: [ | |
|                         { | |
|                             fallback: | |
|                                 "Your " + | |
|                                 monitorJSON["name"] + | |
|                                 " service went up!", | |
|                             color: "#32CD32", | |
|                             title: | |
|                                 "✅ " + | |
|                                 monitorJSON["name"] + | |
|                                 " service went up! ✅", | |
|                             title_link: monitorJSON["url"], | |
|                             fields: [ | |
|                                 { | |
|                                     short: true, | |
|                                     title: "Service Name", | |
|                                     value: monitorJSON["name"], | |
|                                 }, | |
|                                 { | |
|                                     short: true, | |
|                                     title: "Time (UTC)", | |
|                                     value: heartbeatJSON["time"], | |
|                                 }, | |
|                                 { | |
|                                     short: false, | |
|                                     title: "Ping", | |
|                                     value: heartbeatJSON["ping"] + "ms", | |
|                                 }, | |
|                             ], | |
|                         }, | |
|                     ], | |
|                 }; | |
|                 await axios.post( | |
|                     notification.mattermostWebhookUrl, | |
|                     mattermostupdata | |
|                 ); | |
|                 return okMsg; | |
|             } | |
|         } catch (error) { | |
|             this.throwGeneralAxiosError(error); | |
|         } | |
| 
 | |
|     } | |
| } | |
| 
 | |
| module.exports = Mattermost;
 | |
| 
 |