From bd10066545cb1b92f32c25ccb6ccd1117af26b36 Mon Sep 17 00:00:00 2001 From: David Newhall II Date: Sun, 14 Mar 2021 17:27:03 -0700 Subject: [PATCH] add dead ports and sfp data --- integrations/influxunifi/go.mod | 2 +- integrations/influxunifi/influxdb.go | 6 ++-- integrations/influxunifi/usw.go | 42 ++++++++++++++++++---------- 3 files changed, 33 insertions(+), 17 deletions(-) diff --git a/integrations/influxunifi/go.mod b/integrations/influxunifi/go.mod index 01347c22..3cadad42 100644 --- a/integrations/influxunifi/go.mod +++ b/integrations/influxunifi/go.mod @@ -5,7 +5,7 @@ go 1.15 require ( github.com/influxdata/influxdb1-client v0.0.0-20200515024757-02f0bf5dbca3 github.com/unifi-poller/poller v0.0.8 - github.com/unifi-poller/unifi v0.0.7-0.20210308061543-395de2119e12 + github.com/unifi-poller/unifi v0.0.7-0.20210315000917-22c6030f9df5 github.com/unifi-poller/webserver v0.0.0-20200628212441-340749c94743 golift.io/cnfg v0.0.7 ) diff --git a/integrations/influxunifi/influxdb.go b/integrations/influxunifi/influxdb.go index 720ee9e1..f0cb7a45 100644 --- a/integrations/influxunifi/influxdb.go +++ b/integrations/influxunifi/influxdb.go @@ -32,12 +32,14 @@ const ( // Config defines the data needed to store metrics in InfluxDB. type Config struct { Interval cnfg.Duration `json:"interval,omitempty" toml:"interval,omitempty" xml:"interval" yaml:"interval"` - Disable bool `json:"disable" toml:"disable" xml:"disable,attr" yaml:"disable"` - VerifySSL bool `json:"verify_ssl" toml:"verify_ssl" xml:"verify_ssl" yaml:"verify_ssl"` URL string `json:"url,omitempty" toml:"url,omitempty" xml:"url" yaml:"url"` User string `json:"user,omitempty" toml:"user,omitempty" xml:"user" yaml:"user"` Pass string `json:"pass,omitempty" toml:"pass,omitempty" xml:"pass" yaml:"pass"` DB string `json:"db,omitempty" toml:"db,omitempty" xml:"db" yaml:"db"` + Disable bool `json:"disable" toml:"disable" xml:"disable,attr" yaml:"disable"` + VerifySSL bool `json:"verify_ssl" toml:"verify_ssl" xml:"verify_ssl" yaml:"verify_ssl"` + // Save data for dead ports? ie. ports that are down or disabled. + DeadPorts bool `json:"dead_ports" toml:"dead_ports" xml:"dead_ports" yaml:"dead_ports"` } // InfluxDB allows the data to be nested in the config file. diff --git a/integrations/influxunifi/usw.go b/integrations/influxunifi/usw.go index 5f3ed9cf..a651e94f 100644 --- a/integrations/influxunifi/usw.go +++ b/integrations/influxunifi/usw.go @@ -67,26 +67,32 @@ func (u *InfluxUnifi) batchUSWstat(sw *unifi.Sw) map[string]interface{} { } } +//nolint:funlen func (u *InfluxUnifi) batchPortTable(r report, t map[string]string, pt []unifi.Port) { for _, p := range pt { - if !p.Up.Val || !p.Enable.Val { + if !u.DeadPorts && (!p.Up.Val || !p.Enable.Val) { continue // only record UP ports. } tags := map[string]string{ - "site_name": t["site_name"], - "device_name": t["name"], - "source": t["source"], - "type": t["type"], - "name": p.Name, - "poe_mode": p.PoeMode, - "port_poe": p.PortPoe.Txt, - "port_idx": p.PortIdx.Txt, - "port_id": t["name"] + " Port " + p.PortIdx.Txt, - "poe_enable": p.PoeEnable.Txt, - "flowctrl_rx": p.FlowctrlRx.Txt, - "flowctrl_tx": p.FlowctrlTx.Txt, - "media": p.Media, + "site_name": t["site_name"], + "device_name": t["name"], + "source": t["source"], + "type": t["type"], + "name": p.Name, + "poe_mode": p.PoeMode, + "port_poe": p.PortPoe.Txt, + "port_idx": p.PortIdx.Txt, + "port_id": t["name"] + " Port " + p.PortIdx.Txt, + "poe_enable": p.PoeEnable.Txt, + "flowctrl_rx": p.FlowctrlRx.Txt, + "flowctrl_tx": p.FlowctrlTx.Txt, + "media": p.Media, + "has_sfp": p.SFPFound.Txt, + "sfp_compliance": p.SFPCompliance, + "sfp_serial": p.SFPSerial, + "sfp_vendor": p.SFPVendor, + "sfp_part": p.SFPPart, } fields := map[string]interface{}{ "dbytes_r": p.BytesR.Val, @@ -114,6 +120,14 @@ func (u *InfluxUnifi) batchPortTable(r report, t map[string]string, pt []unifi.P fields["poe_voltage"] = p.PoeVoltage.Val } + if p.SFPFound.Val { + fields["sfp_current"] = p.SFPCurrent.Val + fields["sfp_voltage"] = p.SFPVoltage.Val + fields["sfp_temperature"] = p.SFPTemperature.Val + fields["sfp_txpower"] = p.SFPTxpower.Val + fields["sfp_rxpower"] = p.SFPRxpower.Val + } + r.send(&metric{Table: "usw_ports", Tags: tags, Fields: fields}) } }