From 484cb71804ed26ddb3d03c222deea94eb8e029bb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lucas=20Ple=C3=9F?= Date: Sun, 4 Sep 2022 14:18:40 +0200 Subject: [PATCH] cleaned up ip-poll.js --- ip-poll.js | 49 ++----------------------------------------------- 1 file changed, 2 insertions(+), 47 deletions(-) diff --git a/ip-poll.js b/ip-poll.js index a5113b5..cf051b5 100644 --- a/ip-poll.js +++ b/ip-poll.js @@ -1,50 +1,20 @@ -//var redis = require("redis"); var util = require('util'); var EventEmitter = require('events').EventEmitter; var exec = require('child_process').exec; -var moment = require('moment'); -var redisprefix = "ippoll:"; - var IpPoll = function(switchaddr, hostsaddr) { var self = this; -// var redisClient = redis.createClient(); var regexp = /\(([0-9]+) hosts* up\)/; var nmap = "nmap -n -sP "; -/* - redisClient.on("connect", function () { - console.log("IP-Poll: 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(); - - redisClient.zremrangebyscore(redisprefix + 'onlinecount', "-inf", time - 7*24*60*1000); - - var num = matches[1]; - - redisClient.zadd(redisprefix + 'onlinecount', time, time + "|" + num, function() { - self.emit('doneCount', parseInt(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"); + if(matches != null && matches.length === 2) { + self.emit('doneState', matches[1] === "1"); } } else { self.emit('doneState', "unknown"); @@ -52,22 +22,7 @@ var IpPoll = function(switchaddr, hostsaddr) { }); }; - /* - this.getHistory = function(start, end, callback) { - - redisClient.zrangebyscore(redisprefix + '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] }); - }); - - callback(data); - }); - };*/ }; util.inherits(IpPoll, EventEmitter); - module.exports = IpPoll;