-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
125 lines (114 loc) · 2.58 KB
/
index.js
File metadata and controls
125 lines (114 loc) · 2.58 KB
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
#! /usr/bin/env node
const request = require('request');
const rp = require('request-promise');
const chalk = require('chalk');
const Table = require('cli-table');
const jsonfile = require('jsonfile');
const figlet = require('figlet');
const file = './config.json';
const apiKey = jsonfile.readFileSync(file);
const currSym = '$';
figletLog('Checking your uptime...');
var options = {
method: 'POST',
uri: 'https://api.uptimerobot.com/v2/getMonitors',
body: {
api_key: apiKey.key,
all_time_uptime_ratio: 1,
response_times_average: 1,
},
json: true // Automatically stringifies the body to JSON
};
rp(options)
.then(function (parsedBody) {
var table = new Table({ head: [
chalk.blue('ID'),
chalk.blue('Name'),
chalk.blue('URL'),
chalk.blue('Status'),
chalk.blue('Type'),
chalk.blue('Interval'),
chalk.blue('Uptime'),
chalk.blue('Created'),
] });
parsedBody.monitors.forEach(function (value, key) {
table.push([
chalk.blue(value.id),
chalk.green(value.friendly_name),
chalk.green(value.url),
chalk.green(monitorStatus(value.status)),
chalk.green(monitorType(value.type)),
chalk.green(value.interval),
chalk.green(value.all_time_uptime_ratio+'%'),
chalk.green(new Date(value.create_datetime * 1000).toUTCString()),
]);
});
console.log('\n'+table.toString());
})
.catch(function (err) {
console.log('Something went wrong...');
console.log(err);
});
/**
* Figlet console log
*/
function figletLog(text) {
figlet(text, function(err, data) {
if (err) {
console.log('Something went wrong...');
console.dir(err);
return;
}
console.log(data)
});
}
/**
* Switch case for monitor types
* Makes API data understandable
*/
var monitorType = function monitorType(typeNumber) {
switch(typeNumber) {
case 1:
type = "HTTP(s)";
break;
case 2:
type = "Keyword";
break;
case 3:
type = "Ping";
break;
case 4:
type = "Port";
break;
default:
type = "Unknown";
}
return type;
}
/**
* Switch case for monitor statuses
* Makes API data understandable
*/
var monitorStatus = function monitorStatus(statusNumber) {
switch(statusNumber) {
case 0:
status = "Paused";
break;
case 1:
status = "Not Checked Yet";
break;
case 2:
status = "Up";
break;
case 8:
status = "Seems Down";
break;
case 9:
status = "Down";
break;
default:
status = "Unknown";
}
return status;
}
module.exports = { options, monitorType, monitorStatus };