slower timing template for nmap, retabbed source because of inconsistencies
This commit is contained in:
parent
a30d1ba420
commit
3cac37d61f
|
@ -8,37 +8,37 @@ var redisprefix = "ippoll:";
|
||||||
var IpPoll = function(switchaddr, hostsaddr) {
|
var IpPoll = function(switchaddr, hostsaddr) {
|
||||||
var self = this;
|
var self = this;
|
||||||
|
|
||||||
var redisClient = redis.createClient();
|
var redisClient = redis.createClient();
|
||||||
var regexp = /\(([0-9]+) hosts* up\)/;
|
var regexp = /\(([0-9]+) hosts* up\)/;
|
||||||
var nmap = "nmap -n -sP -T5 ";
|
var nmap = "nmap -n -sP -T4 ";
|
||||||
|
|
||||||
redisClient.on("connect", function () {
|
redisClient.on("connect", function () {
|
||||||
console.log("connected to redis");
|
console.log("connected to redis");
|
||||||
self.emit('ready');
|
self.emit('ready');
|
||||||
});
|
});
|
||||||
|
|
||||||
this.pollCount = function() {
|
this.pollCount = function() {
|
||||||
exec(nmap + "--min-hostgroup 10 " + hostsaddr, function (error, stdout, stderr) {
|
exec(nmap + "--min-hostgroup 10 " + hostsaddr, function (error, stdout, stderr) {
|
||||||
if(error == null) {
|
if(error == null) {
|
||||||
var matches = regexp.exec(stdout);
|
var matches = regexp.exec(stdout);
|
||||||
if(matches != null && matches.length == 2) {
|
if(matches != null && matches.length == 2) {
|
||||||
var time = Date.now();
|
var time = Date.now();
|
||||||
|
|
||||||
redisClient.zremrangebyscore('onlinecount', "-inf", time - 7*24*60*1000);
|
redisClient.zremrangebyscore('onlinecount', "-inf", time - 7*24*60*1000);
|
||||||
|
|
||||||
var num = matches[1];
|
var num = matches[1];
|
||||||
|
|
||||||
redisClient.zadd('onlinecount', time, time + "|" + num, function() {
|
redisClient.zadd('onlinecount', time, time + "|" + num, function() {
|
||||||
self.emit('doneCount', num);
|
self.emit('doneCount', num);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
this.pollState = function() {
|
this.pollState = function() {
|
||||||
exec(nmap + switchaddr, function (error, stdout, stderr) {
|
exec(nmap + switchaddr, function (error, stdout, stderr) {
|
||||||
if(error == null) {
|
if(error == null) {
|
||||||
var matches = regexp.exec(stdout);
|
var matches = regexp.exec(stdout);
|
||||||
if(matches != null && matches.length == 2) {
|
if(matches != null && matches.length == 2) {
|
||||||
self.emit('doneState', matches[1] == "1");
|
self.emit('doneState', matches[1] == "1");
|
||||||
|
@ -46,22 +46,22 @@ var IpPoll = function(switchaddr, hostsaddr) {
|
||||||
} else {
|
} else {
|
||||||
self.emit('doneState', "unknown");
|
self.emit('doneState', "unknown");
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
this.getHistory = function(start, end, callback) {
|
this.getHistory = function(start, end, callback) {
|
||||||
|
|
||||||
redisClient.zrangebyscore('onlinecount', "-inf", "+inf", function(err, replies) {
|
redisClient.zrangebyscore('onlinecount', "-inf", "+inf", function(err, replies) {
|
||||||
var data = [];
|
var data = [];
|
||||||
|
|
||||||
replies.forEach(function (reply, i) {
|
replies.forEach(function (reply, i) {
|
||||||
var line = reply.split('|');
|
var line = reply.split('|');
|
||||||
data.push( { at: moment(parseInt(line[0])).format(), value: line[1] });
|
data.push( { at: moment(parseInt(line[0])).format(), value: line[1] });
|
||||||
});
|
});
|
||||||
|
|
||||||
callback(data);
|
callback(data);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
util.inherits(IpPoll, EventEmitter);
|
util.inherits(IpPoll, EventEmitter);
|
||||||
|
|
Loading…
Reference in New Issue