fix lint errors
This commit is contained in:
parent
fad5b93717
commit
0f0398d7a7
|
|
@ -15,7 +15,6 @@ import (
|
|||
"encoding/pem"
|
||||
"fmt"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
"net/http/cookiejar"
|
||||
"net/url"
|
||||
|
|
@ -130,7 +129,7 @@ func (u *Unifi) Login() error {
|
|||
}
|
||||
|
||||
defer resp.Body.Close() // we need no data here.
|
||||
_, _ = io.Copy(ioutil.Discard, resp.Body) // avoid leaking.
|
||||
_, _ = io.Copy(io.Discard, resp.Body) // avoid leaking.
|
||||
u.DebugLog("Requested %s: elapsed %v, returned %d bytes",
|
||||
req.URL, time.Since(start).Round(time.Millisecond), resp.ContentLength)
|
||||
|
||||
|
|
@ -188,7 +187,7 @@ func (u *Unifi) checkNewStyleAPI() error {
|
|||
}
|
||||
|
||||
defer resp.Body.Close() // we need no data here.
|
||||
_, _ = io.Copy(ioutil.Discard, resp.Body) // avoid leaking.
|
||||
_, _ = io.Copy(io.Discard, resp.Body) // avoid leaking.
|
||||
|
||||
if resp.StatusCode == http.StatusOK {
|
||||
// The new version returns a "200" for a / request.
|
||||
|
|
@ -350,7 +349,7 @@ func (u *Unifi) do(req *http.Request) ([]byte, error) {
|
|||
|
||||
defer resp.Body.Close()
|
||||
|
||||
body, err := ioutil.ReadAll(resp.Body)
|
||||
body, err := io.ReadAll(resp.Body)
|
||||
if err != nil {
|
||||
return body, fmt.Errorf("reading response: %w", err)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
package unifi // nolint: testpackage
|
||||
|
||||
import (
|
||||
"io/ioutil"
|
||||
"io"
|
||||
"net/http"
|
||||
"runtime"
|
||||
"testing"
|
||||
|
|
@ -60,7 +60,7 @@ func TestUniReq(t *testing.T) {
|
|||
a.EqualValues("application/json", r.Header.Get("Accept"), "Accept header must be set to application/json")
|
||||
|
||||
// Check the parameters.
|
||||
d, err := ioutil.ReadAll(r.Body)
|
||||
d, err := io.ReadAll(r.Body)
|
||||
a.Nil(err, "problem reading request body, POST parameters may be malformed")
|
||||
a.EqualValues(k, string(d), "POST parameters improperly encoded")
|
||||
}
|
||||
|
|
@ -89,7 +89,7 @@ func TestUniReqPut(t *testing.T) {
|
|||
a.EqualValues("application/json", r.Header.Get("Accept"), "Accept header must be set to application/json")
|
||||
|
||||
// Check the parameters.
|
||||
d, err := ioutil.ReadAll(r.Body)
|
||||
d, err := io.ReadAll(r.Body)
|
||||
a.Nil(err, "problem reading request body, PUT parameters may be malformed")
|
||||
a.EqualValues(k, string(d), "PUT parameters improperly encoded")
|
||||
}
|
||||
|
|
|
|||
|
|
@ -62,7 +62,7 @@ func (u *DatadogUnifi) batchAlarms(r report, event *unifi.Alarm) { // nolint:dup
|
|||
tagMap = cleanTags(tagMap)
|
||||
tags := tagMapToTags(tagMap)
|
||||
title := fmt.Sprintf("[%s][%s] Alarm at %s from %s", event.EventType, event.Catname, event.SiteName, event.SourceName)
|
||||
r.reportEvent(title, event.Datetime, event.Msg, tags)
|
||||
_ = r.reportEvent(title, event.Datetime, event.Msg, tags)
|
||||
r.reportWarnLog(fmt.Sprintf("[%d] %s: %s - %s", event.Datetime.Unix(), title, event.Msg, tagMapToSimpleStrings(tagMap)))
|
||||
}
|
||||
|
||||
|
|
@ -83,6 +83,6 @@ func (u *DatadogUnifi) batchAnomaly(r report, event *unifi.Anomaly) {
|
|||
tags := tagMapToTags(tagMap)
|
||||
|
||||
title := fmt.Sprintf("Anomaly detected at %s from %s", event.SiteName, event.SourceName)
|
||||
r.reportEvent(title, event.Datetime, event.Anomaly, tags)
|
||||
_ = r.reportEvent(title, event.Datetime, event.Anomaly, tags)
|
||||
r.reportWarnLog(fmt.Sprintf("[%d] %s: %s - %s", event.Datetime.Unix(), title, event.Anomaly, tagMapToSimpleStrings(tagMap)))
|
||||
}
|
||||
|
|
|
|||
|
|
@ -191,7 +191,7 @@ func (u *DatadogUnifi) setConfigDefaults() {
|
|||
// Run runs a ticker to poll the unifi server and update Datadog.
|
||||
func (u *DatadogUnifi) Run(c poller.Collect) error {
|
||||
u.Collector = c
|
||||
disabled := u.Disable == nil || *u.Disable == true
|
||||
disabled := u.Disable == nil || *u.Disable
|
||||
if disabled {
|
||||
u.LogDebugf("Datadog config is disabled, output is disabled.")
|
||||
return nil
|
||||
|
|
@ -239,10 +239,10 @@ func (u *DatadogUnifi) PollController() {
|
|||
if err != nil {
|
||||
// Is the agent down?
|
||||
u.LogErrorf("unable to report metrics and events", err)
|
||||
report.reportCount("unifi.collect.errors", 1, []string{})
|
||||
_ = report.reportCount("unifi.collect.errors", 1, []string{})
|
||||
continue
|
||||
}
|
||||
report.reportCount("unifi.collect.success", 1, []string{})
|
||||
_ = report.reportCount("unifi.collect.success", 1, []string{})
|
||||
u.LogDatadogReport(report)
|
||||
}
|
||||
}
|
||||
|
|
@ -263,7 +263,7 @@ func (u *DatadogUnifi) ReportMetrics(m *poller.Metrics, e *poller.Events) (*Repo
|
|||
u.loopPoints(r)
|
||||
r.End = time.Now()
|
||||
r.Elapsed = r.End.Sub(r.Start)
|
||||
r.reportTiming("unifi.collector_timing", r.Elapsed, []string{})
|
||||
_ = r.reportTiming("unifi.collector_timing", r.Elapsed, []string{})
|
||||
return r, nil
|
||||
}
|
||||
|
||||
|
|
@ -350,12 +350,12 @@ func (u *DatadogUnifi) LogDatadogReport(r *Report) {
|
|||
r.Elapsed,
|
||||
)
|
||||
metricName := metricNamespace("collector")
|
||||
r.reportCount(metricName("num_sites"), int64(len(m.Sites)), u.Tags)
|
||||
r.reportCount(metricName("num_sites_dpi"), int64(len(m.SitesDPI)), u.Tags)
|
||||
r.reportCount(metricName("num_clients"), int64(len(m.Clients)), u.Tags)
|
||||
r.reportCount(metricName("num_clients_dpi"), int64(len(m.ClientsDPI)), u.Tags)
|
||||
r.reportCount(metricName("num_rogue_ap"), int64(len(m.RogueAPs)), u.Tags)
|
||||
r.reportCount(metricName("num_devices"), int64(len(m.Devices)), u.Tags)
|
||||
r.reportCount(metricName("num_errors"), int64(len(r.Errors)), u.Tags)
|
||||
r.reportTiming(metricName("elapsed_time"), r.Elapsed, u.Tags)
|
||||
_ = r.reportCount(metricName("num_sites"), int64(len(m.Sites)), u.Tags)
|
||||
_ = r.reportCount(metricName("num_sites_dpi"), int64(len(m.SitesDPI)), u.Tags)
|
||||
_ = r.reportCount(metricName("num_clients"), int64(len(m.Clients)), u.Tags)
|
||||
_ = r.reportCount(metricName("num_clients_dpi"), int64(len(m.ClientsDPI)), u.Tags)
|
||||
_ = r.reportCount(metricName("num_rogue_ap"), int64(len(m.RogueAPs)), u.Tags)
|
||||
_ = r.reportCount(metricName("num_devices"), int64(len(m.Devices)), u.Tags)
|
||||
_ = r.reportCount(metricName("num_errors"), int64(len(r.Errors)), u.Tags)
|
||||
_ = r.reportTiming(metricName("elapsed_time"), r.Elapsed, u.Tags)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -64,7 +64,7 @@ func (u *DatadogUnifi) batchIDS(r report, i *unifi.IDS) { // nolint:dupl
|
|||
tagMap = cleanTags(tagMap)
|
||||
tags := tagMapToTags(tagMap)
|
||||
title := fmt.Sprintf("Intrusion Detection at %s from %s", i.SiteName, i.SourceName)
|
||||
r.reportEvent(title, i.Datetime, i.Msg, tags)
|
||||
_ = r.reportEvent(title, i.Datetime, i.Msg, tags)
|
||||
r.reportWarnLog(fmt.Sprintf("[%d] %s: %s - %s", i.Datetime.Unix(), title, i.Msg, tagMapToSimpleStrings(tagMap)))
|
||||
}
|
||||
|
||||
|
|
@ -138,6 +138,6 @@ func (u *DatadogUnifi) batchEvent(r report, i *unifi.Event) { // nolint: funlen
|
|||
tagMap = cleanTags(tagMap)
|
||||
tags := tagMapToTags(tagMap)
|
||||
title := fmt.Sprintf("Unifi Event at %s from %s", i.SiteName, i.SourceName)
|
||||
r.reportEvent(title, i.Datetime, i.Msg, tags)
|
||||
_ = r.reportEvent(title, i.Datetime, i.Msg, tags)
|
||||
r.reportInfoLog(fmt.Sprintf("[%d] %s: %s - %s", i.Datetime.Unix(), title, i.Msg, tagMapToSimpleStrings(tagMap)))
|
||||
}
|
||||
|
|
|
|||
|
|
@ -33,7 +33,7 @@ func metricNamespace(namespace string) func(string) string {
|
|||
|
||||
func reportGaugeForFloat64Map(r report, metricName func(string) string, data map[string]float64, tags map[string]string) {
|
||||
for name, value := range data {
|
||||
r.reportGauge(metricName(name), value, tagMapToTags(tags))
|
||||
_ = r.reportGauge(metricName(name), value, tagMapToTags(tags))
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -56,7 +56,7 @@ func (u *DatadogUnifi) reportSite(r report, s *unifi.Site) {
|
|||
}
|
||||
|
||||
for name, value := range data {
|
||||
r.reportGauge(metricName(name), value, tags)
|
||||
_ = r.reportGauge(metricName(name), value, tags)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -72,9 +72,9 @@ func (u *DatadogUnifi) reportSiteDPI(r report, s *unifi.DPITable) {
|
|||
tag("source", s.SourceName),
|
||||
}
|
||||
|
||||
r.reportCount(metricName("tx_packets"), dpi.TxPackets, tags)
|
||||
r.reportCount(metricName("rx_packets"), dpi.RxPackets, tags)
|
||||
r.reportCount(metricName("tx_bytes"), dpi.TxBytes, tags)
|
||||
r.reportCount(metricName("rx_bytes"), dpi.RxBytes, tags)
|
||||
_ = r.reportCount(metricName("tx_packets"), dpi.TxPackets, tags)
|
||||
_ = r.reportCount(metricName("rx_packets"), dpi.RxPackets, tags)
|
||||
_ = r.reportCount(metricName("tx_bytes"), dpi.TxBytes, tags)
|
||||
_ = r.reportCount(metricName("rx_bytes"), dpi.RxBytes, tags)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,8 +5,8 @@ package influxunifi
|
|||
import (
|
||||
"crypto/tls"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"log"
|
||||
"os"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
|
|
@ -165,7 +165,7 @@ func (u *InfluxUnifi) setConfigDefaults() {
|
|||
}
|
||||
|
||||
func (u *InfluxUnifi) getPassFromFile(filename string) string {
|
||||
b, err := ioutil.ReadFile(filename)
|
||||
b, err := os.ReadFile(filename)
|
||||
if err != nil {
|
||||
u.LogErrorf("Reading InfluxDB Password File: %v", err)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ package inputunifi
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
|
|
@ -93,7 +93,7 @@ func (c *Controller) getCerts() ([][]byte, error) {
|
|||
b := make([][]byte, len(c.CertPaths))
|
||||
|
||||
for i, f := range c.CertPaths {
|
||||
d, err := ioutil.ReadFile(f)
|
||||
d, err := os.ReadFile(f)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("reading SSL cert file: %w", err)
|
||||
}
|
||||
|
|
@ -189,7 +189,7 @@ FIRST:
|
|||
}
|
||||
|
||||
func (u *InputUnifi) getPassFromFile(filename string) string {
|
||||
b, err := ioutil.ReadFile(filename)
|
||||
b, err := os.ReadFile(filename)
|
||||
if err != nil {
|
||||
u.LogErrorf("Reading UniFi Password File: %v", err)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ import (
|
|||
"crypto/tls"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"io"
|
||||
"net/http"
|
||||
"strings"
|
||||
)
|
||||
|
|
@ -92,7 +92,7 @@ func (c *Client) Do(req *http.Request) (int, []byte, error) {
|
|||
}
|
||||
defer resp.Body.Close()
|
||||
|
||||
body, err := ioutil.ReadAll(resp.Body)
|
||||
body, err := io.ReadAll(resp.Body)
|
||||
if err != nil {
|
||||
return resp.StatusCode, body, fmt.Errorf("reading body: %w", err)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@ package lokiunifi
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
|
|
@ -90,7 +90,7 @@ func (l *Loki) ValidateConfig() {
|
|||
}
|
||||
|
||||
if strings.HasPrefix(l.Password, "file://") {
|
||||
pass, err := ioutil.ReadFile(strings.TrimPrefix(l.Password, "file://"))
|
||||
pass, err := os.ReadFile(strings.TrimPrefix(l.Password, "file://"))
|
||||
if err != nil {
|
||||
l.LogErrorf("Reading Loki Password File: %v", err)
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue