-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
26 lines (25 loc) · 893 Bytes
/
server.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
var http = require("http");
var url = require('url');
var nagios = require('./nagios');
http.createServer(function(request, response) {
var url_parts = url.parse(request.url, true);
switch(request.url) {
case "/restart":
console.log("running restart");
break;
default:
var query = url_parts.query;
if(query['hostname'] != undefined) {
if(query['service'] != undefined){
console.log("Adding service entry")
console.log(nagios.CreateServiceEntry(query['service'],query['hostname'],query['ip']));
} else {
console.log("Adding host entry")
console.log(nagios.CreateHostEntry(query['hostname'],query['ip']));
}
response.writeHead(200, {"Content-Type": "text/plain"});
response.write("Added entry ");
}
}
response.end();
}).listen(8888);