var util = require('util'); var EventEmitter = require('events').EventEmitter; var request = require('request'); var Flukso = function(hostname, pathname) { var self = this; var regexp = /([0-9]+)\]\]$/; // /\(([0-9]+) hosts* up\)/; this.pollPower = function() { request({url: "http://" + hostname + pathname}, function(error, res, response) { if (error) { self.emit('failed', error) } else { var matches = regexp.exec(response); if(matches != null && matches.length == 2) { var time = Date.now(); var num = matches[1]; self.emit('done', parseInt(num)); } } }); }; }; util.inherits(Flukso, EventEmitter); module.exports = Flukso;