diff --git a/core/unifi/README.md b/core/unifi/README.md index ccb1614e..1c430930 100644 --- a/core/unifi/README.md +++ b/core/unifi/README.md @@ -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) } diff --git a/core/unifi/clients.go b/core/unifi/clients.go index 7e94b465..2b98ece8 100644 --- a/core/unifi/clients.go +++ b/core/unifi/clients.go @@ -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 != "" { diff --git a/core/unifi/uap.go b/core/unifi/uap.go index 6114c861..a35db906 100644 --- a/core/unifi/uap.go +++ b/core/unifi/uap.go @@ -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())