changed nmap timing,

added label to gage,
cleaned up a bit,
removed redis foo from flukso code since it is not needed
This commit is contained in:
Lucas Pleß 2014-07-23 02:45:57 +02:00
parent 0dd746c47f
commit b89ebeaf4f
6 changed files with 18 additions and 51 deletions

View File

@ -1,24 +1,12 @@
var redis = require("redis");
var util = require('util'); var util = require('util');
var EventEmitter = require('events').EventEmitter; var EventEmitter = require('events').EventEmitter;
var http = require("http"); var http = require("http");
var redisprefix = "flukso:";
var Flukso = function(hostname, pathname) { var Flukso = function(hostname, pathname) {
var self = this; var self = this;
var redisClient = redis.createClient();
var regexp = /([0-9]+)\]\]$/; // /\(([0-9]+) hosts* up\)/; var regexp = /([0-9]+)\]\]$/; // /\(([0-9]+) hosts* up\)/;
redisClient.on("connect", function () {
console.log("connected to redis");
self.emit('ready');
});
this.pollPower = function() { this.pollPower = function() {
http.request({ host: hostname, path: pathname }, function(response) { http.request({ host: hostname, path: pathname }, function(response) {
var str = ''; var str = '';
@ -27,39 +15,16 @@ var Flukso = function(hostname, pathname) {
}); });
response.on('end', function () { response.on('end', function () {
// console.log("http received: " + str);
var matches = regexp.exec(str); var matches = regexp.exec(str);
if(matches != null && matches.length == 2) { if(matches != null && matches.length == 2) {
var time = Date.now(); var time = Date.now();
redisClient.zremrangebyscore(redisprefix + 'power', "-inf", time - 7*24*60*1000);
var num = matches[1]; var num = matches[1];
self.emit('done', parseInt(num));
redisClient.zadd(redisprefix + 'power', time, time + "|" + num, function() {
self.emit('done', parseInt(num));
});
} }
}); });
}).end(); }).end();
}; };
// this.getHistory = function(start, end, callback) {
//
// redisClient.zrangebyscore(redisprefix + 'power', start, end, 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(Flukso, EventEmitter); util.inherits(Flukso, EventEmitter);
module.exports = Flukso; module.exports = Flukso;

View File

@ -10,7 +10,7 @@ var IpPoll = function(switchaddr, hostsaddr) {
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 -T3 "; var nmap = "nmap -n -sP -T2 ";
redisClient.on("connect", function () { redisClient.on("connect", function () {
console.log("connected to redis"); console.log("connected to redis");

View File

@ -10,8 +10,8 @@ angular.module('roomstateapp.controllers', []).
url: '/api/simple/v2' url: '/api/simple/v2'
}). }).
success(function (data, status, headers, config) { success(function (data, status, headers, config) {
$scope.simple = data;
gpower.refresh(message.data.power); gpower.refresh(message.data.power);
$scope.simple = data;
}). }).
error(function (data, status, headers, config) { error(function (data, status, headers, config) {
//$scope.name = 'Error!' //$scope.name = 'Error!'
@ -20,8 +20,8 @@ angular.module('roomstateapp.controllers', []).
Socket.on('sdata', function(message) { Socket.on('sdata', function(message) {
console.log("received data from server: " + message.data.names); console.log("received data from server: " + message.data.names);
$scope.simple = message.data;
gpower.refresh(message.data.power); gpower.refresh(message.data.power);
$scope.simple = message.data;
}); });
}); });
@ -75,8 +75,10 @@ gpower = new JustGage({
id: "gauge", id: "gauge",
value: 0, value: 0,
min: 0, min: 0,
max: 15000, max: 60000,
title: "Power" title: " ",
label: "Watt",
showMinMax: false
}); });
}); });

View File

@ -1,10 +1,10 @@
exports.index = function (req, res) { exports.index = function (req, res) {
res.render('index', { title: 'Home', status: req.flash('status') }) res.render('index', { title: 'Home' })
}; };
exports.db = function (req, res) { exports.db = function (req, res) {
res.render('database', { title: 'Manage MAC', status: req.flash('status') }) res.render('database', { title: 'Manage MAC' })
}; };
exports.form = function (req, res) { exports.form = function (req, res) {

View File

@ -2,6 +2,13 @@ extend layout
block content block content
.intro
p
| Hier siehst du den aktuellen Status von uns. Die Daten werden vom Router und unserem Flukso
| eingesammelt. Die Anzahl der Geräte und der Status selber werden Minütlich abgefragt. Unseren
| Energieverbrauch bekommst du alle fünf Sekunden neu. Den Status "geöffnet" oder "geschlossen"
| bestimmt das Programm mit einem ping auf den Switch im Raum.
.ink-grid(ng-controller='StatusCtrl') .ink-grid(ng-controller='StatusCtrl')
.column-group.gutters .column-group.gutters
.large-20.medium-20.small-100 .large-20.medium-20.small-100
@ -22,7 +29,7 @@ block content
.large-50.medium-80.small-100 .large-50.medium-80.small-100
h2 Anzahl Geräte: h2 Anzahl Geräte im LAN:
#graph #graph

View File

@ -19,13 +19,6 @@ html(ng-app="roomstateapp")
header header
h1 chaostreff status h1 chaostreff status
.intro
p
| Hier siehst du den aktuellen Status von uns. Die Daten werden vom Router und unserem Flukso
| eingesammelt. Die Anzahl der Geräte und der Status selber werden Minütlich abgefragt. Unseren
| Energieverbrauch bekommst du alle fünf Sekunden neu. Den Status "geöffnet" oder "geschlossen"
| bestimmt das Programm mit einem ping auf den Switch im Raum.
.main-content .main-content
block content block content