-
Notifications
You must be signed in to change notification settings - Fork 0
/
statusIndicator.js
50 lines (39 loc) · 1.21 KB
/
statusIndicator.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
var blinkstick = require("blinkstick");
var fetch = require("node-fetch");
var {
setRgb,
hexToRgb
} = require("./util");
const fs = require('fs');
setInterval(() => {
// fetch("http://localhost/healthcheck").then(result => {
fetch("http://zero.allenmuncy.com/healthcheck").then(result => {
if(result.status>200) {
// PROBLEMS
var colors = setRgb(...hexToRgb(`#ff0011`));
statusIndicator.setColors(0, colors);
} else {
// All good
setTimeout(() => {
var colors = setRgb(...hexToRgb(`#000100`)); // Perm
statusIndicator.setColors(0, colors);
}, 100);
}
var colors = setRgb(...hexToRgb(`#000200`)); // Blink
statusIndicator.setColors(0, colors);
}).catch(err => {
fs.appendFile("newfile.txt", new Date().toDateString() + " " + new Date().toLocaleTimeString() + "\n", () => {});
var colors = setRgb(...hexToRgb(`#ff0000`));
statusIndicator.setColors(0, colors);
});
}, 60000);
var arr = blinkstick.findAll();
var statusIndicator = arr[0];
var exit = function() {
console.log("Don't be effing rude.");
statusIndicator.setColor("#000000");
process.exit();
}
console.log("We're up");
process.on('exit', exit);
process.on('SIGINT', exit);