2014-07-23 00:16:15 +00:00
|
|
|
var util = require('util');
|
|
|
|
var EventEmitter = require('events').EventEmitter;
|
|
|
|
var http = require("http");
|
|
|
|
|
|
|
|
var Flukso = function(hostname, pathname) {
|
|
|
|
var self = this;
|
|
|
|
var regexp = /([0-9]+)\]\]$/; // /\(([0-9]+) hosts* up\)/;
|
|
|
|
|
|
|
|
this.pollPower = function() {
|
|
|
|
http.request({ host: hostname, path: pathname }, function(response) {
|
|
|
|
var str = '';
|
|
|
|
|
|
|
|
response.on('data', function(chunk) {
|
|
|
|
str += chunk;
|
|
|
|
});
|
|
|
|
|
|
|
|
response.on('end', function () {
|
|
|
|
var matches = regexp.exec(str);
|
|
|
|
if(matches != null && matches.length == 2) {
|
|
|
|
var time = Date.now();
|
|
|
|
var num = matches[1];
|
2014-07-23 00:45:57 +00:00
|
|
|
self.emit('done', parseInt(num));
|
2014-07-23 00:16:15 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}).end();
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
util.inherits(Flukso, EventEmitter);
|
|
|
|
module.exports = Flukso;
|