From 6f4384c18dd76efcae25b0a3082187a885f465b2 Mon Sep 17 00:00:00 2001 From: Cody Lee Date: Wed, 3 Dec 2025 11:40:21 -0600 Subject: [PATCH] fix linting --- .github/workflows/build.yml | 2 +- .golangci.yaml | 7 +++++- pkg/datadogunifi/integration_test.go | 2 ++ pkg/influxunifi/influxdb.go | 1 - pkg/influxunifi/integration_test.go | 1 + pkg/influxunifi/report.go | 1 + pkg/inputunifi/collector.go | 1 + pkg/inputunifi/input.go | 37 ++++++++++++++-------------- pkg/lokiunifi/loki.go | 3 ++- pkg/poller/commands.go | 1 + pkg/poller/inputs.go | 3 ++- pkg/promunifi/collector.go | 1 + pkg/promunifi/report.go | 3 ++- pkg/webserver/plugins.go | 2 ++ 14 files changed, 41 insertions(+), 24 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 404c8362..8d669821 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -48,4 +48,4 @@ jobs: uses: golangci/golangci-lint-action@v9 with: # Required: the version of golangci-lint is required and must be specified without patch version: we always use the latest patch version. - version: v2.0 + version: v2.6 diff --git a/.golangci.yaml b/.golangci.yaml index 811529fe..66f74b94 100644 --- a/.golangci.yaml +++ b/.golangci.yaml @@ -5,7 +5,7 @@ linters: - revive - tagalign - testpackage - - wsl + - wsl_v5 exclusions: generated: lax presets: @@ -17,6 +17,11 @@ linters: - third_party$ - builtin$ - examples$ +settings: + wsl_v5: + allow-first-in-block: true + allow-whole-block: false + branch-max-lines: 2 issues: max-issues-per-linter: 0 max-same-issues: 0 diff --git a/pkg/datadogunifi/integration_test.go b/pkg/datadogunifi/integration_test.go index 98031c65..2d9599dc 100644 --- a/pkg/datadogunifi/integration_test.go +++ b/pkg/datadogunifi/integration_test.go @@ -246,6 +246,7 @@ func TestDataDogUnifiIntegration(t *testing.T) { require.NoError(t, err) var testExpectationsData testExpectations + err = yaml.Unmarshal(yamlFile, &testExpectationsData) require.NoError(t, err) @@ -277,6 +278,7 @@ func TestDataDogUnifiIntegration(t *testing.T) { u.Collector = testRig.Collector u.Collect(time.Minute) + mockCapture.RLock() defer mockCapture.RUnlock() diff --git a/pkg/influxunifi/influxdb.go b/pkg/influxunifi/influxdb.go index a34c1b4d..c9da7de9 100644 --- a/pkg/influxunifi/influxdb.go +++ b/pkg/influxunifi/influxdb.go @@ -346,7 +346,6 @@ func (u *InfluxUnifi) ReportMetrics(m *poller.Metrics, e *poller.Events) (*Repor // Make a new Influx Points Batcher. r.bp, err = influxV1.NewBatchPoints(influxV1.BatchPointsConfig{Database: u.DB}) - if err != nil { return nil, fmt.Errorf("influx.NewBatchPoint: %w", err) } diff --git a/pkg/influxunifi/integration_test.go b/pkg/influxunifi/integration_test.go index 873528fd..0a36c844 100644 --- a/pkg/influxunifi/integration_test.go +++ b/pkg/influxunifi/integration_test.go @@ -161,6 +161,7 @@ func TestInfluxV1Integration(t *testing.T) { require.NoError(t, err) var testExpectationsData testExpectations + err = yaml.Unmarshal(yamlFile, &testExpectationsData) require.NoError(t, err) diff --git a/pkg/influxunifi/report.go b/pkg/influxunifi/report.go index b8fcfcbb..c351b65e 100644 --- a/pkg/influxunifi/report.go +++ b/pkg/influxunifi/report.go @@ -63,6 +63,7 @@ func (r *Report) done() { func (r *Report) send(m *metric) { r.wg.Add(1) + r.ch <- m } diff --git a/pkg/inputunifi/collector.go b/pkg/inputunifi/collector.go index 8b74a4fe..f5861744 100644 --- a/pkg/inputunifi/collector.go +++ b/pkg/inputunifi/collector.go @@ -87,6 +87,7 @@ func (u *InputUnifi) collectController(c *Controller) (*poller.Metrics, error) { func (u *InputUnifi) pollController(c *Controller) (*poller.Metrics, error) { u.RLock() defer u.RUnlock() + u.LogDebugf("Polling controller: %s (%s)", c.URL, c.ID) // Get the sites we care about. diff --git a/pkg/inputunifi/input.go b/pkg/inputunifi/input.go index 109fac9c..66096fbf 100644 --- a/pkg/inputunifi/input.go +++ b/pkg/inputunifi/input.go @@ -34,25 +34,25 @@ type InputUnifi struct { // Controller represents the configuration for a UniFi Controller. // Each polled controller may have its own configuration. type Controller struct { - VerifySSL *bool `json:"verify_ssl" toml:"verify_ssl" xml:"verify_ssl" yaml:"verify_ssl"` - SaveAnomal *bool `json:"save_anomalies" toml:"save_anomalies" xml:"save_anomalies" yaml:"save_anomalies"` - SaveAlarms *bool `json:"save_alarms" toml:"save_alarms" xml:"save_alarms" yaml:"save_alarms"` - SaveEvents *bool `json:"save_events" toml:"save_events" xml:"save_events" yaml:"save_events"` - SaveIDs *bool `json:"save_ids" toml:"save_ids" xml:"save_ids" yaml:"save_ids"` - SaveDPI *bool `json:"save_dpi" toml:"save_dpi" xml:"save_dpi" yaml:"save_dpi"` - SaveRogue *bool `json:"save_rogue" toml:"save_rogue" xml:"save_rogue" yaml:"save_rogue"` - HashPII *bool `json:"hash_pii" toml:"hash_pii" xml:"hash_pii" yaml:"hash_pii"` - DropPII *bool `json:"drop_pii" toml:"drop_pii" xml:"drop_pii" yaml:"drop_pii"` - SaveSites *bool `json:"save_sites" toml:"save_sites" xml:"save_sites" yaml:"save_sites"` - CertPaths []string `json:"ssl_cert_paths" toml:"ssl_cert_paths" xml:"ssl_cert_path" yaml:"ssl_cert_paths"` - User string `json:"user" toml:"user" xml:"user" yaml:"user"` - Pass string `json:"pass" toml:"pass" xml:"pass" yaml:"pass"` - APIKey string `json:"api_key" toml:"api_key" xml:"api_key" yaml:"api_key"` - URL string `json:"url" toml:"url" xml:"url" yaml:"url"` - Sites []string `json:"sites" toml:"sites" xml:"site" yaml:"sites"` + VerifySSL *bool `json:"verify_ssl" toml:"verify_ssl" xml:"verify_ssl" yaml:"verify_ssl"` + SaveAnomal *bool `json:"save_anomalies" toml:"save_anomalies" xml:"save_anomalies" yaml:"save_anomalies"` + SaveAlarms *bool `json:"save_alarms" toml:"save_alarms" xml:"save_alarms" yaml:"save_alarms"` + SaveEvents *bool `json:"save_events" toml:"save_events" xml:"save_events" yaml:"save_events"` + SaveIDs *bool `json:"save_ids" toml:"save_ids" xml:"save_ids" yaml:"save_ids"` + SaveDPI *bool `json:"save_dpi" toml:"save_dpi" xml:"save_dpi" yaml:"save_dpi"` + SaveRogue *bool `json:"save_rogue" toml:"save_rogue" xml:"save_rogue" yaml:"save_rogue"` + HashPII *bool `json:"hash_pii" toml:"hash_pii" xml:"hash_pii" yaml:"hash_pii"` + DropPII *bool `json:"drop_pii" toml:"drop_pii" xml:"drop_pii" yaml:"drop_pii"` + SaveSites *bool `json:"save_sites" toml:"save_sites" xml:"save_sites" yaml:"save_sites"` + CertPaths []string `json:"ssl_cert_paths" toml:"ssl_cert_paths" xml:"ssl_cert_path" yaml:"ssl_cert_paths"` + User string `json:"user" toml:"user" xml:"user" yaml:"user"` + Pass string `json:"pass" toml:"pass" xml:"pass" yaml:"pass"` + APIKey string `json:"api_key" toml:"api_key" xml:"api_key" yaml:"api_key"` + URL string `json:"url" toml:"url" xml:"url" yaml:"url"` + Sites []string `json:"sites" toml:"sites" xml:"site" yaml:"sites"` DefaultSiteNameOverride string `json:"default_site_name_override" toml:"default_site_name_override" xml:"default_site_name_override" yaml:"default_site_name_override"` - Unifi *unifi.Unifi `json:"-" toml:"-" xml:"-" yaml:"-"` - ID string `json:"id,omitempty"` // this is an output, not an input. + Unifi *unifi.Unifi `json:"-" toml:"-" xml:"-" yaml:"-"` + ID string `json:"id,omitempty"` // this is an output, not an input. } // Config contains our configuration data. @@ -185,6 +185,7 @@ FIRST: continue FIRST } } + u.LogErrorf("Configured site not found on controller %s: %v", c.URL, s) } diff --git a/pkg/lokiunifi/loki.go b/pkg/lokiunifi/loki.go index b97f2997..dc6c7a0e 100644 --- a/pkg/lokiunifi/loki.go +++ b/pkg/lokiunifi/loki.go @@ -135,7 +135,7 @@ func (l *Loki) ValidateConfig() error { pass, err := os.ReadFile(strings.TrimPrefix(l.Password, "file://")) if err != nil { l.LogErrorf("Reading Loki Password File: %v", err) - + return fmt.Errorf("error reading password file") } @@ -182,6 +182,7 @@ func (l *Loki) ProcessEvents(report *Report, events *poller.Events) error { logs := report.ProcessEventLogs(events) if len(logs.Streams) == 0 { l.LogDebugf("No new events to send to Loki.") + return nil } diff --git a/pkg/poller/commands.go b/pkg/poller/commands.go index 33044812..52a73740 100644 --- a/pkg/poller/commands.go +++ b/pkg/poller/commands.go @@ -58,6 +58,7 @@ func (u *UnifiPoller) PrintPasswordHash() (err error) { func (u *UnifiPoller) DebugIO() error { inputSync.RLock() defer inputSync.RUnlock() + outputSync.RLock() defer outputSync.RUnlock() diff --git a/pkg/poller/inputs.go b/pkg/poller/inputs.go index 3655ff23..d9316695 100644 --- a/pkg/poller/inputs.go +++ b/pkg/poller/inputs.go @@ -81,12 +81,14 @@ func (u *UnifiPoller) InitializeInputs() error { if err := input.Initialize(u); err != nil { u.LogDebugf("error initializing input ... %s", input.Name) + errChan <- err return } u.LogDebugf("input successfully initialized ... %s", input.Name) + errChan <- nil }(input) } @@ -142,7 +144,6 @@ func collectEvents(filter *Filter, inputs []*InputPlugin) (*Events, error) { } e, err := input.Events(filter) - if err != nil { resultChan <- eventInputResult{err: err} diff --git a/pkg/promunifi/collector.go b/pkg/promunifi/collector.go index 3fbebcf6..4bf17a82 100644 --- a/pkg/promunifi/collector.go +++ b/pkg/promunifi/collector.go @@ -323,6 +323,7 @@ func (u *promUnifi) collect(ch chan<- prometheus.Metric, filter *poller.Filter) // Pass Report interface into our collecting and reporting methods. go u.exportMetrics(r, ch, r.ch) + u.loopExports(r) } diff --git a/pkg/promunifi/report.go b/pkg/promunifi/report.go index c31d18f2..cf788e11 100644 --- a/pkg/promunifi/report.go +++ b/pkg/promunifi/report.go @@ -38,6 +38,7 @@ func (r *Report) done() { func (r *Report) send(m []*metric) { r.wg.Add(1) // notlint: gomnd + r.ch <- m } @@ -71,7 +72,7 @@ func (r *Report) error(ch chan<- prometheus.Metric, d *prometheus.Desc, v any) { r.Errors++ if r.ReportErrors { - ch <- prometheus.NewInvalidMetric(d, fmt.Errorf("error: %v", v)) // nolint: goerr113 + ch <- prometheus.NewInvalidMetric(d, fmt.Errorf("error: %v", v)) // nolint } } diff --git a/pkg/webserver/plugins.go b/pkg/webserver/plugins.go index 92398dd1..00c92022 100644 --- a/pkg/webserver/plugins.go +++ b/pkg/webserver/plugins.go @@ -202,12 +202,14 @@ func (w *webPlugins) newOutputEvent(plugin, id string, event *Event) { func (w *webPlugins) newInput(config *Input) { w.Lock() defer w.Unlock() + w.inputs = append(w.inputs, config) } func (w *webPlugins) newOutput(config *Output) { w.Lock() defer w.Unlock() + w.outputs = append(w.outputs, config) }