forked from flybaseio/status
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
56 lines (51 loc) · 1.67 KB
/
script.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
$(document).ready(function() {
var config = {
uptimerobot: {
api_keys: [
'ur491309-36117bc8f6a6bf6d221a0167'
],
logs: 1
}
};
var monitors = config.uptimerobot.api_keys;
for( var i in monitors ){
var api_key = monitors[i];
$.post('https://api.uptimerobot.com/v2/getMonitors', {
"api_key": api_key,
"format": "json",
"logs": config.uptimerobot.logs,
}, function(response) {
status( response );
}, 'json');
}
function status(data) {
data.monitors = data.monitors.map(function(check) {
check.class = check.status === 2 ? 'label-success' : 'label-danger';
check.text = check.status === 2 ? 'operational' : 'major outage';
if( check.status !== 2 && !check.lasterrortime ){
check.lasterrortime = Date.now();
}
if (check.status === 2 && Date.now() - (check.lasterrortime * 1000) <= 86400000) {
check.class = 'label-warning';
check.text = 'degraded performance';
}
return check;
});
var status = data.monitors.reduce(function(status, check) {
return check.status !== 2 ? 'danger' : 'operational';
}, 'operational');
if (!$('#panel').data('incident')) {
$('#panel').attr('class', (status === 'operational' ? 'panel-success' : 'panel-warning') );
$('#paneltitle').html(status === 'operational' ? 'All systems are operational.' : 'One or more systems inoperative');
}
data.monitors.forEach(function(item) {
var name = item.friendly_name;
var clas = item.class;
var text = item.text;
$('#services').append('<div class="list-group-item">'+
'<span class="badge '+ clas + '">' + text + '</span>' +
'<h4 class="list-group-item-heading">' + name + '</h4>' +
'</div>');
});
};
});