mirror of
https://github.com/unpoller/unpoller.git
synced 2026-03-31 06:24:19 -04:00
fix linting
This commit is contained in:
2
.github/workflows/build.yml
vendored
2
.github/workflows/build.yml
vendored
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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()
|
||||
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
|
||||
|
||||
@@ -63,6 +63,7 @@ func (r *Report) done() {
|
||||
|
||||
func (r *Report) send(m *metric) {
|
||||
r.wg.Add(1)
|
||||
|
||||
r.ch <- m
|
||||
}
|
||||
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
|
||||
@@ -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()
|
||||
|
||||
|
||||
@@ -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}
|
||||
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
|
||||
|
||||
@@ -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
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user