This repository has been archived by the owner on Sep 23, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstorm.js
59 lines (55 loc) · 1.64 KB
/
storm.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
var express = require('express');
var dbpoller = require('./dbpoller');
var config = require('./config');
var stuff = {
db: {}
};
/* Start database monitors */
for (var i=0;i<config.dbservers.length; i++) {
conn = dbpoller.connect(config.dbservers[i]);
dbpoller.getmysqlstatus(conn, stuff.db, 5000);
}
/* Set up API server */
app = express();
app.get('/', function(req, res) {
res.setHeader("Content-type", "text/json");
res.send(stuff);
});
app.get('/:subsys', function(req, res) {
var subsys = req.params.subsys;
if (!(subsys in stuff)) {
res.status(404).send("404 Not Found");
return;
}
res.setHeader("Content-type", "text/json");
res.send(Object.keys(stuff[subsys]));
});
app.get('/:subsys/:hostname', function(req, res) {
var subsys = req.params.subsys;
var hostname = req.params.hostname;
if (!(subsys in stuff) || !(hostname in stuff[subsys])) {
res.status(404).send("404 Not Found");
return;
}
res.setHeader("Content-type", "text/json");
res.send(Object.keys(stuff[subsys][hostname]));
});
app.get('/:subsys/:hostname/:sensor', function(req, res) {
var subsys = req.params.subsys;
var hostname = req.params.hostname;
var sensor = req.params.sensor;
if (!(subsys in stuff) || !(hostname in stuff[subsys]) ||
!(sensor in stuff[subsys][hostname])) {
res.status(404).send("404 Not Found");
return;
}
res.setHeader("Content-type", "text/json");
if (typeof stuff[subsys][hostname][sensor] === "object") {
var sv = stuff[subsys][hostname][sensor];
} else {
sv = {};
sv[sensor] = stuff[subsys][hostname][sensor];
}
res.send(sv);
});
app.listen(config.port);