-
Notifications
You must be signed in to change notification settings - Fork 0
/
simplemonitor-status.js
66 lines (57 loc) · 1.73 KB
/
simplemonitor-status.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
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
const fetch = require('node-fetch');
async function downloadStatus() {
const URL = process.env.STATUS_JSON_URL;
const result = await fetch(URL);
return await result.json();
}
function reformatStatusList(rawStatusObject) {
const monitors = rawStatusObject.monitors;
const hosts = [
'ping-uberspace-wjbots',
'ping-uberspace-alioth',
];
const bots = [
'service-telegram-bot-album-creator',
'service-telegram-bot-getids',
'service-telegram-bot-wjclub-support',
'service-telegram-bot-removekeyboard',
'service-telegram-channel-webfail',
]
return {
hosts: hosts.map(host => reformatStatus(monitors[host], host)),
bots: bots.map(bot => reformatStatus(monitors[bot], bot))
}
}
function reformatStatus(status, name) {
if (status === undefined) {
return {
name: name.replace('ping-','').replace('service-',''),
ok: false,
emoji: '❓',
down_since: 'unknown'
}
}
const ok = status.status === 'OK';
return {
name: name.replace('ping-','').replace('service-',''),
ok: ok,
emoji: ok ? '✅' : '❌',
down_since: ok ? '' : (status.first_failure_time + '')
}
}
function status2TelegramHtml(reformattedStatus, generatedAt) {
const {hosts, bots} = reformattedStatus;
return '\nStatus of our systems:\n<u>Servers:</u>\n'
+ hosts
.map(({name, ok, emoji, down_since}) => emoji + ' ' + name + (ok?'':' ('+down_since+')'))
.join('\n')
+ '\n\n<u>Bots & Channels:</u>\n'
+ bots
.map(({name, ok, emoji, down_since}) => emoji + ' ' + name + (ok?'':' ('+down_since+')'))
.join('\n')
+ '\n\n<i>updated: '+generatedAt+'</i>'
}
exports.getStatusForTelegram = async function() {
const freshStatus = await downloadStatus();
return status2TelegramHtml(reformatStatusList(freshStatus), freshStatus.generated);
}