-
Notifications
You must be signed in to change notification settings - Fork 0
/
ubnt.js
executable file
·41 lines (35 loc) · 1.14 KB
/
ubnt.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
38
39
40
41
/*
* https://github.com/delian/node-unifiapi
* https://ubntwiki.com/products/software/unifi-controller/api
*
*/
const unifi = require('node-unifiapi');
const winston = require('winston')
module.exports = function(god, loggerName = 'ubnt') {
var self = {
controller: {},
init: function() {
this.logger = winston.loggers.get(loggerName)
this.logger.info("Connecting to Unifi controller on " + god.config.ubnt.controllerUrl)
this.controller = unifi({
baseUrl: god.config.ubnt.controllerUrl,
username: god.config.ubnt.user,
password: god.config.ubnt.passwd,
// debug: true, // More debug of the API (uses the debug module)
// debugNet: true // Debug of the network requests (uses request module)
})
this.controller.list_clients()
.then(done => {
// this.logger.warn('Success %o',done)
done.data.forEach(client => {
let l = Math.trunc(Date.now() / 1000) - client.last_seen
let line = client.hostname + " (last seen " + l + " sec ago)"
this.logger.debug(line)
})
})
.catch(err => this.logger.error('Error %o',err))
},
}
self.init()
return self
}