minor tweaks

This commit is contained in:
David Newhall II 2019-01-26 04:04:36 -08:00
parent f3a87e2e37
commit 7256b15467
3 changed files with 9 additions and 8 deletions

View File

@ -5,19 +5,17 @@ an authenticated http Client you may use to query the device for data. Also
contains some built-in methods for de-serializing common client and device
data. The data is provided in a large struct you can consume in your application.
This library also contains methods to export the Unifi data in InfluxDB format.
This library also contains methods to export the Unifi data in InfluxDB format,
and this can be used as an example to base your own metrics collection methods.
Pull requests and feedback are welcomed!
Here's a working example:
```golang
package main
import (
"log"
"github.com/golift/unifi"
)
import "log"
import "github.com/golift/unifi"
func main() {
username := "admin"
@ -27,7 +25,7 @@ func main() {
if err != nil {
log.Fatalln("error:", err)
}
// Log with log.Printf or make your own interface.
// Log with log.Printf or make your own interface that accepts (msg, fmt)
uni.ErrorLog = log.Printf
uni.DebugLog = log.Printf
clients, err := uni.GetUnifiClients()
@ -45,7 +43,7 @@ func main() {
log.Println(len(devices.USWs), "Unifi Switches Found")
log.Println(len(devices.USGs), "Unifi Gateways Found")
log.Println(len(devices.UAPs), "Unifi Access Points Found:")
log.Println(len(devices.UAPs), "Unifi Wireless APs Found:")
for i, uap := range devices.UAPs {
log.Println(i+1, uap.Name, uap.IP)
}

View File

@ -10,6 +10,7 @@ import (
// Points generates a client's datapoints for InfluxDB.
func (u UCL) Points() ([]*influx.Point, error) {
var points []*influx.Point
// Fix name and hostname fields. Sometimes one or the other is blank.
if u.Name == "" && u.Hostname != "" {
u.Name = u.Hostname
} else if u.Hostname == "" && u.Name != "" {

View File

@ -221,6 +221,7 @@ func (u UAP) Points() ([]*influx.Point, error) {
fields["radio_tx_power"] = s.TxPower
fields["radio_tx_retries"] = s.TxRetries
fields["user-num_sta"] = s.UserNumSta
continue
}
}
for _, s := range u.VapTable {
@ -254,6 +255,7 @@ func (u UAP) Points() ([]*influx.Point, error) {
fields["tx_retries"] = s.TxRetries
fields["usage"] = s.Usage
tags["wlanconf_id"] = s.WlanconfID
continue
}
}
pt, err := influx.NewPoint("uap_radios", tags, fields, time.Now())