mirror of
				https://github.com/louislam/uptime-kuma.git
				synced 2025-11-01 03:49:24 +08:00 
			
		
		
		
	Use constants for UP/DOWN through notifications class
This commit is contained in:
		| @@ -4,6 +4,8 @@ const FormData = require("form-data"); | ||||
| const nodemailer = require("nodemailer"); | ||||
| const child_process = require("child_process"); | ||||
|  | ||||
| const { UP, DOWN } = require("../src/util"); | ||||
|  | ||||
| class Notification { | ||||
|  | ||||
|     /** | ||||
| @@ -22,7 +24,7 @@ class Notification { | ||||
|         // heartbeatJSON is only defined if we're not testing | ||||
|         if(heartbeatJSON) { | ||||
|             let text; | ||||
|             if (heartbeatJSON["status"] === 1) { | ||||
|             if (heartbeatJSON["status"] === UP) { | ||||
|                 text = "✅ Up" | ||||
|             } else { | ||||
|                 text = "🔴 Down" | ||||
| @@ -121,7 +123,7 @@ class Notification { | ||||
|                 } | ||||
|  | ||||
|                 // If heartbeatJSON is not null, we go into the normal alerting loop. | ||||
|                 if (heartbeatJSON["status"] == 0) { | ||||
|                 if (heartbeatJSON["status"] == DOWN) { | ||||
|                     let discorddowndata = { | ||||
|                         username: discordDisplayName, | ||||
|                         embeds: [{ | ||||
| @@ -151,7 +153,7 @@ class Notification { | ||||
|                     await axios.post(notification.discordWebhookUrl, discorddowndata) | ||||
|                     return okMsg; | ||||
|  | ||||
|                 } else if (heartbeatJSON["status"] == 1) { | ||||
|                 } else if (heartbeatJSON["status"] == UP) { | ||||
|                     let discordupdata = { | ||||
|                         username: discordDisplayName, | ||||
|                         embeds: [{ | ||||
| @@ -355,7 +357,7 @@ class Notification { | ||||
|                 const mattermostIconEmoji = notification.mattermosticonemo; | ||||
|                 const mattermostIconUrl = notification.mattermosticonurl; | ||||
|  | ||||
|                 if (heartbeatJSON["status"] == 0) { | ||||
|                 if (heartbeatJSON["status"] == DOWN) { | ||||
|                     let mattermostdowndata = { | ||||
|                         username: mattermostUserName, | ||||
|                         text: "Uptime Kuma Alert", | ||||
| @@ -399,7 +401,7 @@ class Notification { | ||||
|                         mattermostdowndata | ||||
|                     ); | ||||
|                     return okMsg; | ||||
|                 } else if (heartbeatJSON["status"] == 1) { | ||||
|                 } else if (heartbeatJSON["status"] == UP) { | ||||
|                     let mattermostupdata = { | ||||
|                         username: mattermostUserName, | ||||
|                         text: "Uptime Kuma Alert", | ||||
| @@ -501,7 +503,7 @@ class Notification { | ||||
|                     return okMsg; | ||||
|                 } | ||||
|  | ||||
|                 if (heartbeatJSON["status"] == 0) { | ||||
|                 if (heartbeatJSON["status"] == DOWN) { | ||||
|                     let downdata = { | ||||
|                         "title": "UptimeKuma Alert: " + monitorJSON["name"], | ||||
|                         "body": "[🔴 Down] " + heartbeatJSON["msg"] + "\nTime (UTC): " + heartbeatJSON["time"], | ||||
| @@ -510,7 +512,7 @@ class Notification { | ||||
|                     return okMsg; | ||||
|                 } | ||||
|  | ||||
|                 if (heartbeatJSON["status"] == 1) { | ||||
|                 if (heartbeatJSON["status"] == UP) { | ||||
|                     let updata = { | ||||
|                         "title": "UptimeKuma Alert: " + monitorJSON["name"], | ||||
|                         "body": "[✅ Up] " + heartbeatJSON["msg"] + "\nTime (UTC): " + heartbeatJSON["time"], | ||||
| @@ -539,14 +541,14 @@ class Notification { | ||||
|                         "body": "Testing Successful.", | ||||
|                     } | ||||
|                     await axios.post(pushbulletUrl, testdata, config) | ||||
|                 } else if (heartbeatJSON["status"] == 0) { | ||||
|                 } else if (heartbeatJSON["status"] == DOWN) { | ||||
|                     let downdata = { | ||||
|                         "type": "note", | ||||
|                         "title": "UptimeKuma Alert: " + monitorJSON["name"], | ||||
|                         "body": "[🔴 Down] " + heartbeatJSON["msg"] + "\nTime (UTC): " + heartbeatJSON["time"], | ||||
|                     } | ||||
|                     await axios.post(pushbulletUrl, downdata, config) | ||||
|                 } else if (heartbeatJSON["status"] == 1) { | ||||
|                 } else if (heartbeatJSON["status"] == UP) { | ||||
|                     let updata = { | ||||
|                         "type": "note", | ||||
|                         "title": "UptimeKuma Alert: " + monitorJSON["name"], | ||||
| @@ -578,7 +580,7 @@ class Notification { | ||||
|                         ] | ||||
|                     } | ||||
|                     await axios.post(lineAPIUrl, testMessage, config) | ||||
|                 } else if (heartbeatJSON["status"] == 0) { | ||||
|                 } else if (heartbeatJSON["status"] == DOWN) { | ||||
|                     let downMessage = { | ||||
|                         "to": notification.lineUserID, | ||||
|                         "messages": [ | ||||
| @@ -589,7 +591,7 @@ class Notification { | ||||
|                         ] | ||||
|                     } | ||||
|                     await axios.post(lineAPIUrl, downMessage, config) | ||||
|                 } else if (heartbeatJSON["status"] == 1) { | ||||
|                 } else if (heartbeatJSON["status"] == UP) { | ||||
|                     let upMessage = { | ||||
|                         "to": notification.lineUserID, | ||||
|                         "messages": [ | ||||
|   | ||||
		Reference in New Issue
	
	Block a user