add dead ports and sfp data

This commit is contained in:
David Newhall II 2021-03-14 17:27:03 -07:00
parent a77d5ab566
commit bd10066545
3 changed files with 33 additions and 17 deletions

View File

@ -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
)

View File

@ -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.

View File

@ -67,9 +67,10 @@ 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.
}
@ -87,6 +88,11 @@ func (u *InfluxUnifi) batchPortTable(r report, t map[string]string, pt []unifi.P
"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})
}
}