$(document).ready(function() { var config = { uptimerobot: { api_keys: [ "YOUR-UPTIME-ROBOT-API-KEY-1", "YOUR-UPTIME-ROBOT-API-KEY-2" ], logs: 1 }, github: { org: 'YOUR-GITHUB-USERNAME', repo: 'YOUR-GITHUB-REPO' } }; 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('
'+ '' + text + '' + '

' + name + '

' + '
'); }); }; $.getJSON( 'https://api.github.com/repos/' + config.github.org + '/' + config.github.repo + '/issues?state=all' ).done(message); function message(issues) { issues.forEach(function(issue) { 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('' + issue.title + ''); } var html = '
\n'; html += '
\n'; if (issue.state === 'closed') { html += '
'; } else { html += '
'; } html += '
\n'; html += '' + datetime(issue.created_at) + '\n'; if (issue.state === 'closed') { html += 'closed'; } else { html += 'open\n'; } for (var i = 0; i < systems.length; i++) { html += '' + systems[i] + ''; } html += '

' + issue.title + '

\n'; html += '
\n'; html += '

' + issue.body + '

\n'; if (issue.state === 'closed') { html += '

Updated ' + datetime(issue.closed_at) + '
'; html += 'The system is back in normal operation.

'; } html += '
'; html += '
'; html += '
'; $('#incidents').append(html); }); function datetime(string) { var datetime = string.split('T'); var date = datetime[0]; var time = datetime[1].replace('Z', ''); return date + ' ' + time; }; }; });