From f4630b30b079fb2879c7bb75709f761b339cc971 Mon Sep 17 00:00:00 2001 From: Christian Kroll Date: Tue, 26 Nov 2013 21:11:05 +0100 Subject: [PATCH] retabbed source because of inconsistencies... again --- node/ip-poll.js | 90 ++++++++++++++++++++++++------------------------- 1 file changed, 45 insertions(+), 45 deletions(-) diff --git a/node/ip-poll.js b/node/ip-poll.js index d512e10..6803b99 100644 --- a/node/ip-poll.js +++ b/node/ip-poll.js @@ -6,62 +6,62 @@ var exec = require('child_process').exec; var redisprefix = "ippoll:"; var IpPoll = function(switchaddr, hostsaddr) { - var self = this; + var self = this; - var redisClient = redis.createClient(); - var regexp = /\(([0-9]+) hosts* up\)/; - var nmap = "nmap -n -sP -T4 "; + var redisClient = redis.createClient(); + var regexp = /\(([0-9]+) hosts* up\)/; + var nmap = "nmap -n -sP -T4 "; - redisClient.on("connect", function () { - console.log("connected to redis"); - self.emit('ready'); - }); + redisClient.on("connect", function () { + console.log("connected to redis"); + self.emit('ready'); + }); - this.pollCount = function() { - exec(nmap + "--min-hostgroup 10 " + hostsaddr, function (error, stdout, stderr) { - if(error == null) { - var matches = regexp.exec(stdout); - if(matches != null && matches.length == 2) { - var time = Date.now(); + this.pollCount = function() { + exec(nmap + "--min-hostgroup 10 " + hostsaddr, function (error, stdout, stderr) { + if(error == null) { + var matches = regexp.exec(stdout); + if(matches != null && matches.length == 2) { + 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() { - self.emit('doneCount', num); - }); - } - } - }); - }; + redisClient.zadd('onlinecount', time, time + "|" + num, function() { + self.emit('doneCount', num); + }); + } + } + }); + }; - this.pollState = function() { - exec(nmap + switchaddr, function (error, stdout, stderr) { - if(error == null) { - var matches = regexp.exec(stdout); - if(matches != null && matches.length == 2) { - self.emit('doneState', matches[1] == "1"); - } - } else { - self.emit('doneState', "unknown"); - } - }); - }; + this.pollState = function() { + exec(nmap + switchaddr, function (error, stdout, stderr) { + if(error == null) { + var matches = regexp.exec(stdout); + if(matches != null && matches.length == 2) { + self.emit('doneState', matches[1] == "1"); + } + } else { + self.emit('doneState', "unknown"); + } + }); + }; - this.getHistory = function(start, end, callback) { + this.getHistory = function(start, end, callback) { - redisClient.zrangebyscore('onlinecount', "-inf", "+inf", function(err, replies) { - var data = []; + redisClient.zrangebyscore('onlinecount', "-inf", "+inf", function(err, replies) { + var data = []; - replies.forEach(function (reply, i) { - var line = reply.split('|'); - data.push( { at: moment(parseInt(line[0])).format(), value: line[1] }); - }); + replies.forEach(function (reply, i) { + var line = reply.split('|'); + data.push( { at: moment(parseInt(line[0])).format(), value: line[1] }); + }); - callback(data); - }); - }; + callback(data); + }); + }; }; util.inherits(IpPoll, EventEmitter);