-
Notifications
You must be signed in to change notification settings - Fork 0
/
hnm.js
131 lines (123 loc) · 3.39 KB
/
hnm.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
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
126
127
128
129
130
131
//
// hnm.js -- Home Network Monitor
//
// John D. Allen
// July 2013
//
var c = require('./config.json');
var test = require('./tests.js');
var scr = require('./screen.js');
const STARTX = 4;
const STARTY = 3;
scr.setColIncr(40);
var pos = [];
//---------------------------------------------------------------------------
// runTests() -- Main function that fires off all the various node tests.
//---------------------------------------------------------------------------
function runTests() {
// parse through nodes array and fire off tests
scr.setHome(STARTX, STARTY);
c.nodes.forEach((node) => {
pos = scr.nextXY();
runATest(pos, node);
});
}
//---------------------------------------------------------------------------
// runATest() -- Each node/test gens this function call to handle the
// request in an asynch manner.
//
// Available Tests:
// ping -- Do a simple ping to the node IP address.
// http -- Do a simple HTTP call to the node.
// https -- Do a HTTPS call, but ignore SSL errors.
// dnsquery -- Check the IP for a response to a DNS Query.
// extcmd -- Run an External Command using the passed string. Must return "OK" to pass.
// wpchk -- Check to see if Wordpress Website is responding correctly.
//---------------------------------------------------------------------------
function runATest(p,n) {
scr.label(p, n.name);
switch(n.test) {
case "ping":
test.ping(n.ip, n.log).then((out) => {
if (out) {
scr.up(p);
} else {
scr.down(p);
}
});
break;
case "http":
test.http(n.ip, n.port, n.log).then((out) => {
if (out) {
scr.up(p);
} else {
scr.down(p);
}
});
break;
case "https":
test.https(n.ip, n.port, n.log).then((out) => {
if (out) {
scr.up(p);
} else {
scr.down(p);
}
});
break;
case "dnsquery":
test.dnsquery(n.ip, n.log).then((out) => {
if (out) {
scr.up(p);
} else {
scr.down(p);
}
});
break;
case "extcmd":
test.extcmd(n.cmd, n.log).then((out) => {
if (out) {
scr.up(p);
} else {
scr.down(p);
}
});
break;
case "wpchk":
test.wpchk(n.fqdn, n.log).then((out) => {
if (out) {
scr.up(p);
} else {
scr.down(p);
}
});
break;
default:
scr.unkn(p);
break
}
setTimeout(runATest, n.freq, p, n); // Reschedule test
}
function setScreen() {
scr.showHeader("Home Network Monitor");
scr.setHome(STARTX, STARTY);
c.nodes.forEach((node) => {
pos = scr.nextXY();
scr.unkn(pos);
scr.label(pos, node.name);
});
setTimeout(setScreen, 3600000); // Refresh once an hour
}
function showTimestamp() {
scr.hdrTimeStamp();
setTimeout(showTimestamp, 60000);
}
//---------------------------------------------------------------------------
// main() -- Main function that starts the tests.
//---------------------------------------------------------------------------
function main() {
setScreen();
showTimestamp();
runTests();
}
//---------------------------------------------------------------------------
main();