-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.js
41 lines (40 loc) · 1.4 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import fetch from "node-fetch"
async function postplatformstatus() {
const allPlatforms = [
// use any urls and check their status
'https://api.reinforz.ai/ping',
'https://app.reinforz.ai',
'https://reinforz.ai',
];
const messages = []; // array containing the messages to send
for (const platform of allPlatforms) {
const response = await fetch(platform);
// We will only notify people if an error has occurred
if (response.status >= 400) {
// If the status code sent by the response is 400 or higher,
// then it means an error is happening and we will notify relevent people with the platform
const singleMessage = `${platform} is down. Status: ${response.status} 🔴`
// If any error response is recieved add it to messages
console.log(singleMessage);
messages.push(singleMessage);
}
}
const ROLE_ID = '<copy a role Id from discord>';
if (messages.length !== 0) {
// use the send a message to discord using the webhook URL to see if which servers are inactive.
await fetch(
'<the copied webhook url>',
{
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
// <@ROLE_ID> is used to notify members with a specific discord role
content: `<@&${ROLE_ID}>\n${messages.join('\n')}`,
}),
}
);
}
}
postplatformstatus();