From ecd1c64004ca3d0afc8f28b2a32dc32d1c862420 Mon Sep 17 00:00:00 2001 From: davidnewhall2 Date: Tue, 10 Dec 2019 01:19:56 -0800 Subject: [PATCH] Updates --- pkg/influxunifi/uap.go | 7 +++-- pkg/influxunifi/udm.go | 41 +++++++++----------------- pkg/influxunifi/usg.go | 7 +++-- pkg/influxunifi/usw.go | 65 ++++++++++++++++++++++++------------------ pkg/promunifi/uap.go | 3 ++ pkg/promunifi/udm.go | 3 ++ pkg/promunifi/usg.go | 3 ++ pkg/promunifi/usw.go | 3 ++ 8 files changed, 74 insertions(+), 58 deletions(-) diff --git a/pkg/influxunifi/uap.go b/pkg/influxunifi/uap.go index f6f8e8ad..46c25c32 100644 --- a/pkg/influxunifi/uap.go +++ b/pkg/influxunifi/uap.go @@ -7,8 +7,8 @@ import ( // batchUAP generates Wireless-Access-Point datapoints for InfluxDB. // These points can be passed directly to influx. func (u *InfluxUnifi) batchUAP(r report, s *unifi.UAP) { - if s.Stat.Ap == nil { - s.Stat.Ap = &unifi.Ap{} + if !s.Adopted.Val || s.Locating.Val { + return } tags := map[string]string{ "mac": s.Mac, @@ -36,6 +36,9 @@ func (u *InfluxUnifi) batchUAP(r report, s *unifi.UAP) { } func (u *InfluxUnifi) processUAPstats(ap *unifi.Ap) map[string]interface{} { + if ap == nil { + return map[string]interface{}{} + } // Accumulative Statistics. return map[string]interface{}{ "stat_user-rx_packets": ap.UserRxPackets.Val, diff --git a/pkg/influxunifi/udm.go b/pkg/influxunifi/udm.go index 2e93ce8e..af42e5d0 100644 --- a/pkg/influxunifi/udm.go +++ b/pkg/influxunifi/udm.go @@ -33,11 +33,8 @@ func (u *InfluxUnifi) batchSysStats(s unifi.SysStats, ss unifi.SystemStats) map[ // batchUDM generates Unifi Gateway datapoints for InfluxDB. // These points can be passed directly to influx. func (u *InfluxUnifi) batchUDM(r report, s *unifi.UDM) { - if s.Stat.Sw == nil { - s.Stat.Sw = &unifi.Sw{} - } - if s.Stat.Gw == nil { - s.Stat.Gw = &unifi.Gw{} + if !s.Adopted.Val || s.Locating.Val { + return } tags := map[string]string{ "mac": s.Mac, @@ -81,28 +78,18 @@ func (u *InfluxUnifi) batchUDM(r report, s *unifi.UDM) { "serial": s.Serial, "type": s.Type, } - fields = map[string]interface{}{ - "guest-num_sta": s.GuestNumSta.Val, - "ip": s.IP, - "bytes": s.Bytes.Val, - "last_seen": s.LastSeen.Val, - "rx_bytes": s.RxBytes.Val, - "tx_bytes": s.TxBytes.Val, - "uptime": s.Uptime.Val, - "state": s.State.Val, - "stat_bytes": s.Stat.Sw.Bytes.Val, - "stat_rx_bytes": s.Stat.Sw.RxBytes.Val, - "stat_rx_crypts": s.Stat.Sw.RxCrypts.Val, - "stat_rx_dropped": s.Stat.Sw.RxDropped.Val, - "stat_rx_errors": s.Stat.Sw.RxErrors.Val, - "stat_rx_frags": s.Stat.Sw.RxFrags.Val, - "stat_rx_packets": s.Stat.Sw.TxPackets.Val, - "stat_tx_bytes": s.Stat.Sw.TxBytes.Val, - "stat_tx_dropped": s.Stat.Sw.TxDropped.Val, - "stat_tx_errors": s.Stat.Sw.TxErrors.Val, - "stat_tx_packets": s.Stat.Sw.TxPackets.Val, - "stat_tx_retries": s.Stat.Sw.TxRetries.Val, - } + fields = Combine( + u.batchUSWstat(s.Stat.Sw), + map[string]interface{}{ + "guest-num_sta": s.GuestNumSta.Val, + "ip": s.IP, + "bytes": s.Bytes.Val, + "last_seen": s.LastSeen.Val, + "rx_bytes": s.RxBytes.Val, + "tx_bytes": s.TxBytes.Val, + "uptime": s.Uptime.Val, + "state": s.State.Val, + }) r.send(&metric{Table: "usw", Tags: tags, Fields: fields}) u.batchPortTable(r, tags, s.PortTable) diff --git a/pkg/influxunifi/usg.go b/pkg/influxunifi/usg.go index 0993be1a..221e0e40 100644 --- a/pkg/influxunifi/usg.go +++ b/pkg/influxunifi/usg.go @@ -7,8 +7,8 @@ import ( // batchUSG generates Unifi Gateway datapoints for InfluxDB. // These points can be passed directly to influx. func (u *InfluxUnifi) batchUSG(r report, s *unifi.USG) { - if s.Stat.Gw == nil { - s.Stat.Gw = &unifi.Gw{} + if !s.Adopted.Val || s.Locating.Val { + return } tags := map[string]string{ "mac": s.Mac, @@ -74,6 +74,9 @@ func (u *InfluxUnifi) batchUSG(r report, s *unifi.USG) { */ } func (u *InfluxUnifi) batchUSGstat(ss unifi.SpeedtestStatus, gw *unifi.Gw, ul unifi.Uplink) map[string]interface{} { + if gw == nil { + return map[string]interface{}{} + } return map[string]interface{}{ "uplink_latency": ul.Latency.Val, "uplink_speed": ul.Speed.Val, diff --git a/pkg/influxunifi/usw.go b/pkg/influxunifi/usw.go index a62f5f81..7bc31c37 100644 --- a/pkg/influxunifi/usw.go +++ b/pkg/influxunifi/usw.go @@ -7,9 +7,10 @@ import ( // batchUSW generates Unifi Switch datapoints for InfluxDB. // These points can be passed directly to influx. func (u *InfluxUnifi) batchUSW(r report, s *unifi.USW) { - if s.Stat.Sw == nil { - s.Stat.Sw = &unifi.Sw{} + if !s.Adopted.Val || s.Locating.Val { + return } + tags := map[string]string{ "mac": s.Mac, "site_name": s.SiteName, @@ -19,35 +20,45 @@ func (u *InfluxUnifi) batchUSW(r report, s *unifi.USW) { "serial": s.Serial, "type": s.Type, } - fields := Combine(map[string]interface{}{ - "guest-num_sta": s.GuestNumSta.Val, - "ip": s.IP, - "bytes": s.Bytes.Val, - "fan_level": s.FanLevel.Val, - "general_temperature": s.GeneralTemperature.Val, - "last_seen": s.LastSeen.Val, - "rx_bytes": s.RxBytes.Val, - "tx_bytes": s.TxBytes.Val, - "uptime": s.Uptime.Val, - "state": s.State.Val, - "user-num_sta": s.UserNumSta.Val, - "stat_bytes": s.Stat.Sw.Bytes.Val, - "stat_rx_bytes": s.Stat.Sw.RxBytes.Val, - "stat_rx_crypts": s.Stat.Sw.RxCrypts.Val, - "stat_rx_dropped": s.Stat.Sw.RxDropped.Val, - "stat_rx_errors": s.Stat.Sw.RxErrors.Val, - "stat_rx_frags": s.Stat.Sw.RxFrags.Val, - "stat_rx_packets": s.Stat.Sw.TxPackets.Val, - "stat_tx_bytes": s.Stat.Sw.TxBytes.Val, - "stat_tx_dropped": s.Stat.Sw.TxDropped.Val, - "stat_tx_errors": s.Stat.Sw.TxErrors.Val, - "stat_tx_packets": s.Stat.Sw.TxPackets.Val, - "stat_tx_retries": s.Stat.Sw.TxRetries.Val, - }, u.batchSysStats(s.SysStats, s.SystemStats)) + fields := Combine( + u.batchUSWstat(s.Stat.Sw), + u.batchSysStats(s.SysStats, s.SystemStats), + map[string]interface{}{ + "guest-num_sta": s.GuestNumSta.Val, + "ip": s.IP, + "bytes": s.Bytes.Val, + "fan_level": s.FanLevel.Val, + "general_temperature": s.GeneralTemperature.Val, + "last_seen": s.LastSeen.Val, + "rx_bytes": s.RxBytes.Val, + "tx_bytes": s.TxBytes.Val, + "uptime": s.Uptime.Val, + "state": s.State.Val, + "user-num_sta": s.UserNumSta.Val, + }) r.send(&metric{Table: "usw", Tags: tags, Fields: fields}) u.batchPortTable(r, tags, s.PortTable) } +func (u *InfluxUnifi) batchUSWstat(sw *unifi.Sw) map[string]interface{} { + if sw == nil { + return map[string]interface{}{} + } + return map[string]interface{}{ + "stat_bytes": sw.Bytes.Val, + "stat_rx_bytes": sw.RxBytes.Val, + "stat_rx_crypts": sw.RxCrypts.Val, + "stat_rx_dropped": sw.RxDropped.Val, + "stat_rx_errors": sw.RxErrors.Val, + "stat_rx_frags": sw.RxFrags.Val, + "stat_rx_packets": sw.TxPackets.Val, + "stat_tx_bytes": sw.TxBytes.Val, + "stat_tx_dropped": sw.TxDropped.Val, + "stat_tx_errors": sw.TxErrors.Val, + "stat_tx_packets": sw.TxPackets.Val, + "stat_tx_retries": sw.TxRetries.Val, + } +} func (u *InfluxUnifi) batchPortTable(r report, t map[string]string, pt []unifi.Port) { for _, p := range pt { if !p.Up.Val || !p.Enable.Val { diff --git a/pkg/promunifi/uap.go b/pkg/promunifi/uap.go index 658162d3..9998df30 100644 --- a/pkg/promunifi/uap.go +++ b/pkg/promunifi/uap.go @@ -159,6 +159,9 @@ func descUAP(ns string) *uap { } func (u *promUnifi) exportUAP(r report, d *unifi.UAP) { + if !d.Adopted.Val || d.Locating.Val { + return + } labels := []string{d.Type, d.SiteName, d.Name} infoLabels := []string{d.Version, d.Model, d.Serial, d.Mac, d.IP, d.ID, d.Bytes.Txt, d.Uptime.Txt} u.exportUAPstats(r, labels, d.Stat.Ap, d.BytesD, d.TxBytesD, d.RxBytesD, d.BytesR) diff --git a/pkg/promunifi/udm.go b/pkg/promunifi/udm.go index 83f27526..3ce95117 100644 --- a/pkg/promunifi/udm.go +++ b/pkg/promunifi/udm.go @@ -60,6 +60,9 @@ func descDevice(ns string) *unifiDevice { // UDM is a collection of stats from USG, USW and UAP. It has no unique stats. func (u *promUnifi) exportUDM(r report, d *unifi.UDM) { + if !d.Adopted.Val || d.Locating.Val { + return + } labels := []string{d.Type, d.SiteName, d.Name} infoLabels := []string{d.Version, d.Model, d.Serial, d.Mac, d.IP, d.ID, d.Bytes.Txt, d.Uptime.Txt} // Shared data (all devices do this). diff --git a/pkg/promunifi/usg.go b/pkg/promunifi/usg.go index b4005b1c..94a43f80 100644 --- a/pkg/promunifi/usg.go +++ b/pkg/promunifi/usg.go @@ -69,6 +69,9 @@ func descUSG(ns string) *usg { } func (u *promUnifi) exportUSG(r report, d *unifi.USG) { + if !d.Adopted.Val || d.Locating.Val { + return + } labels := []string{d.Type, d.SiteName, d.Name} infoLabels := []string{d.Version, d.Model, d.Serial, d.Mac, d.IP, d.ID, d.Bytes.Txt, d.Uptime.Txt} // Gateway System Data. diff --git a/pkg/promunifi/usw.go b/pkg/promunifi/usw.go index b77821d1..fd089ea7 100644 --- a/pkg/promunifi/usw.go +++ b/pkg/promunifi/usw.go @@ -91,6 +91,9 @@ func descUSW(ns string) *usw { } func (u *promUnifi) exportUSW(r report, d *unifi.USW) { + if !d.Adopted.Val || d.Locating.Val { + return + } labels := []string{d.Type, d.SiteName, d.Name} infoLabels := []string{d.Version, d.Model, d.Serial, d.Mac, d.IP, d.ID, d.Bytes.Txt, d.Uptime.Txt} u.exportUSWstats(r, labels, d.Stat.Sw)