-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
73 lines (59 loc) · 1.51 KB
/
index.js
File metadata and controls
73 lines (59 loc) · 1.51 KB
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
require('dotenv').config()
const fetch = require('node-fetch')
const Slack = require('slack-node')
const util = require('util')
const slackWebhookSecret = process.env.SLACK_WEBHOOK_SECRET
const slack = new Slack()
slack.setWebhook(`https://hooks.slack.com/services/${slackWebhookSecret}`)
// Promisify the slack webhook method
const slackWebhook = util.promisify(slack.webhook)
const URLs = [
{
name: 'Bookis app',
url: 'https://app.bookis.io'
},
{
name: 'Bookis Landing page',
url: 'https://bookis.io'
}
]
const ping = async url => {
const res = await fetch(url)
}
const postToSlack = async message => {
await slackWebhook({
channel: 'services-status',
username: 'Kokoras',
text: message
})
}
const getDateTimeString = () => {
const event = new Date()
const options = {
weekday: 'long',
year: 'numeric',
month: 'long',
day: 'numeric',
hour: 'numeric',
minute: 'numeric',
second: 'numeric'
}
return event.toLocaleDateString('en-gb', options)
}
const main = async () => {
const message = []
message.push(`============================== (${getDateTimeString()}) UTC`)
for (let i = 0; i < URLs.length; i++) {
const { name, url } = URLs[i]
try {
await ping(url)
message.push(`[*${name}*] ✅`)
} catch (err) {
console.error(err)
message.push(`[*${name}*] UNREACHABLE!!! 🚨🚨🚨 \n Error: ${err.message}`)
}
}
message.push('==============================')
await postToSlack(message.join('\n'))
}
main()