Skip to content

Commit

Permalink
Pull from api/v2/components.json now and get what servcies are down
Browse files Browse the repository at this point in the history
  • Loading branch information
Phara0h committed Nov 3, 2020
1 parent 073f42c commit 3cb27a1
Showing 1 changed file with 33 additions and 8 deletions.
41 changes: 33 additions & 8 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class Checker {
async check() {
try {
var res = await fasquest.request({
uri: 'https://www.cloudflarestatus.com/api/v2/status.json',
uri: 'https://cloudflarestatus.com/api/v2/components.json',
method: 'GET',
simple: false,
resolveWithFullResponse: true,
Expand All @@ -30,24 +30,49 @@ class Checker {
}
});
var code = 500;
var components = res.body.components;
var overallStatus = 'unknown';
var group = '';
var message = '';

switch (res.body.status.indicator) {
case 'none':
for (var i = 0; i < components.length; i++) {
if (components[i].name == 'Cloudflare Sites and Services') {
overallStatus = components[i].status;
group = components[i].id;
} else if (
components[i].group_id == group &&
components[i].status != 'operational'
) {
message += `${components[i].name}:${components[i].status}, `;
}
}

//remove trailling comma
if (message != '') {
message = message.slice(0, -2);
}

switch (overallStatus) {
case 'operational':
code = 200;
message = 'All systems are operational!';
break;
case 'minor':
case 'degraded_performance':
code = 490;
break;
case 'major':
case 'partial_outage':
code = 491;
break;
case 'critical':
case 'major_outage':
code = 492;
break;
case 'unknown':
code = 500;
message = 'Unknown';
}
return {
code: code,
message: res.body.status.description
code,
message
};
} catch (e) {
return {
Expand Down

0 comments on commit 3cb27a1

Please sign in to comment.