-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathscript.js
141 lines (122 loc) · 4.2 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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
$(document).ready(function() {
var config = {
uptimerobot: {
api_keys: [
],
logs: 1
},
github: {
org: 'flybaseio',
repo: 'status'
}
};
var status_text = {
'operational': 'operational',
'investigating': 'investigating',
'major outage': 'outage',
'degraded performance': 'degraded',
};
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>');
});
};
$.getJSON( 'https://api.github.com/repos/' + config.github.org + '/' + config.github.repo + '/issues?state=all' ).done(message);
function message(issues) {
issues.forEach(function(issue) {
if( issue.labels.length > 0 ){ // only display labelled issues
var status = issue.labels.reduce(function(status, label) {
if (/^status:/.test(label.name)) {
return label.name.replace('status:', '');
} else {
return status;
}
}, 'operational');
var systems = issue.labels.filter(function(label) {
return /^system:/.test(label.name);
}).map(function(label) {
return label.name.replace('system:', '')
});
if (issue.state === 'open') {
$('#panel').data('incident', 'true');
$('#panel').attr('class', (status === 'operational' ? 'panel-success' : 'panel-warn') );
$('#paneltitle').html('<a href="#incidents">' + issue.title + '</a>');
}
var html = '<article class="timeline-entry">\n';
html += '<div class="timeline-entry-inner">\n';
if (issue.state === 'closed') {
html += '<div class="timeline-icon bg-success"><i class="entypo-feather"></i></div>';
} else {
html += '<div class="timeline-icon bg-secondary"><i class="entypo-feather"></i></div>';
}
html += '<div class="timeline-label">\n';
html += '<span class="date">' + datetime(issue.created_at) + '</span>\n';
// status
if (issue.state === 'closed') {
html += '<span class="badge label-success pull-right">closed</span>';
} else {
html += '<span class="badge ' + (status === 'operational' ? 'label-success' : 'label-warn') + ' pull-right">';
html += "open";
html += '</span>\n';
}
// systems
for (var i = 0; i < systems.length; i++) {
html += '<span class="badge system pull-right">' + systems[i] + '</span>';
}
html += '<h2>' + issue.title + '</h2>\n';
html += '<hr>\n';
html += '<p>' + issue.body + '</p>\n';
if (issue.state === 'closed') {
html += '<p><em>Updated ' + datetime(issue.closed_at) + '<br/>';
html += 'The system is back in normal operation.</p>';
}
html += '</div>';
html += '</div>';
html += '</article>';
$('#incidents').append(html);
}
});
function datetime(string) {
var datetime = string.split('T');
var date = datetime[0];
var time = datetime[1].replace('Z', '');
return date + ' ' + time;
};
};
});