fix lint errors

This commit is contained in:
davidnewhall2 2019-11-25 13:20:45 -08:00
parent 6622050a34
commit 58e49c8b75
7 changed files with 17 additions and 17 deletions

View File

@ -6,12 +6,14 @@ import (
"strings"
)
const callDepth = 2
// LogError logs an error and increments the error counter.
// Should be used in the poller loop.
func (u *UnifiPoller) LogError(err error, prefix string) {
if err != nil {
u.errorCount++
_ = log.Output(2, fmt.Sprintf("[ERROR] %v: %v", prefix, err))
_ = log.Output(callDepth, fmt.Sprintf("[ERROR] %v: %v", prefix, err))
}
}
@ -28,18 +30,18 @@ func StringInSlice(str string, slice []string) bool {
// Logf prints a log entry if quiet is false.
func (u *UnifiPoller) Logf(m string, v ...interface{}) {
if !u.Config.Quiet {
_ = log.Output(2, fmt.Sprintf("[INFO] "+m, v...))
_ = log.Output(callDepth, fmt.Sprintf("[INFO] "+m, v...))
}
}
// LogDebugf prints a debug log entry if debug is true and quite is false
func (u *UnifiPoller) LogDebugf(m string, v ...interface{}) {
if u.Config.Debug && !u.Config.Quiet {
_ = log.Output(2, fmt.Sprintf("[DEBUG] "+m, v...))
_ = log.Output(callDepth, fmt.Sprintf("[DEBUG] "+m, v...))
}
}
// LogErrorf prints an error log entry. This is used for external library logging.
func (u *UnifiPoller) LogErrorf(m string, v ...interface{}) {
_ = log.Output(2, fmt.Sprintf("[ERROR] "+m, v...))
_ = log.Output(callDepth, fmt.Sprintf("[ERROR] "+m, v...))
}

View File

@ -78,8 +78,7 @@ func (u *UnifiPoller) CollectMetrics() (*metrics.Metrics, error) {
m.Sites, err = u.GetFilteredSites()
u.LogError(err, "unifi.GetSites()")
if u.Config.CollectIDS {
// Check back in time since twice the interval. Dups are discarded by InfluxDB.
m.IDSList, err = u.Unifi.GetIDS(m.Sites, time.Now().Add(2*u.Config.Interval.Duration), time.Now())
m.IDSList, err = u.Unifi.GetIDS(m.Sites, time.Now().Add(u.Config.Interval.Duration), time.Now())
u.LogError(err, "unifi.GetIDS()")
}
// Get all the points.

View File

@ -22,7 +22,7 @@ type UnifiCollectorCnfg struct {
// will be collected at all.
ReportErrors bool
// This function is passed to the Collect() method. The Collect method runs
// this function to retreive the latest UniFi measurements and export them.
// this function to retrieve the latest UniFi measurements and export them.
CollectFn func() (*metrics.Metrics, error)
// Provide a logger function if you want to run a routine *after* prometheus checks in.
LoggingFn func(*Report)
@ -98,7 +98,7 @@ func (u *unifiCollector) Describe(ch chan<- *prometheus.Desc) {
describe(u.Site)
}
// Collect satisifes the prometheus Collector. This runs the input method to get
// Collect satisfies the prometheus Collector. This runs the input method to get
// the current metrics (from another package) then exports them for prometheus.
func (u *unifiCollector) Collect(ch chan<- prometheus.Metric) {
var err error

View File

@ -67,17 +67,16 @@ func descSite(ns string) *site {
}
}
func (u *unifiCollector) exportSites(sites unifi.Sites, ch chan []*metricExports) (e []*metricExports) {
func (u *unifiCollector) exportSites(sites unifi.Sites, ch chan []*metricExports) {
for _, s := range sites {
ch <- u.exportSite(s)
}
return
}
// exportSite exports Network Site Data
func (u *unifiCollector) exportSite(s *unifi.Site) []*metricExports {
labels := []string{s.Name, s.Desc, s.SiteName}
var metrics []*metricExports
metrics := []*metricExports{}
for _, h := range s.Health {
l := append([]string{h.Subsystem, h.Status, h.GwVersion}, labels...)

View File

@ -83,7 +83,7 @@ func descUAP(ns string) *uap {
Uptime: prometheus.NewDesc(ns+"uptime", "Uptime", labels, nil),
TotalTxBytes: prometheus.NewDesc(ns+"bytes_tx_total", "Total Transmitted Bytes", labels, nil),
TotalRxBytes: prometheus.NewDesc(ns+"bytes_rx_total", "Total Received Bytes", labels, nil),
TotalBytes: prometheus.NewDesc(ns+"bytes_total", "Total Bytes Transfered", labels, nil),
TotalBytes: prometheus.NewDesc(ns+"bytes_total", "Total Bytes Transferred", labels, nil),
BytesD: prometheus.NewDesc(ns+"bytes_d_total", "Total Bytes D???", labels, nil),
TxBytesD: prometheus.NewDesc(ns+"bytes_d_tx", "Transmit Bytes D???", labels, nil),
RxBytesD: prometheus.NewDesc(ns+"bytes_d_rx", "Receive Bytes D???", labels, nil),

View File

@ -66,7 +66,7 @@ func descUSG(ns string) *usg {
Uptime: prometheus.NewDesc(ns+"uptime", "Uptime", labels, nil),
TotalTxBytes: prometheus.NewDesc(ns+"bytes_tx_total", "Total Transmitted Bytes", labels, nil),
TotalRxBytes: prometheus.NewDesc(ns+"bytes_rx_total", "Total Received Bytes", labels, nil),
TotalBytes: prometheus.NewDesc(ns+"bytes_total", "Total Bytes Transfered", labels, nil),
TotalBytes: prometheus.NewDesc(ns+"bytes_total", "Total Bytes Transferred", labels, nil),
NumSta: prometheus.NewDesc(ns+"stations_total", "Number of Stations", labels, nil),
UserNumSta: prometheus.NewDesc(ns+"stations_user_total", "Number of User Stations", labels, nil),
GuestNumSta: prometheus.NewDesc(ns+"stations_guest_total", "Number of Guest Stations", labels, nil),
@ -164,7 +164,7 @@ func (u *unifiCollector) exportUSG(s *unifi.USG) []*metricExports {
}
func (u *unifiCollector) exportWANPorts(labels []string, wans ...unifi.Wan) []*metricExports {
var metrics []*metricExports
metrics := []*metricExports{}
for _, wan := range wans {
if !wan.Up.Val {
continue // only record UP interfaces.

View File

@ -83,7 +83,7 @@ func descUSW(ns string) *usw {
FanLevel: prometheus.NewDesc(ns+"fan_level", "Fan Level", labels, nil),
TotalTxBytes: prometheus.NewDesc(ns+"bytes_tx_total", "Total Transmitted Bytes", labels, nil),
TotalRxBytes: prometheus.NewDesc(ns+"bytes_rx_total", "Total Received Bytes", labels, nil),
TotalBytes: prometheus.NewDesc(ns+"bytes_total", "Total Bytes Transfered", labels, nil),
TotalBytes: prometheus.NewDesc(ns+"bytes_total", "Total Bytes Transferred", labels, nil),
NumSta: prometheus.NewDesc(ns+"stations_total", "Number of Stations", labels, nil),
UserNumSta: prometheus.NewDesc(ns+"stations_user_total", "Number of User Stations", labels, nil),
GuestNumSta: prometheus.NewDesc(ns+"stations_guest_total", "Number of Guest Stations", labels, nil),
@ -111,7 +111,7 @@ func descUSW(ns string) *usw {
SwRxBroadcast: prometheus.NewDesc(ns+"switch_broadcast_rx_total", "Switch Broadcast Receive Total", labels, nil),
SwTxMulticast: prometheus.NewDesc(ns+"switch_multicast_tx_total", "Switch Multicast Transmit Total", labels, nil),
SwTxBroadcast: prometheus.NewDesc(ns+"switch_broadcast_tx_total", "Switch Broadcast Transmit Total", labels, nil),
SwBytes: prometheus.NewDesc(ns+"switch_bytes_total", "Switch Bytes Transfered Total", labels, nil),
SwBytes: prometheus.NewDesc(ns+"switch_bytes_total", "Switch Bytes Transferred Total", labels, nil),
// per-port data
PoeCurrent: prometheus.NewDesc(pns+"poe_current", "POE Current", labelP, nil),
@ -187,7 +187,7 @@ func (u *unifiCollector) exportUSW(s *unifi.USW) []*metricExports {
}
func (u *unifiCollector) exportPortTable(pt []unifi.Port, labels []string) []*metricExports {
var metrics []*metricExports
metrics := []*metricExports{}
// Per-port data on a switch
for _, p := range pt {
// Copy labels, and add four new ones.