Permalink
Browse files

v2.2.4

  • Loading branch information...
apocas committed Nov 24, 2014
1 parent 29a5dbc commit 64b81903fb81a0bcb369a03f5fbe555f2ac84df7
Showing with 69 additions and 27 deletions.
  1. +33 −21 lib/crawler/crawler.js
  2. +10 −4 lib/sensor.js
  3. +1 −1 lib/server.js
  4. +1 −1 package.json
  5. +24 −0 tests/findServer.js
View
@@ -65,27 +65,38 @@ Crawler.prototype.loadServer = function(serverSelf) {
var self = this;
vendors.mongo(function(db) {
db.collection('servers').findOne({
$or: [{
id: serverSelf.id
}, {
address: serverSelf.conf.host
}, {
ips: {
$elemMatch: {
$in: [serverSelf.conf.host]
}
}
}]
},
function(err, server) {
if (!server) {
if (serverSelf.hostname.indexOf(' ') === -1) {
serverSelf.save();
outils.sendMessage('message', 'Server ' + serverSelf.conf.host + ' found.');
db.collection('servers').find({
$or: [{
id: serverSelf.id
}, {
address: serverSelf.conf.host
}, {
ips: {
$elemMatch: {
$in: [serverSelf.conf.host]
}
}
}]
}).toArray(function(err, servers) {
if (servers.length === 0) {
if (serverSelf.hostname.indexOf(' ') === -1) {
serverSelf.save();
outils.sendMessage('message', 'Server ' + serverSelf.conf.host + ' found.');
}
} else {
var server = servers[0];
if (server.id && server.hostname && server.hostname !== serverSelf.hostname) {
db.collection('servers').remove({
'id': server.id
}, function(err, removed) {
if(removed) {
serverSelf.save();
outils.sendMessage('message', 'Server ' + serverSelf.conf.host + ' found.');
}
});
} else {
if (server.address !== serverSelf.conf.host && server.ips.indexOf(serverSelf.conf.host) === -1) {
if (server.address !== serverSelf.conf.host && (!server.ips || server.ips.indexOf(serverSelf.conf.host) === -1)) {
server.ips = server.ips || [];
console.log('Adding address ' + serverSelf.conf.host + ' to ' + server.address);
server.ips.push(serverSelf.conf.host);
@@ -102,8 +113,9 @@ Crawler.prototype.loadServer = function(serverSelf) {
);
}
}
serverSelf.disconnect();
});
}
serverSelf.disconnect();
});
});
};
View
@@ -56,15 +56,21 @@ Sensor.prototype.getStatus = function() {
Sensor.prototype.start = function () {
var self = this;
self.work(function() {
self.interval = setInterval(function () {
self.work();
var handler = function(callback) {
self.timer = setTimeout(function () {
self.work(function() {
handler();
});
}, self.timing);
};
self.work(function() {
handler();
});
};
Sensor.prototype.stop = function () {
clearInterval(this.interval);
clearTimeout(this.timer);
};
Sensor.prototype.work = function (cb) {
View
@@ -93,7 +93,7 @@ Server.prototype.extract = function () {
aux.port = this.conf.port;
aux.id = this.id;
aux.hostname = this.hostname;
aux.ips = this.ips;
//aux.ips = this.ips; //overwriting crawler
aux.connected = this.connected;
aux.sensors = [];
View
@@ -1,6 +1,6 @@
{
"name": "outkept",
"version": "2.2.3",
"version": "2.2.4",
"dependencies": {
"ssh2": "0.3.x",
"prompt": "0.2.x",
View
@@ -0,0 +1,24 @@
var vendors = require('../vendors'),
async = require('async');
vendors.mongo(function(db) {
db.collection('servers').find({
$or: [{
id: ''
}, {
address: ''
}, {
ips: {
$elemMatch: {
$in: ['']
}
}
}]
}).toArray(function(err, servers) {
if (servers.length !== 0) {
console.log('#### FOUND ####');
console.log(servers);
}
});
});

0 comments on commit 64b8190

Please sign in to comment.