-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
37 lines (36 loc) · 938 Bytes
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
var inspect = require('eyespect').inspector();
var EventEmitter = require('events').EventEmitter;
var propagit = require('propagit')
var rk = require('required-keys');
module.exports = function (data, cb) {
var keys = ['host', 'port', 'secret']
var err = rk.truthySync(data, keys)
if (err) {
return cb({
message: 'error getting json output from fleet, missing key in data',
error: err,
stack: new Error().stack
})
}
var host = data.host
var port = data.port
var secret = data.secret
var hub = [host, port].join(':')
var propData = {
hub: host + ':' + port,
secret: secret
}
var p = propagit(propData)
p.hub.on('up', function (hub) {
var em = new EventEmitter
var output = {}
em.on('data', function (key, procs) {
output[key] = procs
});
em.on('end', function () {
p.hub.close();
cb(null, output)
});
hub.ps(em.emit.bind(em));
})
}