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