From 247cc868b32b9f424c24fe55944860e71ac88431 Mon Sep 17 00:00:00 2001 From: Cody Lee Date: Sat, 3 Dec 2022 16:32:12 -0600 Subject: [PATCH] go 1.19 interface{} -> any --- pkg/datadogunifi/clients.go | 2 +- pkg/datadogunifi/datadog.go | 2 +- pkg/datadogunifi/logger.go | 6 +++--- pkg/datadogunifi/points.go | 2 +- pkg/datadogunifi/report.go | 8 ++++---- pkg/datadogunifi/udm.go | 4 ++-- pkg/influxunifi/alarms.go | 4 ++-- pkg/influxunifi/clients.go | 8 ++++---- pkg/influxunifi/events.go | 6 +++--- pkg/influxunifi/influxdb.go | 4 ++-- pkg/influxunifi/logger.go | 6 +++--- pkg/influxunifi/site.go | 6 +++--- pkg/influxunifi/uap.go | 12 ++++++------ pkg/influxunifi/udm.go | 20 ++++++++++---------- pkg/influxunifi/usg.go | 12 ++++++------ pkg/influxunifi/usw.go | 10 +++++----- pkg/influxunifi/uxg.go | 4 ++-- pkg/inputunifi/collectevents.go | 16 ++++++++-------- pkg/inputunifi/interface.go | 2 +- pkg/inputunifi/updateweb.go | 6 +++--- pkg/lokiunifi/client.go | 2 +- pkg/lokiunifi/logger.go | 6 +++--- pkg/poller/README.md | 2 +- pkg/poller/config.go | 16 ++++++++-------- pkg/poller/inputs.go | 2 +- pkg/poller/logger.go | 12 ++++++------ pkg/poller/outputs.go | 2 +- pkg/promunifi/clients.go | 2 +- pkg/promunifi/collector.go | 6 +++--- pkg/promunifi/logger.go | 6 +++--- pkg/promunifi/report.go | 4 ++-- pkg/promunifi/site.go | 2 +- pkg/webserver/handlers.go | 2 +- pkg/webserver/logger.go | 6 +++--- pkg/webserver/plugins_types.go | 28 ++++++++++++++-------------- pkg/webserver/shared.go | 2 +- 36 files changed, 120 insertions(+), 120 deletions(-) diff --git a/pkg/datadogunifi/clients.go b/pkg/datadogunifi/clients.go index 8c2ef504..5766f54d 100644 --- a/pkg/datadogunifi/clients.go +++ b/pkg/datadogunifi/clients.go @@ -80,7 +80,7 @@ func (u *DatadogUnifi) batchClient(r report, s *unifi.Client) { // nolint: funle // totalsDPImap: controller, site, name (app/cat name), dpi. type totalsDPImap map[string]map[string]map[string]unifi.DPIData -func (u *DatadogUnifi) batchClientDPI(r report, v interface{}, appTotal, catTotal totalsDPImap) { +func (u *DatadogUnifi) batchClientDPI(r report, v any, appTotal, catTotal totalsDPImap) { s, ok := v.(*unifi.DPITable) if !ok { u.LogErrorf("invalid type given to batchClientDPI: %T", v) diff --git a/pkg/datadogunifi/datadog.go b/pkg/datadogunifi/datadog.go index 8006f0ca..baa8066c 100644 --- a/pkg/datadogunifi/datadog.go +++ b/pkg/datadogunifi/datadog.go @@ -301,7 +301,7 @@ func (u *DatadogUnifi) loopPoints(r report) { reportClientDPItotals(r, appTotal, catTotal) } -func (u *DatadogUnifi) switchExport(r report, v interface{}) { //nolint:cyclop +func (u *DatadogUnifi) switchExport(r report, v any) { //nolint:cyclop switch v := v.(type) { case *unifi.RogueAP: u.batchRogueAP(r, v) diff --git a/pkg/datadogunifi/logger.go b/pkg/datadogunifi/logger.go index eddf5313..01810adb 100644 --- a/pkg/datadogunifi/logger.go +++ b/pkg/datadogunifi/logger.go @@ -1,21 +1,21 @@ package datadogunifi // Logf logs a message. -func (u *DatadogUnifi) Logf(msg string, v ...interface{}) { +func (u *DatadogUnifi) Logf(msg string, v ...any) { if u.Collector != nil { u.Collector.Logf(msg, v...) } } // LogErrorf logs an error message. -func (u *DatadogUnifi) LogErrorf(msg string, v ...interface{}) { +func (u *DatadogUnifi) LogErrorf(msg string, v ...any) { if u.Collector != nil { u.Collector.LogErrorf(msg, v...) } } // LogDebugf logs a debug message. -func (u *DatadogUnifi) LogDebugf(msg string, v ...interface{}) { +func (u *DatadogUnifi) LogDebugf(msg string, v ...any) { if u.Collector != nil { u.Collector.LogDebugf(msg, v...) } diff --git a/pkg/datadogunifi/points.go b/pkg/datadogunifi/points.go index 60573719..ab5bd8f3 100644 --- a/pkg/datadogunifi/points.go +++ b/pkg/datadogunifi/points.go @@ -5,7 +5,7 @@ import ( "strings" ) -func tag(name string, value interface{}) string { +func tag(name string, value any) string { return fmt.Sprintf("%s:%v", name, value) } diff --git a/pkg/datadogunifi/report.go b/pkg/datadogunifi/report.go index 74e9ef56..d91a2bfe 100644 --- a/pkg/datadogunifi/report.go +++ b/pkg/datadogunifi/report.go @@ -47,8 +47,8 @@ type report interface { reportDistribution(name string, value float64, tags []string) error reportTiming(name string, value time.Duration, tags []string) error reportEvent(title string, date time.Time, message string, tags []string) error - reportInfoLog(message string, f ...interface{}) - reportWarnLog(message string, f ...interface{}) + reportInfoLog(message string, f ...any) + reportWarnLog(message string, f ...any) reportServiceCheck(name string, status statsd.ServiceCheckStatus, message string, tags []string) error } @@ -119,11 +119,11 @@ func (r *Report) reportEvent(title string, date time.Time, message string, tags }) } -func (r *Report) reportInfoLog(message string, f ...interface{}) { +func (r *Report) reportInfoLog(message string, f ...any) { r.Collector.Logf(message, f) } -func (r *Report) reportWarnLog(message string, f ...interface{}) { +func (r *Report) reportWarnLog(message string, f ...any) { r.Collector.Logf(message, f) } diff --git a/pkg/datadogunifi/udm.go b/pkg/datadogunifi/udm.go index 796beb95..4863b40e 100644 --- a/pkg/datadogunifi/udm.go +++ b/pkg/datadogunifi/udm.go @@ -11,8 +11,8 @@ import ( const udmT = item("UDM") // Combine concatenates N maps. This will delete things if not used with caution. -func Combine(in ...map[string]interface{}) map[string]interface{} { - out := make(map[string]interface{}) +func Combine(in ...map[string]any) map[string]any { + out := make(map[string]any) for i := range in { for k := range in[i] { diff --git a/pkg/influxunifi/alarms.go b/pkg/influxunifi/alarms.go index 510cd343..238de6c7 100644 --- a/pkg/influxunifi/alarms.go +++ b/pkg/influxunifi/alarms.go @@ -17,7 +17,7 @@ func (u *InfluxUnifi) batchAlarms(r report, event *unifi.Alarm) { // nolint:dupl return // The event is older than our interval, ignore it. } - fields := map[string]interface{}{ + fields := map[string]any{ "dest_port": event.DestPort, "src_port": event.SrcPort, "dest_ip": event.DestIP, @@ -76,7 +76,7 @@ func (u *InfluxUnifi) batchAnomaly(r report, event *unifi.Anomaly) { r.send(&metric{ TS: event.Datetime, Table: "unifi_anomaly", - Fields: map[string]interface{}{"msg": event.Anomaly}, + Fields: map[string]any{"msg": event.Anomaly}, Tags: cleanTags(map[string]string{ "application": "unifi_anomaly", "source": event.SourceName, diff --git a/pkg/influxunifi/clients.go b/pkg/influxunifi/clients.go index bcf11dff..24e1beca 100644 --- a/pkg/influxunifi/clients.go +++ b/pkg/influxunifi/clients.go @@ -33,7 +33,7 @@ func (u *InfluxUnifi) batchClient(r report, s *unifi.Client) { // nolint: funlen "channel": s.Channel.Txt, "vlan": s.Vlan.Txt, } - fields := map[string]interface{}{ + fields := map[string]any{ "anomalies": s.Anomalies, "ip": s.IP, "essid": s.Essid, @@ -76,7 +76,7 @@ func (u *InfluxUnifi) batchClient(r report, s *unifi.Client) { // nolint: funlen // totalsDPImap: controller, site, name (app/cat name), dpi. type totalsDPImap map[string]map[string]map[string]unifi.DPIData -func (u *InfluxUnifi) batchClientDPI(r report, v interface{}, appTotal, catTotal totalsDPImap) { +func (u *InfluxUnifi) batchClientDPI(r report, v any, appTotal, catTotal totalsDPImap) { s, ok := v.(*unifi.DPITable) if !ok { u.LogErrorf("invalid type given to batchClientDPI: %T", v) @@ -99,7 +99,7 @@ func (u *InfluxUnifi) batchClientDPI(r report, v interface{}, appTotal, catTotal "site_name": s.SiteName, "source": s.SourceName, }, - Fields: map[string]interface{}{ + Fields: map[string]any{ "tx_packets": dpi.TxPackets, "rx_packets": dpi.RxPackets, "tx_bytes": dpi.TxBytes, @@ -166,7 +166,7 @@ func reportClientDPItotals(r report, appTotal, catTotal totalsDPImap) { "site_name": site, "source": controller, }, - Fields: map[string]interface{}{ + Fields: map[string]any{ "tx_packets": m.TxPackets, "rx_packets": m.RxPackets, "tx_bytes": m.TxBytes, diff --git a/pkg/influxunifi/events.go b/pkg/influxunifi/events.go index 624f5678..1d4476bf 100644 --- a/pkg/influxunifi/events.go +++ b/pkg/influxunifi/events.go @@ -18,7 +18,7 @@ func (u *InfluxUnifi) batchIDS(r report, i *unifi.IDS) { // nolint:dupl return // The event is older than our interval, ignore it. } - fields := map[string]interface{}{ + fields := map[string]any{ "dest_port": i.DestPort, "src_port": i.SrcPort, "dest_ip": i.DestIP, @@ -73,7 +73,7 @@ func (u *InfluxUnifi) batchEvent(r report, i *unifi.Event) { // nolint: funlen return // The event is older than our interval, ignore it. } - fields := map[string]interface{}{ + fields := map[string]any{ "msg": i.Msg, // contains user[] or guest[] or admin[] "duration": i.Duration.Val, // probably microseconds? "guest": i.Guest, // mac address @@ -157,7 +157,7 @@ func cleanTags(tags map[string]string) map[string]string { } // cleanFields removes any field with a default (or empty) value. -func cleanFields(fields map[string]interface{}) map[string]interface{} { //nolint:cyclop +func cleanFields(fields map[string]any) map[string]any { //nolint:cyclop for s := range fields { switch v := fields[s].(type) { case nil: diff --git a/pkg/influxunifi/influxdb.go b/pkg/influxunifi/influxdb.go index 7f31c378..780acc45 100644 --- a/pkg/influxunifi/influxdb.go +++ b/pkg/influxunifi/influxdb.go @@ -58,7 +58,7 @@ type InfluxUnifi struct { type metric struct { Table string Tags map[string]string - Fields map[string]interface{} + Fields map[string]any TS time.Time } @@ -266,7 +266,7 @@ func (u *InfluxUnifi) loopPoints(r report) { reportClientDPItotals(r, appTotal, catTotal) } -func (u *InfluxUnifi) switchExport(r report, v interface{}) { //nolint:cyclop +func (u *InfluxUnifi) switchExport(r report, v any) { //nolint:cyclop switch v := v.(type) { case *unifi.RogueAP: u.batchRogueAP(r, v) diff --git a/pkg/influxunifi/logger.go b/pkg/influxunifi/logger.go index 32b9fc89..57806442 100644 --- a/pkg/influxunifi/logger.go +++ b/pkg/influxunifi/logger.go @@ -8,7 +8,7 @@ import ( ) // Logf logs a message. -func (u *InfluxUnifi) Logf(msg string, v ...interface{}) { +func (u *InfluxUnifi) Logf(msg string, v ...any) { webserver.NewOutputEvent(PluginName, PluginName, &webserver.Event{ Ts: time.Now(), Msg: fmt.Sprintf(msg, v...), @@ -18,7 +18,7 @@ func (u *InfluxUnifi) Logf(msg string, v ...interface{}) { } // LogErrorf logs an error message. -func (u *InfluxUnifi) LogErrorf(msg string, v ...interface{}) { +func (u *InfluxUnifi) LogErrorf(msg string, v ...any) { webserver.NewOutputEvent(PluginName, PluginName, &webserver.Event{ Ts: time.Now(), Msg: fmt.Sprintf(msg, v...), @@ -28,7 +28,7 @@ func (u *InfluxUnifi) LogErrorf(msg string, v ...interface{}) { } // LogDebugf logs a debug message. -func (u *InfluxUnifi) LogDebugf(msg string, v ...interface{}) { +func (u *InfluxUnifi) LogDebugf(msg string, v ...any) { webserver.NewOutputEvent(PluginName, PluginName, &webserver.Event{ Ts: time.Now(), Msg: fmt.Sprintf(msg, v...), diff --git a/pkg/influxunifi/site.go b/pkg/influxunifi/site.go index 9ad2263b..749f7b1e 100644 --- a/pkg/influxunifi/site.go +++ b/pkg/influxunifi/site.go @@ -19,7 +19,7 @@ func (u *InfluxUnifi) batchSite(r report, s *unifi.Site) { "gw_name": h.GwName, "lan_ip": h.LanIP, } - fields := map[string]interface{}{ + fields := map[string]any{ "num_user": h.NumUser.Val, "num_guest": h.NumGuest.Val, "num_iot": h.NumIot.Val, @@ -57,7 +57,7 @@ func (u *InfluxUnifi) batchSite(r report, s *unifi.Site) { } } -func (u *InfluxUnifi) batchSiteDPI(r report, v interface{}) { +func (u *InfluxUnifi) batchSiteDPI(r report, v any) { s, ok := v.(*unifi.DPITable) if !ok { u.LogErrorf("invalid type given to batchSiteDPI: %T", v) @@ -73,7 +73,7 @@ func (u *InfluxUnifi) batchSiteDPI(r report, v interface{}) { "site_name": s.SiteName, "source": s.SourceName, }, - Fields: map[string]interface{}{ + Fields: map[string]any{ "tx_packets": dpi.TxPackets, "rx_packets": dpi.RxPackets, "tx_bytes": dpi.TxBytes, diff --git a/pkg/influxunifi/uap.go b/pkg/influxunifi/uap.go index 4bc936ba..c06692b2 100644 --- a/pkg/influxunifi/uap.go +++ b/pkg/influxunifi/uap.go @@ -27,7 +27,7 @@ func (u *InfluxUnifi) batchRogueAP(r report, s *unifi.RogueAP) { "name": s.Essid, "source": s.SourceName, }, - Fields: map[string]interface{}{ + Fields: map[string]any{ "age": s.Age.Val, "bw": s.Bw.Val, "center_freq": s.CenterFreq.Val, @@ -76,13 +76,13 @@ func (u *InfluxUnifi) batchUAP(r report, s *unifi.UAP) { u.batchPortTable(r, tags, s.PortTable) } -func (u *InfluxUnifi) processUAPstats(ap *unifi.Ap) map[string]interface{} { +func (u *InfluxUnifi) processUAPstats(ap *unifi.Ap) map[string]any { if ap == nil { - return map[string]interface{}{} + return map[string]any{} } // Accumulative Statistics. - return map[string]interface{}{ + return map[string]any{ "stat_user-rx_packets": ap.UserRxPackets.Val, "stat_guest-rx_packets": ap.GuestRxPackets.Val, "stat_rx_packets": ap.RxPackets.Val, @@ -137,7 +137,7 @@ func (u *InfluxUnifi) processVAPTable(r report, t map[string]string, vt unifi.Va "state": s.State, "is_guest": s.IsGuest.Txt, } - fields := map[string]interface{}{ + fields := map[string]any{ "ccq": s.Ccq, "mac_filter_rejections": s.MacFilterRejections, "num_satisfaction_sta": s.NumSatisfactionSta.Val, @@ -192,7 +192,7 @@ func (u *InfluxUnifi) processRadTable(r report, t map[string]string, rt unifi.Ra "channel": p.Channel.Txt, "radio": p.Radio, } - fields := map[string]interface{}{ + fields := map[string]any{ "current_antenna_gain": p.CurrentAntennaGain.Val, "ht": p.Ht.Txt, "max_txpower": p.MaxTxpower.Val, diff --git a/pkg/influxunifi/udm.go b/pkg/influxunifi/udm.go index d34642d5..154aeb22 100644 --- a/pkg/influxunifi/udm.go +++ b/pkg/influxunifi/udm.go @@ -11,8 +11,8 @@ import ( const udmT = item("UDM") // Combine concatenates N maps. This will delete things if not used with caution. -func Combine(in ...map[string]interface{}) map[string]interface{} { - out := make(map[string]interface{}) +func Combine(in ...map[string]any) map[string]any { + out := make(map[string]any) for i := range in { for k := range in[i] { @@ -24,8 +24,8 @@ func Combine(in ...map[string]interface{}) map[string]interface{} { } // batchSysStats is used by all device types. -func (u *InfluxUnifi) batchSysStats(s unifi.SysStats, ss unifi.SystemStats) map[string]interface{} { - m := map[string]interface{}{ +func (u *InfluxUnifi) batchSysStats(s unifi.SysStats, ss unifi.SystemStats) map[string]any { + m := map[string]any{ "loadavg_1": s.Loadavg1.Val, "loadavg_5": s.Loadavg5.Val, "loadavg_15": s.Loadavg15.Val, @@ -49,8 +49,8 @@ func (u *InfluxUnifi) batchSysStats(s unifi.SysStats, ss unifi.SystemStats) map[ return m } -func (u *InfluxUnifi) batchUDMtemps(temps []unifi.Temperature) map[string]interface{} { - output := make(map[string]interface{}) +func (u *InfluxUnifi) batchUDMtemps(temps []unifi.Temperature) map[string]any { + output := make(map[string]any) for _, t := range temps { output["temp_"+t.Name] = t.Value @@ -59,8 +59,8 @@ func (u *InfluxUnifi) batchUDMtemps(temps []unifi.Temperature) map[string]interf return output } -func (u *InfluxUnifi) batchUDMstorage(storage []*unifi.Storage) map[string]interface{} { - output := make(map[string]interface{}) +func (u *InfluxUnifi) batchUDMstorage(storage []*unifi.Storage) map[string]any { + output := make(map[string]any) for _, t := range storage { output["storage_"+t.Name+"_size"] = t.Size.Val @@ -98,7 +98,7 @@ func (u *InfluxUnifi) batchUDM(r report, s *unifi.UDM) { // nolint: funlen u.batchUDMtemps(s.Temperatures), u.batchUSGstats(s.SpeedtestStatus, s.Stat.Gw, s.Uplink), u.batchSysStats(s.SysStats, s.SystemStats), - map[string]interface{}{ + map[string]any{ "source": s.SourceName, "ip": s.IP, "bytes": s.Bytes.Val, @@ -134,7 +134,7 @@ func (u *InfluxUnifi) batchUDM(r report, s *unifi.UDM) { // nolint: funlen } fields = Combine( u.batchUSWstat(s.Stat.Sw), - map[string]interface{}{ + map[string]any{ "guest-num_sta": s.GuestNumSta.Val, "ip": s.IP, "bytes": s.Bytes.Val, diff --git a/pkg/influxunifi/usg.go b/pkg/influxunifi/usg.go index 1cc19b19..575d4570 100644 --- a/pkg/influxunifi/usg.go +++ b/pkg/influxunifi/usg.go @@ -28,7 +28,7 @@ func (u *InfluxUnifi) batchUSG(r report, s *unifi.USG) { u.batchUDMtemps(s.Temperatures), u.batchSysStats(s.SysStats, s.SystemStats), u.batchUSGstats(s.SpeedtestStatus, s.Stat.Gw, s.Uplink), - map[string]interface{}{ + map[string]any{ "ip": s.IP, "bytes": s.Bytes.Val, "last_seen": s.LastSeen.Val, @@ -53,12 +53,12 @@ func (u *InfluxUnifi) batchUSG(r report, s *unifi.USG) { u.batchUSGwans(r, tags, s.Wan1, s.Wan2) } -func (u *InfluxUnifi) batchUSGstats(ss unifi.SpeedtestStatus, gw *unifi.Gw, ul unifi.Uplink) map[string]interface{} { +func (u *InfluxUnifi) batchUSGstats(ss unifi.SpeedtestStatus, gw *unifi.Gw, ul unifi.Uplink) map[string]any { if gw == nil { - return map[string]interface{}{} + return map[string]any{} } - return map[string]interface{}{ + return map[string]any{ "uplink_name": ul.Name, "uplink_latency": ul.Latency.Val, "uplink_speed": ul.Speed.Val, @@ -95,7 +95,7 @@ func (u *InfluxUnifi) batchUSGwans(r report, tags map[string]string, wans ...uni "up": wan.Up.Txt, "enabled": wan.Enable.Txt, } - fields := map[string]interface{}{ + fields := map[string]any{ "bytes-r": wan.BytesR.Val, "full_duplex": wan.FullDuplex.Val, "gateway": wan.Gateway, @@ -137,7 +137,7 @@ func (u *InfluxUnifi) batchNetTable(r report, tags map[string]string, nt unifi.N "purpose": p.Purpose, "is_guest": p.IsGuest.Txt, } - fields := map[string]interface{}{ + fields := map[string]any{ "num_sta": p.NumSta.Val, "rx_bytes": p.RxBytes.Val, "rx_packets": p.RxPackets.Val, diff --git a/pkg/influxunifi/usw.go b/pkg/influxunifi/usw.go index b785998a..3438d8d6 100644 --- a/pkg/influxunifi/usw.go +++ b/pkg/influxunifi/usw.go @@ -27,7 +27,7 @@ func (u *InfluxUnifi) batchUSW(r report, s *unifi.USW) { fields := Combine( u.batchUSWstat(s.Stat.Sw), u.batchSysStats(s.SysStats, s.SystemStats), - map[string]interface{}{ + map[string]any{ "guest-num_sta": s.GuestNumSta.Val, "ip": s.IP, "bytes": s.Bytes.Val, @@ -46,12 +46,12 @@ func (u *InfluxUnifi) batchUSW(r report, s *unifi.USW) { u.batchPortTable(r, tags, s.PortTable) } -func (u *InfluxUnifi) batchUSWstat(sw *unifi.Sw) map[string]interface{} { +func (u *InfluxUnifi) batchUSWstat(sw *unifi.Sw) map[string]any { if sw == nil { - return map[string]interface{}{} + return map[string]any{} } - return map[string]interface{}{ + return map[string]any{ "stat_bytes": sw.Bytes.Val, "stat_rx_bytes": sw.RxBytes.Val, "stat_rx_crypts": sw.RxCrypts.Val, @@ -94,7 +94,7 @@ func (u *InfluxUnifi) batchPortTable(r report, t map[string]string, pt []unifi.P "sfp_vendor": p.SFPVendor, "sfp_part": p.SFPPart, } - fields := map[string]interface{}{ + fields := map[string]any{ "dbytes_r": p.BytesR.Val, "rx_broadcast": p.RxBroadcast.Val, "rx_bytes": p.RxBytes.Val, diff --git a/pkg/influxunifi/uxg.go b/pkg/influxunifi/uxg.go index fd8c27e7..a0aaf94d 100644 --- a/pkg/influxunifi/uxg.go +++ b/pkg/influxunifi/uxg.go @@ -29,7 +29,7 @@ func (u *InfluxUnifi) batchUXG(r report, s *unifi.UXG) { // nolint: funlen u.batchUDMtemps(s.Temperatures), u.batchUSGstats(s.SpeedtestStatus, s.Stat.Gw, s.Uplink), u.batchSysStats(s.SysStats, s.SystemStats), - map[string]interface{}{ + map[string]any{ "source": s.SourceName, "ip": s.IP, "bytes": s.Bytes.Val, @@ -65,7 +65,7 @@ func (u *InfluxUnifi) batchUXG(r report, s *unifi.UXG) { // nolint: funlen } fields = Combine( u.batchUSWstat(s.Stat.Sw), - map[string]interface{}{ + map[string]any{ "guest-num_sta": s.GuestNumSta.Val, "ip": s.IP, "bytes": s.Bytes.Val, diff --git a/pkg/inputunifi/collectevents.go b/pkg/inputunifi/collectevents.go index 17db05c7..e5129f59 100644 --- a/pkg/inputunifi/collectevents.go +++ b/pkg/inputunifi/collectevents.go @@ -10,7 +10,7 @@ import ( /* Event collection. Events are also sent to the webserver for display. */ -func (u *InputUnifi) collectControllerEvents(c *Controller) ([]interface{}, error) { +func (u *InputUnifi) collectControllerEvents(c *Controller) ([]any, error) { if u.isNill(c) { u.Logf("Re-authenticating to UniFi Controller: %s", c.URL) @@ -20,8 +20,8 @@ func (u *InputUnifi) collectControllerEvents(c *Controller) ([]interface{}, erro } var ( - logs = []interface{}{} - newLogs []interface{} + logs = []any{} + newLogs []any ) // Get the sites we care about. @@ -30,7 +30,7 @@ func (u *InputUnifi) collectControllerEvents(c *Controller) ([]interface{}, erro return nil, fmt.Errorf("unifi.GetSites(): %w", err) } - type caller func([]interface{}, []*unifi.Site, *Controller) ([]interface{}, error) + type caller func([]any, []*unifi.Site, *Controller) ([]any, error) for _, call := range []caller{u.collectIDS, u.collectAnomalies, u.collectAlarms, u.collectEvents} { if newLogs, err = call(logs, sites, c); err != nil { @@ -43,7 +43,7 @@ func (u *InputUnifi) collectControllerEvents(c *Controller) ([]interface{}, erro return logs, nil } -func (u *InputUnifi) collectAlarms(logs []interface{}, sites []*unifi.Site, c *Controller) ([]interface{}, error) { +func (u *InputUnifi) collectAlarms(logs []any, sites []*unifi.Site, c *Controller) ([]any, error) { if *c.SaveAlarms { for _, s := range sites { events, err := c.Unifi.GetAlarmsSite(s) @@ -67,7 +67,7 @@ func (u *InputUnifi) collectAlarms(logs []interface{}, sites []*unifi.Site, c *C return logs, nil } -func (u *InputUnifi) collectAnomalies(logs []interface{}, sites []*unifi.Site, c *Controller) ([]interface{}, error) { +func (u *InputUnifi) collectAnomalies(logs []any, sites []*unifi.Site, c *Controller) ([]any, error) { if *c.SaveAnomal { for _, s := range sites { events, err := c.Unifi.GetAnomaliesSite(s) @@ -90,7 +90,7 @@ func (u *InputUnifi) collectAnomalies(logs []interface{}, sites []*unifi.Site, c return logs, nil } -func (u *InputUnifi) collectEvents(logs []interface{}, sites []*unifi.Site, c *Controller) ([]interface{}, error) { +func (u *InputUnifi) collectEvents(logs []any, sites []*unifi.Site, c *Controller) ([]any, error) { if *c.SaveEvents { for _, s := range sites { events, err := c.Unifi.GetSiteEvents(s, time.Hour) @@ -115,7 +115,7 @@ func (u *InputUnifi) collectEvents(logs []interface{}, sites []*unifi.Site, c *C return logs, nil } -func (u *InputUnifi) collectIDS(logs []interface{}, sites []*unifi.Site, c *Controller) ([]interface{}, error) { +func (u *InputUnifi) collectIDS(logs []any, sites []*unifi.Site, c *Controller) ([]any, error) { if *c.SaveIDS { for _, s := range sites { events, err := c.Unifi.GetIDSSite(s) diff --git a/pkg/inputunifi/interface.go b/pkg/inputunifi/interface.go index 7d2dd25f..e80e8cd8 100644 --- a/pkg/inputunifi/interface.go +++ b/pkg/inputunifi/interface.go @@ -84,7 +84,7 @@ func (u *InputUnifi) Events(filter *poller.Filter) (*poller.Events, error) { return nil, nil } - logs := []interface{}{} + logs := []any{} if filter == nil { filter = &poller.Filter{} diff --git a/pkg/inputunifi/updateweb.go b/pkg/inputunifi/updateweb.go index ac26b508..6af46641 100644 --- a/pkg/inputunifi/updateweb.go +++ b/pkg/inputunifi/updateweb.go @@ -184,7 +184,7 @@ func formatDevices(c *Controller, devices *unifi.Devices) (d webserver.Devices) } // Logf logs a message. -func (u *InputUnifi) Logf(msg string, v ...interface{}) { +func (u *InputUnifi) Logf(msg string, v ...any) { webserver.NewInputEvent(PluginName, PluginName, &webserver.Event{ Ts: time.Now(), Msg: fmt.Sprintf(msg, v...), @@ -194,7 +194,7 @@ func (u *InputUnifi) Logf(msg string, v ...interface{}) { } // LogErrorf logs an error message. -func (u *InputUnifi) LogErrorf(msg string, v ...interface{}) { +func (u *InputUnifi) LogErrorf(msg string, v ...any) { webserver.NewInputEvent(PluginName, PluginName, &webserver.Event{ Ts: time.Now(), Msg: fmt.Sprintf(msg, v...), @@ -204,7 +204,7 @@ func (u *InputUnifi) LogErrorf(msg string, v ...interface{}) { } // LogDebugf logs a debug message. -func (u *InputUnifi) LogDebugf(msg string, v ...interface{}) { +func (u *InputUnifi) LogDebugf(msg string, v ...any) { webserver.NewInputEvent(PluginName, PluginName, &webserver.Event{ Ts: time.Now(), Msg: fmt.Sprintf(msg, v...), diff --git a/pkg/lokiunifi/client.go b/pkg/lokiunifi/client.go index 96610996..8ba1449c 100644 --- a/pkg/lokiunifi/client.go +++ b/pkg/lokiunifi/client.go @@ -37,7 +37,7 @@ func (l *Loki) httpClient() *Client { } // Post marshals and posts a batch of log messages. -func (c *Client) Post(logs interface{}) error { +func (c *Client) Post(logs any) error { msg, err := json.Marshal(logs) if err != nil { return fmt.Errorf("json marshal: %w", err) diff --git a/pkg/lokiunifi/logger.go b/pkg/lokiunifi/logger.go index 831c6258..ff8f554e 100644 --- a/pkg/lokiunifi/logger.go +++ b/pkg/lokiunifi/logger.go @@ -8,7 +8,7 @@ import ( ) // Logf logs a message. -func (l *Loki) Logf(msg string, v ...interface{}) { +func (l *Loki) Logf(msg string, v ...any) { webserver.NewOutputEvent(PluginName, PluginName, &webserver.Event{ Ts: time.Now(), Msg: fmt.Sprintf(msg, v...), @@ -18,7 +18,7 @@ func (l *Loki) Logf(msg string, v ...interface{}) { } // LogErrorf logs an error message. -func (l *Loki) LogErrorf(msg string, v ...interface{}) { +func (l *Loki) LogErrorf(msg string, v ...any) { webserver.NewOutputEvent(PluginName, PluginName, &webserver.Event{ Ts: time.Now(), Msg: fmt.Sprintf(msg, v...), @@ -28,7 +28,7 @@ func (l *Loki) LogErrorf(msg string, v ...interface{}) { } // LogDebugf logs a debug message. -func (l *Loki) LogDebugf(msg string, v ...interface{}) { +func (l *Loki) LogDebugf(msg string, v ...any) { webserver.NewOutputEvent(PluginName, PluginName, &webserver.Event{ Ts: time.Now(), Msg: fmt.Sprintf(msg, v...), diff --git a/pkg/poller/README.md b/pkg/poller/README.md index 76c54f7d..202208bf 100644 --- a/pkg/poller/README.md +++ b/pkg/poller/README.md @@ -10,7 +10,7 @@ Aggregates metrics on request. Provides CLI app and args parsing. This library has no notion of "UniFi" or controllers, or Influx, or Prometheus. This library simply provides an input interface and an output interface. -Each interface uses an `[]interface{}` type, so any type of data can be used. +Each interface uses an `[]any` type, so any type of data can be used. That is to say, you could write input and output plugins that work with, say, Cisco gear, or any other network (or even non-network) data. The existing plugins should provide ample example of how to use this library, but at some point the diff --git a/pkg/poller/config.go b/pkg/poller/config.go index ab8472c8..47797505 100644 --- a/pkg/poller/config.go +++ b/pkg/poller/config.go @@ -78,17 +78,17 @@ type Flags struct { // Metrics is a type shared by the exporting and reporting packages. type Metrics struct { TS time.Time - Sites []interface{} - Clients []interface{} - SitesDPI []interface{} - ClientsDPI []interface{} - Devices []interface{} - RogueAPs []interface{} + Sites []any + Clients []any + SitesDPI []any + ClientsDPI []any + Devices []any + RogueAPs []any } // Events defines the type for log entries. type Events struct { - Logs []interface{} + Logs []any } // Config represents the core library input data. @@ -160,7 +160,7 @@ func getFirstFile(files []string) (string, error) { } // parseInterface parses the config file and environment variables into the provided interface. -func (u *UnifiPoller) parseInterface(i interface{}) error { +func (u *UnifiPoller) parseInterface(i any) error { // Parse config file into provided interface. if err := cnfgfile.Unmarshal(i, u.Flags.ConfigFile); err != nil { return fmt.Errorf("cnfg unmarshal: %w", err) diff --git a/pkg/poller/inputs.go b/pkg/poller/inputs.go index af9a983c..12f66a05 100644 --- a/pkg/poller/inputs.go +++ b/pkg/poller/inputs.go @@ -23,7 +23,7 @@ type Input interface { // InputPlugin describes an input plugin's consumable interface. type InputPlugin struct { Name string - Config interface{} // Each config is passed into an unmarshaller later. + Config any // Each config is passed into an unmarshaller later. Input } diff --git a/pkg/poller/logger.go b/pkg/poller/logger.go index 689771da..5c37118d 100644 --- a/pkg/poller/logger.go +++ b/pkg/poller/logger.go @@ -10,26 +10,26 @@ const callDepth = 2 // Logger is passed into input packages so they may write logs. type Logger interface { - Logf(m string, v ...interface{}) - LogErrorf(m string, v ...interface{}) - LogDebugf(m string, v ...interface{}) + Logf(m string, v ...any) + LogErrorf(m string, v ...any) + LogDebugf(m string, v ...any) } // Logf prints a log entry if quiet is false. -func (u *UnifiPoller) Logf(m string, v ...interface{}) { +func (u *UnifiPoller) Logf(m string, v ...any) { if !u.Quiet { _ = 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{}) { +func (u *UnifiPoller) LogDebugf(m string, v ...any) { if u.Debug && !u.Quiet { _ = log.Output(callDepth, fmt.Sprintf("[DEBUG] "+m, v...)) } } // LogErrorf prints an error log entry. -func (u *UnifiPoller) LogErrorf(m string, v ...interface{}) { +func (u *UnifiPoller) LogErrorf(m string, v ...any) { _ = log.Output(callDepth, fmt.Sprintf("[ERROR] "+m, v...)) } diff --git a/pkg/poller/outputs.go b/pkg/poller/outputs.go index 4dd05c0d..a3a5a3ce 100644 --- a/pkg/poller/outputs.go +++ b/pkg/poller/outputs.go @@ -28,7 +28,7 @@ type Collect interface { // Output packages should call NewOutput with this struct in init(). type Output struct { Name string - Config interface{} // Each config is passed into an unmarshaller later. + Config any // Each config is passed into an unmarshaller later. Method func(Collect) error // Called on startup for each configured output. } diff --git a/pkg/promunifi/clients.go b/pkg/promunifi/clients.go index 3806a1e8..07cc6548 100644 --- a/pkg/promunifi/clients.go +++ b/pkg/promunifi/clients.go @@ -74,7 +74,7 @@ func descClient(ns string) *uclient { } } -func (u *promUnifi) exportClientDPI(r report, v interface{}, appTotal, catTotal totalsDPImap) { +func (u *promUnifi) exportClientDPI(r report, v any, appTotal, catTotal totalsDPImap) { s, ok := v.(*unifi.DPITable) if !ok { u.LogErrorf("invalid type given to ClientsDPI: %T", v) diff --git a/pkg/promunifi/collector.go b/pkg/promunifi/collector.go index 72091607..795119de 100644 --- a/pkg/promunifi/collector.go +++ b/pkg/promunifi/collector.go @@ -71,7 +71,7 @@ type Config struct { type metric struct { Desc *prometheus.Desc ValueType prometheus.ValueType - Value interface{} + Value any Labels []string } @@ -221,7 +221,7 @@ func (t *target) Describe(ch chan<- *prometheus.Desc) { // Describe satisfies the prometheus Collector. This returns all of the // metric descriptions that this packages produces. func (u *promUnifi) Describe(ch chan<- *prometheus.Desc) { - for _, f := range []interface{}{u.Client, u.Device, u.UAP, u.USG, u.USW, u.Site} { + for _, f := range []any{u.Client, u.Device, u.UAP, u.USG, u.USW, u.Site} { v := reflect.Indirect(reflect.ValueOf(f)) // Loop each struct member and send it to the provided channel. @@ -332,7 +332,7 @@ func (u *promUnifi) loopExports(r report) { u.exportClientDPItotals(r, appTotal, catTotal) } -func (u *promUnifi) switchExport(r report, v interface{}) { +func (u *promUnifi) switchExport(r report, v any) { switch v := v.(type) { case *unifi.RogueAP: // r.addRogueAP() diff --git a/pkg/promunifi/logger.go b/pkg/promunifi/logger.go index d9529484..8215fd51 100644 --- a/pkg/promunifi/logger.go +++ b/pkg/promunifi/logger.go @@ -8,7 +8,7 @@ import ( ) // Logf logs a message. -func (u *promUnifi) Logf(msg string, v ...interface{}) { +func (u *promUnifi) Logf(msg string, v ...any) { webserver.NewOutputEvent(PluginName, PluginName, &webserver.Event{ Ts: time.Now(), Msg: fmt.Sprintf(msg, v...), @@ -18,7 +18,7 @@ func (u *promUnifi) Logf(msg string, v ...interface{}) { } // LogErrorf logs an error message. -func (u *promUnifi) LogErrorf(msg string, v ...interface{}) { +func (u *promUnifi) LogErrorf(msg string, v ...any) { webserver.NewOutputEvent(PluginName, PluginName, &webserver.Event{ Ts: time.Now(), Msg: fmt.Sprintf(msg, v...), @@ -28,7 +28,7 @@ func (u *promUnifi) LogErrorf(msg string, v ...interface{}) { } // LogDebugf logs a debug message. -func (u *promUnifi) LogDebugf(msg string, v ...interface{}) { +func (u *promUnifi) LogDebugf(msg string, v ...any) { webserver.NewOutputEvent(PluginName, PluginName, &webserver.Event{ Ts: time.Now(), Msg: fmt.Sprintf(msg, v...), diff --git a/pkg/promunifi/report.go b/pkg/promunifi/report.go index 34426146..afb0e86b 100644 --- a/pkg/promunifi/report.go +++ b/pkg/promunifi/report.go @@ -18,7 +18,7 @@ type report interface { metrics() *poller.Metrics report(c poller.Logger, descs map[*prometheus.Desc]bool) export(m *metric, v float64) prometheus.Metric - error(ch chan<- prometheus.Metric, d *prometheus.Desc, v interface{}) + error(ch chan<- prometheus.Metric, d *prometheus.Desc, v any) addUDM() addUXG() addUSG() @@ -64,7 +64,7 @@ func (r *Report) export(m *metric, v float64) prometheus.Metric { return prometheus.MustNewConstMetric(m.Desc, m.ValueType, v, m.Labels...) } -func (r *Report) error(ch chan<- prometheus.Metric, d *prometheus.Desc, v interface{}) { +func (r *Report) error(ch chan<- prometheus.Metric, d *prometheus.Desc, v any) { r.Errors++ if r.ReportErrors { diff --git a/pkg/promunifi/site.go b/pkg/promunifi/site.go index d17539cf..20f75d2c 100644 --- a/pkg/promunifi/site.go +++ b/pkg/promunifi/site.go @@ -75,7 +75,7 @@ func descSite(ns string) *site { } } -func (u *promUnifi) exportSiteDPI(r report, v interface{}) { +func (u *promUnifi) exportSiteDPI(r report, v any) { s, ok := v.(*unifi.DPITable) if !ok { u.LogErrorf("invalid type given to SiteDPI: %T", v) diff --git a/pkg/webserver/handlers.go b/pkg/webserver/handlers.go index 8ff2b59c..4ea072db 100644 --- a/pkg/webserver/handlers.go +++ b/pkg/webserver/handlers.go @@ -39,7 +39,7 @@ func (s *Server) handleConfig(w http.ResponseWriter, r *http.Request) { switch vars["sub"] { case "": - data := map[string]interface{}{ + data := map[string]any{ "inputs": s.Collect.Inputs(), "outputs": s.Collect.Outputs(), "poller": s.Collect.Poller(), diff --git a/pkg/webserver/logger.go b/pkg/webserver/logger.go index ab29b2a2..31d2baa5 100644 --- a/pkg/webserver/logger.go +++ b/pkg/webserver/logger.go @@ -6,7 +6,7 @@ import ( ) // Logf logs a message. -func (s *Server) Logf(msg string, v ...interface{}) { +func (s *Server) Logf(msg string, v ...any) { NewOutputEvent(PluginName, PluginName, &Event{ Ts: time.Now(), Msg: fmt.Sprintf(msg, v...), @@ -16,7 +16,7 @@ func (s *Server) Logf(msg string, v ...interface{}) { } // LogErrorf logs an error message. -func (s *Server) LogErrorf(msg string, v ...interface{}) { +func (s *Server) LogErrorf(msg string, v ...any) { NewOutputEvent(PluginName, PluginName, &Event{ Ts: time.Now(), Msg: fmt.Sprintf(msg, v...), @@ -26,7 +26,7 @@ func (s *Server) LogErrorf(msg string, v ...interface{}) { } // LogDebugf logs a debug message. -func (s *Server) LogDebugf(msg string, v ...interface{}) { +func (s *Server) LogDebugf(msg string, v ...any) { NewOutputEvent(PluginName, PluginName, &Event{ Ts: time.Now(), Msg: fmt.Sprintf(msg, v...), diff --git a/pkg/webserver/plugins_types.go b/pkg/webserver/plugins_types.go index 5a6b4072..47891397 100644 --- a/pkg/webserver/plugins_types.go +++ b/pkg/webserver/plugins_types.go @@ -15,7 +15,7 @@ type Input struct { Events Events Devices Devices Clients Clients - Config interface{} + Config any Counter map[string]int64 sync.RWMutex // Locks this data structure. } @@ -27,7 +27,7 @@ type Input struct { type Output struct { Name string Events Events - Config interface{} + Config any Counter map[string]int64 sync.RWMutex // Locks this data structure. } @@ -94,18 +94,18 @@ type Devices []*Device // Device holds the data for a network device. type Device struct { - Clients int `json:"clients"` - Uptime int `json:"uptime"` - Name string `json:"name"` - SiteID string `json:"site_id"` - Source string `json:"source"` - Controller string `json:"controller"` - MAC string `json:"mac"` - IP string `json:"ip"` - Type string `json:"type"` - Model string `json:"model"` - Version string `json:"version"` - Config interface{} `json:"config,omitempty"` + Clients int `json:"clients"` + Uptime int `json:"uptime"` + Name string `json:"name"` + SiteID string `json:"site_id"` + Source string `json:"source"` + Controller string `json:"controller"` + MAC string `json:"mac"` + IP string `json:"ip"` + Type string `json:"type"` + Model string `json:"model"` + Version string `json:"version"` + Config any `json:"config,omitempty"` } func (c Devices) Filter(siteid string) (devices []*Device) { diff --git a/pkg/webserver/shared.go b/pkg/webserver/shared.go index ec3a7ca7..b8549383 100644 --- a/pkg/webserver/shared.go +++ b/pkg/webserver/shared.go @@ -89,7 +89,7 @@ func (s *Server) handleDone(w http.ResponseWriter, b []byte, cType string) { } // handleJSON sends a json-formatted data reply. -func (s *Server) handleJSON(w http.ResponseWriter, data interface{}) { +func (s *Server) handleJSON(w http.ResponseWriter, data any) { b, err := json.Marshal(data) if err != nil { s.handleError(w, err)