From 16fcd2300c6967fd4bf08a9d53ba912e529bc8a6 Mon Sep 17 00:00:00 2001 From: David Newhall II Date: Sun, 14 Mar 2021 17:45:29 -0700 Subject: [PATCH] add uzg file --- integrations/influxunifi/uxg.go | 79 +++++++++++++++++++++++++++++++++ 1 file changed, 79 insertions(+) create mode 100644 integrations/influxunifi/uxg.go diff --git a/integrations/influxunifi/uxg.go b/integrations/influxunifi/uxg.go new file mode 100644 index 00000000..208ad2a6 --- /dev/null +++ b/integrations/influxunifi/uxg.go @@ -0,0 +1,79 @@ +package influxunifi + +import ( + "github.com/unifi-poller/unifi" +) + +// uxgT is used as a name for printed/logged counters. +const uxgT = item("UXG") + +// batchUXG generates 10Gb Unifi Gateway datapoints for InfluxDB. +// These points can be passed directly to influx. +func (u *InfluxUnifi) batchUXG(r report, s *unifi.UXG) { // nolint: funlen + if !s.Adopted.Val || s.Locating.Val { + return + } + + tags := map[string]string{ + "source": s.SourceName, + "mac": s.Mac, + "site_name": s.SiteName, + "name": s.Name, + "version": s.Version, + "model": s.Model, + "serial": s.Serial, + "type": s.Type, + } + fields := Combine( + u.batchUDMtemps(s.Temperatures), + u.batchUSGstats(s.SpeedtestStatus, s.Stat.Gw, s.Uplink), + u.batchSysStats(s.SysStats, s.SystemStats), + map[string]interface{}{ + "source": s.SourceName, + "ip": s.IP, + "bytes": s.Bytes.Val, + "last_seen": s.LastSeen.Val, + "license_state": s.LicenseState, + "guest-num_sta": s.GuestNumSta.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, + "version": s.Version, + "num_desktop": s.NumDesktop.Val, + "num_handheld": s.NumHandheld.Val, + "num_mobile": s.NumMobile.Val, + }, + ) + + r.addCount(uxgT) + r.send(&metric{Table: "usg", Tags: tags, Fields: fields}) + u.batchNetTable(r, tags, s.NetworkTable) + u.batchUSGwans(r, tags, s.Wan1, s.Wan2) + + tags = map[string]string{ + "mac": s.Mac, + "site_name": s.SiteName, + "source": s.SourceName, + "name": s.Name, + "version": s.Version, + "model": s.Model, + "serial": s.Serial, + "type": s.Type, + } + 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, + }) + + r.send(&metric{Table: "usw", Tags: tags, Fields: fields}) + u.batchPortTable(r, tags, s.PortTable) // udm has a usw in it. +}