Add badges for Uptime Robot (#947)
* numberOfDays optional (default 30) for Uptime Robot ratio * Require a monitor key, not a user key * Update gitignore for Jetbrains
This commit is contained in:
parent
c5bd4a4f5a
commit
a079b682e3
3
.gitignore
vendored
3
.gitignore
vendored
|
@ -18,6 +18,9 @@ Thumbs.db
|
|||
.Spotlight-V100
|
||||
.Trashes
|
||||
|
||||
# Jetbrains
|
||||
/.idea
|
||||
|
||||
# Created by https://www.gitignore.io/api/node
|
||||
|
||||
### Node ###
|
||||
|
|
12
index.html
12
index.html
|
@ -935,6 +935,18 @@ Pixel-perfect Retina-ready Fast Consistent Hackable
|
|||
<td><img src='https://img.shields.io/swagger/valid/2.0/https/bitbucket.org/api/swagger.json.svg?maxAge=2592000' alt=''/></td>
|
||||
<td><code>https://img.shields.io/swagger/valid/2.0/https/bitbucket.org/api/swagger.json.svg</code></td>
|
||||
</tr>
|
||||
<tr><th> Uptime Robot status: </th>
|
||||
<td><img src='https://img.shields.io/uptimerobot/status/m778918918-3e92c097147760ee39d02d36.svg?maxAge=2592000' alt=''/></td>
|
||||
<td><code>https://img.shields.io/uptimerobot/status/m778918918-3e92c097147760ee39d02d36.svg</code></td>
|
||||
</tr>
|
||||
<tr><th> Uptime Robot ratio: </th>
|
||||
<td><img src='https://img.shields.io/uptimerobot/ratio/m778918918-3e92c097147760ee39d02d36.svg?maxAge=2592000' alt=''/></td>
|
||||
<td><code>https://img.shields.io/uptimerobot/ratio/m778918918-3e92c097147760ee39d02d36.svg</code></td>
|
||||
</tr>
|
||||
<tr><th> Uptime Robot ratio (7 days): </th>
|
||||
<td><img src='https://img.shields.io/uptimerobot/ratio/7/m778918918-3e92c097147760ee39d02d36.svg?maxAge=2592000' alt=''/></td>
|
||||
<td><code>https://img.shields.io/uptimerobot/ratio/7/m778918918-3e92c097147760ee39d02d36.svg</code></td>
|
||||
</tr>
|
||||
</tbody></table>
|
||||
|
||||
<h3 id="miscellaneous"> Longer Miscellaneous </h3>
|
||||
|
|
132
server.js
132
server.js
|
@ -6089,6 +6089,138 @@ cache(function(data, match, sendBadge, request) {
|
|||
});
|
||||
}));
|
||||
|
||||
// Uptime Robot status integration.
|
||||
// API documentation : https://uptimerobot.com/api
|
||||
camp.route(/^\/uptimerobot\/status\/(.*)\.(svg|png|gif|jpg|json)$/,
|
||||
cache(function(data, match, sendBadge, request) {
|
||||
var monitorApiKey = match[1]; // eg, m778918918-3e92c097147760ee39d02d36
|
||||
var format = match[2];
|
||||
var badgeData = getBadgeData('status', data);
|
||||
var options = {
|
||||
method: 'POST',
|
||||
json: true,
|
||||
body: {
|
||||
"api_key": monitorApiKey,
|
||||
"format": "json"
|
||||
},
|
||||
uri: 'https://api.uptimerobot.com/v2/getMonitors'
|
||||
};
|
||||
// A monitor API key must start with "m"
|
||||
if (monitorApiKey.substring(0, "m".length) !== "m") {
|
||||
badgeData.text[1] = 'must use a monitor key';
|
||||
sendBadge(format, badgeData);
|
||||
return;
|
||||
}
|
||||
request(options, function(err, res, json) {
|
||||
if (err !== null || res.statusCode >= 500 || typeof json !== 'object') {
|
||||
badgeData.text[1] = 'inaccessible';
|
||||
sendBadge(format, badgeData);
|
||||
return;
|
||||
}
|
||||
try {
|
||||
if (json.stat === 'fail') {
|
||||
badgeData.text[1] = 'vendor error';
|
||||
if (json.error && typeof json.error.message === 'string') {
|
||||
badgeData.text[1] = json.error.message;
|
||||
}
|
||||
badgeData.colorscheme = 'lightgrey';
|
||||
sendBadge(format, badgeData);
|
||||
return;
|
||||
}
|
||||
var status = json.monitors[0].status;
|
||||
if (status === 0) {
|
||||
badgeData.text[1] = 'paused';
|
||||
badgeData.colorscheme = 'yellow';
|
||||
} else if (status === 1) {
|
||||
badgeData.text[1] = 'not checked yet';
|
||||
badgeData.colorscheme = 'yellowgreen';
|
||||
} else if (status === 2) {
|
||||
badgeData.text[1] = 'up';
|
||||
badgeData.colorscheme = 'brightgreen';
|
||||
} else if (status === 8) {
|
||||
badgeData.text[1] = 'seems down';
|
||||
badgeData.colorscheme = 'orange';
|
||||
} else if (status === 9) {
|
||||
badgeData.text[1] = 'down';
|
||||
badgeData.colorscheme = 'red';
|
||||
} else {
|
||||
badgeData.text[1] = 'invalid';
|
||||
badgeData.colorscheme = 'lightgrey';
|
||||
}
|
||||
sendBadge(format, badgeData);
|
||||
} catch(e) {
|
||||
badgeData.text[1] = 'invalid';
|
||||
sendBadge(format, badgeData);
|
||||
}
|
||||
});
|
||||
}));
|
||||
|
||||
// Uptime Robot ratio integration.
|
||||
// API documentation : https://uptimerobot.com/api
|
||||
camp.route(/^\/uptimerobot\/ratio(\/[^\/]+)?\/(.*)\.(svg|png|gif|jpg|json)$/,
|
||||
cache(function(data, match, sendBadge, request) {
|
||||
var numberOfDays = match[1]; // eg, 7, null if querying 30
|
||||
var monitorApiKey = match[2]; // eg, m778918918-3e92c097147760ee39d02d36
|
||||
var format = match[3];
|
||||
var badgeData = getBadgeData('uptime', data);
|
||||
if (numberOfDays) {
|
||||
numberOfDays = numberOfDays.slice(1);
|
||||
} else {
|
||||
numberOfDays = '30';
|
||||
}
|
||||
var options = {
|
||||
method: 'POST',
|
||||
json: true,
|
||||
body: {
|
||||
"api_key": monitorApiKey,
|
||||
"custom_uptime_ratios": numberOfDays,
|
||||
"format": "json"
|
||||
},
|
||||
uri: 'https://api.uptimerobot.com/v2/getMonitors'
|
||||
};
|
||||
// A monitor API key must start with "m"
|
||||
if (monitorApiKey.substring(0, "m".length) !== "m") {
|
||||
badgeData.text[1] = 'must use a monitor key';
|
||||
sendBadge(format, badgeData);
|
||||
return;
|
||||
}
|
||||
request(options, function(err, res, json) {
|
||||
if (err !== null) {
|
||||
badgeData.text[1] = 'inaccessible';
|
||||
sendBadge(format, badgeData);
|
||||
return;
|
||||
}
|
||||
try {
|
||||
if (json.stat === 'fail') {
|
||||
badgeData.text[1] = 'vendor error';
|
||||
if (json.error && typeof json.error.message === 'string') {
|
||||
badgeData.text[1] = json.error.message;
|
||||
}
|
||||
badgeData.colorscheme = 'lightgrey';
|
||||
sendBadge(format, badgeData);
|
||||
return;
|
||||
}
|
||||
var percent = parseFloat(json.monitors[0].custom_uptime_ratio);
|
||||
badgeData.text[1] = percent + '%';
|
||||
if (percent <= 10) {
|
||||
badgeData.colorscheme = 'red';
|
||||
} else if (percent <= 30) {
|
||||
badgeData.colorscheme = 'yellow';
|
||||
} else if (percent <= 50) {
|
||||
badgeData.colorscheme = 'yellowgreen';
|
||||
} else if (percent <= 70) {
|
||||
badgeData.colorscheme = 'green';
|
||||
} else {
|
||||
badgeData.colorscheme = 'brightgreen';
|
||||
}
|
||||
sendBadge(format, badgeData);
|
||||
} catch (e) {
|
||||
badgeData.text[1] = 'invalid';
|
||||
sendBadge(format, badgeData);
|
||||
}
|
||||
});
|
||||
}));
|
||||
|
||||
// Any badge.
|
||||
camp.route(/^\/(:|badge\/)(([^-]|--)*?)-(([^-]|--)*)-(([^-]|--)+)\.(svg|png|gif|jpg)$/,
|
||||
function(data, match, end, ask) {
|
||||
|
|
12
try.html
12
try.html
|
@ -946,6 +946,18 @@ Pixel-perfect Retina-ready Fast Consistent Hackable
|
|||
<td><img src='/swagger/valid/2.0/https/bitbucket.org/api/swagger.json.svg' alt=''/></td>
|
||||
<td><code>https://img.shields.io/swagger/valid/2.0/https/bitbucket.org/api/swagger.json.svg</code></td>
|
||||
</tr>
|
||||
<tr><th> Uptime Robot status: </th>
|
||||
<td><img src='/uptimerobot/status/m778918918-3e92c097147760ee39d02d36.svg' alt=''/></td>
|
||||
<td><code>https://img.shields.io/uptimerobot/status/m778918918-3e92c097147760ee39d02d36.svg</code></td>
|
||||
</tr>
|
||||
<tr><th> Uptime Robot ratio: </th>
|
||||
<td><img src='/uptimerobot/ratio/m778918918-3e92c097147760ee39d02d36.svg' alt=''/></td>
|
||||
<td><code>https://img.shields.io/uptimerobot/ratio/m778918918-3e92c097147760ee39d02d36.svg</code></td>
|
||||
</tr>
|
||||
<tr><th> Uptime Robot ratio (7 days): </th>
|
||||
<td><img src='/uptimerobot/ratio/7/m778918918-3e92c097147760ee39d02d36.svg' alt=''/></td>
|
||||
<td><code>https://img.shields.io/uptimerobot/ratio/7/m778918918-3e92c097147760ee39d02d36.svg</code></td>
|
||||
</tr>
|
||||
</tbody></table>
|
||||
|
||||
<h3 id="miscellaneous"> Longer Miscellaneous </h3>
|
||||
|
|
Loading…
Reference in New Issue
Block a user