Merge pull request #447 from unpoller/interface-to-any
go 1.19 interface{} -> any
			
			
This commit is contained in:
		
						commit
						85e4bbefd8
					
				|  | @ -80,7 +80,7 @@ func (u *DatadogUnifi) batchClient(r report, s *unifi.Client) { // nolint: funle | ||||||
| // totalsDPImap: controller, site, name (app/cat name), dpi.
 | // totalsDPImap: controller, site, name (app/cat name), dpi.
 | ||||||
| type totalsDPImap map[string]map[string]map[string]unifi.DPIData | 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) | 	s, ok := v.(*unifi.DPITable) | ||||||
| 	if !ok { | 	if !ok { | ||||||
| 		u.LogErrorf("invalid type given to batchClientDPI: %T", v) | 		u.LogErrorf("invalid type given to batchClientDPI: %T", v) | ||||||
|  |  | ||||||
|  | @ -301,7 +301,7 @@ func (u *DatadogUnifi) loopPoints(r report) { | ||||||
| 	reportClientDPItotals(r, appTotal, catTotal) | 	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) { | 	switch v := v.(type) { | ||||||
| 	case *unifi.RogueAP: | 	case *unifi.RogueAP: | ||||||
| 		u.batchRogueAP(r, v) | 		u.batchRogueAP(r, v) | ||||||
|  |  | ||||||
|  | @ -1,21 +1,21 @@ | ||||||
| package datadogunifi | package datadogunifi | ||||||
| 
 | 
 | ||||||
| // Logf logs a message.
 | // Logf logs a message.
 | ||||||
| func (u *DatadogUnifi) Logf(msg string, v ...interface{}) { | func (u *DatadogUnifi) Logf(msg string, v ...any) { | ||||||
| 	if u.Collector != nil { | 	if u.Collector != nil { | ||||||
| 		u.Collector.Logf(msg, v...) | 		u.Collector.Logf(msg, v...) | ||||||
| 	} | 	} | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| // LogErrorf logs an error message.
 | // 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 { | 	if u.Collector != nil { | ||||||
| 		u.Collector.LogErrorf(msg, v...) | 		u.Collector.LogErrorf(msg, v...) | ||||||
| 	} | 	} | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| // LogDebugf logs a debug message.
 | // 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 { | 	if u.Collector != nil { | ||||||
| 		u.Collector.LogDebugf(msg, v...) | 		u.Collector.LogDebugf(msg, v...) | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
|  | @ -5,7 +5,7 @@ import ( | ||||||
| 	"strings" | 	"strings" | ||||||
| ) | ) | ||||||
| 
 | 
 | ||||||
| func tag(name string, value interface{}) string { | func tag(name string, value any) string { | ||||||
| 	return fmt.Sprintf("%s:%v", name, value) | 	return fmt.Sprintf("%s:%v", name, value) | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -47,8 +47,8 @@ type report interface { | ||||||
| 	reportDistribution(name string, value float64, tags []string) error | 	reportDistribution(name string, value float64, tags []string) error | ||||||
| 	reportTiming(name string, value time.Duration, tags []string) error | 	reportTiming(name string, value time.Duration, tags []string) error | ||||||
| 	reportEvent(title string, date time.Time, message string, tags []string) error | 	reportEvent(title string, date time.Time, message string, tags []string) error | ||||||
| 	reportInfoLog(message string, f ...interface{}) | 	reportInfoLog(message string, f ...any) | ||||||
| 	reportWarnLog(message string, f ...interface{}) | 	reportWarnLog(message string, f ...any) | ||||||
| 	reportServiceCheck(name string, status statsd.ServiceCheckStatus, message string, tags []string) error | 	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) | 	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) | 	r.Collector.Logf(message, f) | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -11,8 +11,8 @@ import ( | ||||||
| const udmT = item("UDM") | const udmT = item("UDM") | ||||||
| 
 | 
 | ||||||
| // Combine concatenates N maps. This will delete things if not used with caution.
 | // Combine concatenates N maps. This will delete things if not used with caution.
 | ||||||
| func Combine(in ...map[string]interface{}) map[string]interface{} { | func Combine(in ...map[string]any) map[string]any { | ||||||
| 	out := make(map[string]interface{}) | 	out := make(map[string]any) | ||||||
| 
 | 
 | ||||||
| 	for i := range in { | 	for i := range in { | ||||||
| 		for k := range in[i] { | 		for k := range in[i] { | ||||||
|  |  | ||||||
|  | @ -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.
 | 		return // The event is older than our interval, ignore it.
 | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	fields := map[string]interface{}{ | 	fields := map[string]any{ | ||||||
| 		"dest_port":            event.DestPort, | 		"dest_port":            event.DestPort, | ||||||
| 		"src_port":             event.SrcPort, | 		"src_port":             event.SrcPort, | ||||||
| 		"dest_ip":              event.DestIP, | 		"dest_ip":              event.DestIP, | ||||||
|  | @ -76,7 +76,7 @@ func (u *InfluxUnifi) batchAnomaly(r report, event *unifi.Anomaly) { | ||||||
| 	r.send(&metric{ | 	r.send(&metric{ | ||||||
| 		TS:     event.Datetime, | 		TS:     event.Datetime, | ||||||
| 		Table:  "unifi_anomaly", | 		Table:  "unifi_anomaly", | ||||||
| 		Fields: map[string]interface{}{"msg": event.Anomaly}, | 		Fields: map[string]any{"msg": event.Anomaly}, | ||||||
| 		Tags: cleanTags(map[string]string{ | 		Tags: cleanTags(map[string]string{ | ||||||
| 			"application": "unifi_anomaly", | 			"application": "unifi_anomaly", | ||||||
| 			"source":      event.SourceName, | 			"source":      event.SourceName, | ||||||
|  |  | ||||||
|  | @ -33,7 +33,7 @@ func (u *InfluxUnifi) batchClient(r report, s *unifi.Client) { // nolint: funlen | ||||||
| 		"channel":     s.Channel.Txt, | 		"channel":     s.Channel.Txt, | ||||||
| 		"vlan":        s.Vlan.Txt, | 		"vlan":        s.Vlan.Txt, | ||||||
| 	} | 	} | ||||||
| 	fields := map[string]interface{}{ | 	fields := map[string]any{ | ||||||
| 		"anomalies":         s.Anomalies, | 		"anomalies":         s.Anomalies, | ||||||
| 		"ip":                s.IP, | 		"ip":                s.IP, | ||||||
| 		"essid":             s.Essid, | 		"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.
 | // totalsDPImap: controller, site, name (app/cat name), dpi.
 | ||||||
| type totalsDPImap map[string]map[string]map[string]unifi.DPIData | 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) | 	s, ok := v.(*unifi.DPITable) | ||||||
| 	if !ok { | 	if !ok { | ||||||
| 		u.LogErrorf("invalid type given to batchClientDPI: %T", v) | 		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, | 				"site_name":   s.SiteName, | ||||||
| 				"source":      s.SourceName, | 				"source":      s.SourceName, | ||||||
| 			}, | 			}, | ||||||
| 			Fields: map[string]interface{}{ | 			Fields: map[string]any{ | ||||||
| 				"tx_packets": dpi.TxPackets, | 				"tx_packets": dpi.TxPackets, | ||||||
| 				"rx_packets": dpi.RxPackets, | 				"rx_packets": dpi.RxPackets, | ||||||
| 				"tx_bytes":   dpi.TxBytes, | 				"tx_bytes":   dpi.TxBytes, | ||||||
|  | @ -166,7 +166,7 @@ func reportClientDPItotals(r report, appTotal, catTotal totalsDPImap) { | ||||||
| 							"site_name":   site, | 							"site_name":   site, | ||||||
| 							"source":      controller, | 							"source":      controller, | ||||||
| 						}, | 						}, | ||||||
| 						Fields: map[string]interface{}{ | 						Fields: map[string]any{ | ||||||
| 							"tx_packets": m.TxPackets, | 							"tx_packets": m.TxPackets, | ||||||
| 							"rx_packets": m.RxPackets, | 							"rx_packets": m.RxPackets, | ||||||
| 							"tx_bytes":   m.TxBytes, | 							"tx_bytes":   m.TxBytes, | ||||||
|  |  | ||||||
|  | @ -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.
 | 		return // The event is older than our interval, ignore it.
 | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	fields := map[string]interface{}{ | 	fields := map[string]any{ | ||||||
| 		"dest_port":            i.DestPort, | 		"dest_port":            i.DestPort, | ||||||
| 		"src_port":             i.SrcPort, | 		"src_port":             i.SrcPort, | ||||||
| 		"dest_ip":              i.DestIP, | 		"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.
 | 		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[]
 | 		"msg":                  i.Msg,          // contains user[] or guest[] or admin[]
 | ||||||
| 		"duration":             i.Duration.Val, // probably microseconds?
 | 		"duration":             i.Duration.Val, // probably microseconds?
 | ||||||
| 		"guest":                i.Guest,        // mac address
 | 		"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.
 | // 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 { | 	for s := range fields { | ||||||
| 		switch v := fields[s].(type) { | 		switch v := fields[s].(type) { | ||||||
| 		case nil: | 		case nil: | ||||||
|  |  | ||||||
|  | @ -58,7 +58,7 @@ type InfluxUnifi struct { | ||||||
| type metric struct { | type metric struct { | ||||||
| 	Table  string | 	Table  string | ||||||
| 	Tags   map[string]string | 	Tags   map[string]string | ||||||
| 	Fields map[string]interface{} | 	Fields map[string]any | ||||||
| 	TS     time.Time | 	TS     time.Time | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | @ -266,7 +266,7 @@ func (u *InfluxUnifi) loopPoints(r report) { | ||||||
| 	reportClientDPItotals(r, appTotal, catTotal) | 	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) { | 	switch v := v.(type) { | ||||||
| 	case *unifi.RogueAP: | 	case *unifi.RogueAP: | ||||||
| 		u.batchRogueAP(r, v) | 		u.batchRogueAP(r, v) | ||||||
|  |  | ||||||
|  | @ -8,7 +8,7 @@ import ( | ||||||
| ) | ) | ||||||
| 
 | 
 | ||||||
| // Logf logs a message.
 | // 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{ | 	webserver.NewOutputEvent(PluginName, PluginName, &webserver.Event{ | ||||||
| 		Ts:   time.Now(), | 		Ts:   time.Now(), | ||||||
| 		Msg:  fmt.Sprintf(msg, v...), | 		Msg:  fmt.Sprintf(msg, v...), | ||||||
|  | @ -18,7 +18,7 @@ func (u *InfluxUnifi) Logf(msg string, v ...interface{}) { | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| // LogErrorf logs an error message.
 | // 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{ | 	webserver.NewOutputEvent(PluginName, PluginName, &webserver.Event{ | ||||||
| 		Ts:   time.Now(), | 		Ts:   time.Now(), | ||||||
| 		Msg:  fmt.Sprintf(msg, v...), | 		Msg:  fmt.Sprintf(msg, v...), | ||||||
|  | @ -28,7 +28,7 @@ func (u *InfluxUnifi) LogErrorf(msg string, v ...interface{}) { | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| // LogDebugf logs a debug message.
 | // 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{ | 	webserver.NewOutputEvent(PluginName, PluginName, &webserver.Event{ | ||||||
| 		Ts:   time.Now(), | 		Ts:   time.Now(), | ||||||
| 		Msg:  fmt.Sprintf(msg, v...), | 		Msg:  fmt.Sprintf(msg, v...), | ||||||
|  |  | ||||||
|  | @ -19,7 +19,7 @@ func (u *InfluxUnifi) batchSite(r report, s *unifi.Site) { | ||||||
| 			"gw_name":   h.GwName, | 			"gw_name":   h.GwName, | ||||||
| 			"lan_ip":    h.LanIP, | 			"lan_ip":    h.LanIP, | ||||||
| 		} | 		} | ||||||
| 		fields := map[string]interface{}{ | 		fields := map[string]any{ | ||||||
| 			"num_user":                 h.NumUser.Val, | 			"num_user":                 h.NumUser.Val, | ||||||
| 			"num_guest":                h.NumGuest.Val, | 			"num_guest":                h.NumGuest.Val, | ||||||
| 			"num_iot":                  h.NumIot.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) | 	s, ok := v.(*unifi.DPITable) | ||||||
| 	if !ok { | 	if !ok { | ||||||
| 		u.LogErrorf("invalid type given to batchSiteDPI: %T", v) | 		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, | 				"site_name":   s.SiteName, | ||||||
| 				"source":      s.SourceName, | 				"source":      s.SourceName, | ||||||
| 			}, | 			}, | ||||||
| 			Fields: map[string]interface{}{ | 			Fields: map[string]any{ | ||||||
| 				"tx_packets": dpi.TxPackets, | 				"tx_packets": dpi.TxPackets, | ||||||
| 				"rx_packets": dpi.RxPackets, | 				"rx_packets": dpi.RxPackets, | ||||||
| 				"tx_bytes":   dpi.TxBytes, | 				"tx_bytes":   dpi.TxBytes, | ||||||
|  |  | ||||||
|  | @ -27,7 +27,7 @@ func (u *InfluxUnifi) batchRogueAP(r report, s *unifi.RogueAP) { | ||||||
| 			"name":       s.Essid, | 			"name":       s.Essid, | ||||||
| 			"source":     s.SourceName, | 			"source":     s.SourceName, | ||||||
| 		}, | 		}, | ||||||
| 		Fields: map[string]interface{}{ | 		Fields: map[string]any{ | ||||||
| 			"age":         s.Age.Val, | 			"age":         s.Age.Val, | ||||||
| 			"bw":          s.Bw.Val, | 			"bw":          s.Bw.Val, | ||||||
| 			"center_freq": s.CenterFreq.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) | 	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 { | 	if ap == nil { | ||||||
| 		return map[string]interface{}{} | 		return map[string]any{} | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	// Accumulative Statistics.
 | 	// Accumulative Statistics.
 | ||||||
| 	return map[string]interface{}{ | 	return map[string]any{ | ||||||
| 		"stat_user-rx_packets":  ap.UserRxPackets.Val, | 		"stat_user-rx_packets":  ap.UserRxPackets.Val, | ||||||
| 		"stat_guest-rx_packets": ap.GuestRxPackets.Val, | 		"stat_guest-rx_packets": ap.GuestRxPackets.Val, | ||||||
| 		"stat_rx_packets":       ap.RxPackets.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, | 			"state":       s.State, | ||||||
| 			"is_guest":    s.IsGuest.Txt, | 			"is_guest":    s.IsGuest.Txt, | ||||||
| 		} | 		} | ||||||
| 		fields := map[string]interface{}{ | 		fields := map[string]any{ | ||||||
| 			"ccq":                       s.Ccq, | 			"ccq":                       s.Ccq, | ||||||
| 			"mac_filter_rejections":     s.MacFilterRejections, | 			"mac_filter_rejections":     s.MacFilterRejections, | ||||||
| 			"num_satisfaction_sta":      s.NumSatisfactionSta.Val, | 			"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, | 			"channel":     p.Channel.Txt, | ||||||
| 			"radio":       p.Radio, | 			"radio":       p.Radio, | ||||||
| 		} | 		} | ||||||
| 		fields := map[string]interface{}{ | 		fields := map[string]any{ | ||||||
| 			"current_antenna_gain": p.CurrentAntennaGain.Val, | 			"current_antenna_gain": p.CurrentAntennaGain.Val, | ||||||
| 			"ht":                   p.Ht.Txt, | 			"ht":                   p.Ht.Txt, | ||||||
| 			"max_txpower":          p.MaxTxpower.Val, | 			"max_txpower":          p.MaxTxpower.Val, | ||||||
|  |  | ||||||
|  | @ -11,8 +11,8 @@ import ( | ||||||
| const udmT = item("UDM") | const udmT = item("UDM") | ||||||
| 
 | 
 | ||||||
| // Combine concatenates N maps. This will delete things if not used with caution.
 | // Combine concatenates N maps. This will delete things if not used with caution.
 | ||||||
| func Combine(in ...map[string]interface{}) map[string]interface{} { | func Combine(in ...map[string]any) map[string]any { | ||||||
| 	out := make(map[string]interface{}) | 	out := make(map[string]any) | ||||||
| 
 | 
 | ||||||
| 	for i := range in { | 	for i := range in { | ||||||
| 		for k := range in[i] { | 		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.
 | // batchSysStats is used by all device types.
 | ||||||
| func (u *InfluxUnifi) batchSysStats(s unifi.SysStats, ss unifi.SystemStats) map[string]interface{} { | func (u *InfluxUnifi) batchSysStats(s unifi.SysStats, ss unifi.SystemStats) map[string]any { | ||||||
| 	m := map[string]interface{}{ | 	m := map[string]any{ | ||||||
| 		"loadavg_1":     s.Loadavg1.Val, | 		"loadavg_1":     s.Loadavg1.Val, | ||||||
| 		"loadavg_5":     s.Loadavg5.Val, | 		"loadavg_5":     s.Loadavg5.Val, | ||||||
| 		"loadavg_15":    s.Loadavg15.Val, | 		"loadavg_15":    s.Loadavg15.Val, | ||||||
|  | @ -49,8 +49,8 @@ func (u *InfluxUnifi) batchSysStats(s unifi.SysStats, ss unifi.SystemStats) map[ | ||||||
| 	return m | 	return m | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| func (u *InfluxUnifi) batchUDMtemps(temps []unifi.Temperature) map[string]interface{} { | func (u *InfluxUnifi) batchUDMtemps(temps []unifi.Temperature) map[string]any { | ||||||
| 	output := make(map[string]interface{}) | 	output := make(map[string]any) | ||||||
| 
 | 
 | ||||||
| 	for _, t := range temps { | 	for _, t := range temps { | ||||||
| 		output["temp_"+t.Name] = t.Value | 		output["temp_"+t.Name] = t.Value | ||||||
|  | @ -59,8 +59,8 @@ func (u *InfluxUnifi) batchUDMtemps(temps []unifi.Temperature) map[string]interf | ||||||
| 	return output | 	return output | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| func (u *InfluxUnifi) batchUDMstorage(storage []*unifi.Storage) map[string]interface{} { | func (u *InfluxUnifi) batchUDMstorage(storage []*unifi.Storage) map[string]any { | ||||||
| 	output := make(map[string]interface{}) | 	output := make(map[string]any) | ||||||
| 
 | 
 | ||||||
| 	for _, t := range storage { | 	for _, t := range storage { | ||||||
| 		output["storage_"+t.Name+"_size"] = t.Size.Val | 		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.batchUDMtemps(s.Temperatures), | ||||||
| 		u.batchUSGstats(s.SpeedtestStatus, s.Stat.Gw, s.Uplink), | 		u.batchUSGstats(s.SpeedtestStatus, s.Stat.Gw, s.Uplink), | ||||||
| 		u.batchSysStats(s.SysStats, s.SystemStats), | 		u.batchSysStats(s.SysStats, s.SystemStats), | ||||||
| 		map[string]interface{}{ | 		map[string]any{ | ||||||
| 			"source":        s.SourceName, | 			"source":        s.SourceName, | ||||||
| 			"ip":            s.IP, | 			"ip":            s.IP, | ||||||
| 			"bytes":         s.Bytes.Val, | 			"bytes":         s.Bytes.Val, | ||||||
|  | @ -134,7 +134,7 @@ func (u *InfluxUnifi) batchUDM(r report, s *unifi.UDM) { // nolint: funlen | ||||||
| 	} | 	} | ||||||
| 	fields = Combine( | 	fields = Combine( | ||||||
| 		u.batchUSWstat(s.Stat.Sw), | 		u.batchUSWstat(s.Stat.Sw), | ||||||
| 		map[string]interface{}{ | 		map[string]any{ | ||||||
| 			"guest-num_sta": s.GuestNumSta.Val, | 			"guest-num_sta": s.GuestNumSta.Val, | ||||||
| 			"ip":            s.IP, | 			"ip":            s.IP, | ||||||
| 			"bytes":         s.Bytes.Val, | 			"bytes":         s.Bytes.Val, | ||||||
|  |  | ||||||
|  | @ -28,7 +28,7 @@ func (u *InfluxUnifi) batchUSG(r report, s *unifi.USG) { | ||||||
| 		u.batchUDMtemps(s.Temperatures), | 		u.batchUDMtemps(s.Temperatures), | ||||||
| 		u.batchSysStats(s.SysStats, s.SystemStats), | 		u.batchSysStats(s.SysStats, s.SystemStats), | ||||||
| 		u.batchUSGstats(s.SpeedtestStatus, s.Stat.Gw, s.Uplink), | 		u.batchUSGstats(s.SpeedtestStatus, s.Stat.Gw, s.Uplink), | ||||||
| 		map[string]interface{}{ | 		map[string]any{ | ||||||
| 			"ip":            s.IP, | 			"ip":            s.IP, | ||||||
| 			"bytes":         s.Bytes.Val, | 			"bytes":         s.Bytes.Val, | ||||||
| 			"last_seen":     s.LastSeen.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) | 	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 { | 	if gw == nil { | ||||||
| 		return map[string]interface{}{} | 		return map[string]any{} | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	return map[string]interface{}{ | 	return map[string]any{ | ||||||
| 		"uplink_name":                    ul.Name, | 		"uplink_name":                    ul.Name, | ||||||
| 		"uplink_latency":                 ul.Latency.Val, | 		"uplink_latency":                 ul.Latency.Val, | ||||||
| 		"uplink_speed":                   ul.Speed.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, | 			"up":          wan.Up.Txt, | ||||||
| 			"enabled":     wan.Enable.Txt, | 			"enabled":     wan.Enable.Txt, | ||||||
| 		} | 		} | ||||||
| 		fields := map[string]interface{}{ | 		fields := map[string]any{ | ||||||
| 			"bytes-r":      wan.BytesR.Val, | 			"bytes-r":      wan.BytesR.Val, | ||||||
| 			"full_duplex":  wan.FullDuplex.Val, | 			"full_duplex":  wan.FullDuplex.Val, | ||||||
| 			"gateway":      wan.Gateway, | 			"gateway":      wan.Gateway, | ||||||
|  | @ -137,7 +137,7 @@ func (u *InfluxUnifi) batchNetTable(r report, tags map[string]string, nt unifi.N | ||||||
| 			"purpose":     p.Purpose, | 			"purpose":     p.Purpose, | ||||||
| 			"is_guest":    p.IsGuest.Txt, | 			"is_guest":    p.IsGuest.Txt, | ||||||
| 		} | 		} | ||||||
| 		fields := map[string]interface{}{ | 		fields := map[string]any{ | ||||||
| 			"num_sta":    p.NumSta.Val, | 			"num_sta":    p.NumSta.Val, | ||||||
| 			"rx_bytes":   p.RxBytes.Val, | 			"rx_bytes":   p.RxBytes.Val, | ||||||
| 			"rx_packets": p.RxPackets.Val, | 			"rx_packets": p.RxPackets.Val, | ||||||
|  |  | ||||||
|  | @ -27,7 +27,7 @@ func (u *InfluxUnifi) batchUSW(r report, s *unifi.USW) { | ||||||
| 	fields := Combine( | 	fields := Combine( | ||||||
| 		u.batchUSWstat(s.Stat.Sw), | 		u.batchUSWstat(s.Stat.Sw), | ||||||
| 		u.batchSysStats(s.SysStats, s.SystemStats), | 		u.batchSysStats(s.SysStats, s.SystemStats), | ||||||
| 		map[string]interface{}{ | 		map[string]any{ | ||||||
| 			"guest-num_sta":       s.GuestNumSta.Val, | 			"guest-num_sta":       s.GuestNumSta.Val, | ||||||
| 			"ip":                  s.IP, | 			"ip":                  s.IP, | ||||||
| 			"bytes":               s.Bytes.Val, | 			"bytes":               s.Bytes.Val, | ||||||
|  | @ -46,12 +46,12 @@ func (u *InfluxUnifi) batchUSW(r report, s *unifi.USW) { | ||||||
| 	u.batchPortTable(r, tags, s.PortTable) | 	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 { | 	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_bytes":      sw.Bytes.Val, | ||||||
| 		"stat_rx_bytes":   sw.RxBytes.Val, | 		"stat_rx_bytes":   sw.RxBytes.Val, | ||||||
| 		"stat_rx_crypts":  sw.RxCrypts.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_vendor":     p.SFPVendor, | ||||||
| 			"sfp_part":       p.SFPPart, | 			"sfp_part":       p.SFPPart, | ||||||
| 		} | 		} | ||||||
| 		fields := map[string]interface{}{ | 		fields := map[string]any{ | ||||||
| 			"dbytes_r":     p.BytesR.Val, | 			"dbytes_r":     p.BytesR.Val, | ||||||
| 			"rx_broadcast": p.RxBroadcast.Val, | 			"rx_broadcast": p.RxBroadcast.Val, | ||||||
| 			"rx_bytes":     p.RxBytes.Val, | 			"rx_bytes":     p.RxBytes.Val, | ||||||
|  |  | ||||||
|  | @ -29,7 +29,7 @@ func (u *InfluxUnifi) batchUXG(r report, s *unifi.UXG) { // nolint: funlen | ||||||
| 		u.batchUDMtemps(s.Temperatures), | 		u.batchUDMtemps(s.Temperatures), | ||||||
| 		u.batchUSGstats(s.SpeedtestStatus, s.Stat.Gw, s.Uplink), | 		u.batchUSGstats(s.SpeedtestStatus, s.Stat.Gw, s.Uplink), | ||||||
| 		u.batchSysStats(s.SysStats, s.SystemStats), | 		u.batchSysStats(s.SysStats, s.SystemStats), | ||||||
| 		map[string]interface{}{ | 		map[string]any{ | ||||||
| 			"source":        s.SourceName, | 			"source":        s.SourceName, | ||||||
| 			"ip":            s.IP, | 			"ip":            s.IP, | ||||||
| 			"bytes":         s.Bytes.Val, | 			"bytes":         s.Bytes.Val, | ||||||
|  | @ -65,7 +65,7 @@ func (u *InfluxUnifi) batchUXG(r report, s *unifi.UXG) { // nolint: funlen | ||||||
| 	} | 	} | ||||||
| 	fields = Combine( | 	fields = Combine( | ||||||
| 		u.batchUSWstat(s.Stat.Sw), | 		u.batchUSWstat(s.Stat.Sw), | ||||||
| 		map[string]interface{}{ | 		map[string]any{ | ||||||
| 			"guest-num_sta": s.GuestNumSta.Val, | 			"guest-num_sta": s.GuestNumSta.Val, | ||||||
| 			"ip":            s.IP, | 			"ip":            s.IP, | ||||||
| 			"bytes":         s.Bytes.Val, | 			"bytes":         s.Bytes.Val, | ||||||
|  |  | ||||||
|  | @ -10,7 +10,7 @@ import ( | ||||||
| 
 | 
 | ||||||
| /* Event collection. Events are also sent to the webserver for display. */ | /* 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) { | 	if u.isNill(c) { | ||||||
| 		u.Logf("Re-authenticating to UniFi Controller: %s", c.URL) | 		u.Logf("Re-authenticating to UniFi Controller: %s", c.URL) | ||||||
| 
 | 
 | ||||||
|  | @ -20,8 +20,8 @@ func (u *InputUnifi) collectControllerEvents(c *Controller) ([]interface{}, erro | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	var ( | 	var ( | ||||||
| 		logs    = []interface{}{} | 		logs    = []any{} | ||||||
| 		newLogs []interface{} | 		newLogs []any | ||||||
| 	) | 	) | ||||||
| 
 | 
 | ||||||
| 	// Get the sites we care about.
 | 	// 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) | 		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} { | 	for _, call := range []caller{u.collectIDS, u.collectAnomalies, u.collectAlarms, u.collectEvents} { | ||||||
| 		if newLogs, err = call(logs, sites, c); err != nil { | 		if newLogs, err = call(logs, sites, c); err != nil { | ||||||
|  | @ -43,7 +43,7 @@ func (u *InputUnifi) collectControllerEvents(c *Controller) ([]interface{}, erro | ||||||
| 	return logs, nil | 	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 { | 	if *c.SaveAlarms { | ||||||
| 		for _, s := range sites { | 		for _, s := range sites { | ||||||
| 			events, err := c.Unifi.GetAlarmsSite(s) | 			events, err := c.Unifi.GetAlarmsSite(s) | ||||||
|  | @ -67,7 +67,7 @@ func (u *InputUnifi) collectAlarms(logs []interface{}, sites []*unifi.Site, c *C | ||||||
| 	return logs, nil | 	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 { | 	if *c.SaveAnomal { | ||||||
| 		for _, s := range sites { | 		for _, s := range sites { | ||||||
| 			events, err := c.Unifi.GetAnomaliesSite(s) | 			events, err := c.Unifi.GetAnomaliesSite(s) | ||||||
|  | @ -90,7 +90,7 @@ func (u *InputUnifi) collectAnomalies(logs []interface{}, sites []*unifi.Site, c | ||||||
| 	return logs, nil | 	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 { | 	if *c.SaveEvents { | ||||||
| 		for _, s := range sites { | 		for _, s := range sites { | ||||||
| 			events, err := c.Unifi.GetSiteEvents(s, time.Hour) | 			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 | 	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 { | 	if *c.SaveIDS { | ||||||
| 		for _, s := range sites { | 		for _, s := range sites { | ||||||
| 			events, err := c.Unifi.GetIDSSite(s) | 			events, err := c.Unifi.GetIDSSite(s) | ||||||
|  |  | ||||||
|  | @ -84,7 +84,7 @@ func (u *InputUnifi) Events(filter *poller.Filter) (*poller.Events, error) { | ||||||
| 		return nil, nil | 		return nil, nil | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	logs := []interface{}{} | 	logs := []any{} | ||||||
| 
 | 
 | ||||||
| 	if filter == nil { | 	if filter == nil { | ||||||
| 		filter = &poller.Filter{} | 		filter = &poller.Filter{} | ||||||
|  |  | ||||||
|  | @ -184,7 +184,7 @@ func formatDevices(c *Controller, devices *unifi.Devices) (d webserver.Devices) | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| // Logf logs a message.
 | // 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{ | 	webserver.NewInputEvent(PluginName, PluginName, &webserver.Event{ | ||||||
| 		Ts:   time.Now(), | 		Ts:   time.Now(), | ||||||
| 		Msg:  fmt.Sprintf(msg, v...), | 		Msg:  fmt.Sprintf(msg, v...), | ||||||
|  | @ -194,7 +194,7 @@ func (u *InputUnifi) Logf(msg string, v ...interface{}) { | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| // LogErrorf logs an error message.
 | // 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{ | 	webserver.NewInputEvent(PluginName, PluginName, &webserver.Event{ | ||||||
| 		Ts:   time.Now(), | 		Ts:   time.Now(), | ||||||
| 		Msg:  fmt.Sprintf(msg, v...), | 		Msg:  fmt.Sprintf(msg, v...), | ||||||
|  | @ -204,7 +204,7 @@ func (u *InputUnifi) LogErrorf(msg string, v ...interface{}) { | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| // LogDebugf logs a debug message.
 | // 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{ | 	webserver.NewInputEvent(PluginName, PluginName, &webserver.Event{ | ||||||
| 		Ts:   time.Now(), | 		Ts:   time.Now(), | ||||||
| 		Msg:  fmt.Sprintf(msg, v...), | 		Msg:  fmt.Sprintf(msg, v...), | ||||||
|  |  | ||||||
|  | @ -37,7 +37,7 @@ func (l *Loki) httpClient() *Client { | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| // Post marshals and posts a batch of log messages.
 | // 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) | 	msg, err := json.Marshal(logs) | ||||||
| 	if err != nil { | 	if err != nil { | ||||||
| 		return fmt.Errorf("json marshal: %w", err) | 		return fmt.Errorf("json marshal: %w", err) | ||||||
|  |  | ||||||
|  | @ -8,7 +8,7 @@ import ( | ||||||
| ) | ) | ||||||
| 
 | 
 | ||||||
| // Logf logs a message.
 | // 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{ | 	webserver.NewOutputEvent(PluginName, PluginName, &webserver.Event{ | ||||||
| 		Ts:   time.Now(), | 		Ts:   time.Now(), | ||||||
| 		Msg:  fmt.Sprintf(msg, v...), | 		Msg:  fmt.Sprintf(msg, v...), | ||||||
|  | @ -18,7 +18,7 @@ func (l *Loki) Logf(msg string, v ...interface{}) { | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| // LogErrorf logs an error message.
 | // 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{ | 	webserver.NewOutputEvent(PluginName, PluginName, &webserver.Event{ | ||||||
| 		Ts:   time.Now(), | 		Ts:   time.Now(), | ||||||
| 		Msg:  fmt.Sprintf(msg, v...), | 		Msg:  fmt.Sprintf(msg, v...), | ||||||
|  | @ -28,7 +28,7 @@ func (l *Loki) LogErrorf(msg string, v ...interface{}) { | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| // LogDebugf logs a debug message.
 | // 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{ | 	webserver.NewOutputEvent(PluginName, PluginName, &webserver.Event{ | ||||||
| 		Ts:   time.Now(), | 		Ts:   time.Now(), | ||||||
| 		Msg:  fmt.Sprintf(msg, v...), | 		Msg:  fmt.Sprintf(msg, v...), | ||||||
|  |  | ||||||
|  | @ -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 has no notion of "UniFi" or controllers, or Influx, or Prometheus. | ||||||
| This library simply provides an input interface and an output interface. | 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, | 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 | 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 | should provide ample example of how to use this library, but at some point the | ||||||
|  |  | ||||||
|  | @ -78,17 +78,17 @@ type Flags struct { | ||||||
| // Metrics is a type shared by the exporting and reporting packages.
 | // Metrics is a type shared by the exporting and reporting packages.
 | ||||||
| type Metrics struct { | type Metrics struct { | ||||||
| 	TS         time.Time | 	TS         time.Time | ||||||
| 	Sites      []interface{} | 	Sites      []any | ||||||
| 	Clients    []interface{} | 	Clients    []any | ||||||
| 	SitesDPI   []interface{} | 	SitesDPI   []any | ||||||
| 	ClientsDPI []interface{} | 	ClientsDPI []any | ||||||
| 	Devices    []interface{} | 	Devices    []any | ||||||
| 	RogueAPs   []interface{} | 	RogueAPs   []any | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| // Events defines the type for log entries.
 | // Events defines the type for log entries.
 | ||||||
| type Events struct { | type Events struct { | ||||||
| 	Logs []interface{} | 	Logs []any | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| // Config represents the core library input data.
 | // 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.
 | // 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.
 | 	// Parse config file into provided interface.
 | ||||||
| 	if err := cnfgfile.Unmarshal(i, u.Flags.ConfigFile); err != nil { | 	if err := cnfgfile.Unmarshal(i, u.Flags.ConfigFile); err != nil { | ||||||
| 		return fmt.Errorf("cnfg unmarshal: %w", err) | 		return fmt.Errorf("cnfg unmarshal: %w", err) | ||||||
|  |  | ||||||
|  | @ -23,7 +23,7 @@ type Input interface { | ||||||
| // InputPlugin describes an input plugin's consumable interface.
 | // InputPlugin describes an input plugin's consumable interface.
 | ||||||
| type InputPlugin struct { | type InputPlugin struct { | ||||||
| 	Name   string | 	Name   string | ||||||
| 	Config interface{} // Each config is passed into an unmarshaller later.
 | 	Config any // Each config is passed into an unmarshaller later.
 | ||||||
| 	Input | 	Input | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -10,26 +10,26 @@ const callDepth = 2 | ||||||
| 
 | 
 | ||||||
| // Logger is passed into input packages so they may write logs.
 | // Logger is passed into input packages so they may write logs.
 | ||||||
| type Logger interface { | type Logger interface { | ||||||
| 	Logf(m string, v ...interface{}) | 	Logf(m string, v ...any) | ||||||
| 	LogErrorf(m string, v ...interface{}) | 	LogErrorf(m string, v ...any) | ||||||
| 	LogDebugf(m string, v ...interface{}) | 	LogDebugf(m string, v ...any) | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| // Logf prints a log entry if quiet is false.
 | // 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 { | 	if !u.Quiet { | ||||||
| 		_ = log.Output(callDepth, fmt.Sprintf("[INFO] "+m, v...)) | 		_ = log.Output(callDepth, fmt.Sprintf("[INFO] "+m, v...)) | ||||||
| 	} | 	} | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| // LogDebugf prints a debug log entry if debug is true and quite is false.
 | // 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 { | 	if u.Debug && !u.Quiet { | ||||||
| 		_ = log.Output(callDepth, fmt.Sprintf("[DEBUG] "+m, v...)) | 		_ = log.Output(callDepth, fmt.Sprintf("[DEBUG] "+m, v...)) | ||||||
| 	} | 	} | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| // LogErrorf prints an error log entry.
 | // 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...)) | 	_ = log.Output(callDepth, fmt.Sprintf("[ERROR] "+m, v...)) | ||||||
| } | } | ||||||
|  |  | ||||||
|  | @ -28,7 +28,7 @@ type Collect interface { | ||||||
| // Output packages should call NewOutput with this struct in init().
 | // Output packages should call NewOutput with this struct in init().
 | ||||||
| type Output struct { | type Output struct { | ||||||
| 	Name   string | 	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.
 | 	Method func(Collect) error // Called on startup for each configured output.
 | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -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) | 	s, ok := v.(*unifi.DPITable) | ||||||
| 	if !ok { | 	if !ok { | ||||||
| 		u.LogErrorf("invalid type given to ClientsDPI: %T", v) | 		u.LogErrorf("invalid type given to ClientsDPI: %T", v) | ||||||
|  |  | ||||||
|  | @ -71,7 +71,7 @@ type Config struct { | ||||||
| type metric struct { | type metric struct { | ||||||
| 	Desc      *prometheus.Desc | 	Desc      *prometheus.Desc | ||||||
| 	ValueType prometheus.ValueType | 	ValueType prometheus.ValueType | ||||||
| 	Value     interface{} | 	Value     any | ||||||
| 	Labels    []string | 	Labels    []string | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | @ -221,7 +221,7 @@ func (t *target) Describe(ch chan<- *prometheus.Desc) { | ||||||
| // Describe satisfies the prometheus Collector. This returns all of the
 | // Describe satisfies the prometheus Collector. This returns all of the
 | ||||||
| // metric descriptions that this packages produces.
 | // metric descriptions that this packages produces.
 | ||||||
| func (u *promUnifi) Describe(ch chan<- *prometheus.Desc) { | 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)) | 		v := reflect.Indirect(reflect.ValueOf(f)) | ||||||
| 
 | 
 | ||||||
| 		// Loop each struct member and send it to the provided channel.
 | 		// 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) | 	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) { | 	switch v := v.(type) { | ||||||
| 	case *unifi.RogueAP: | 	case *unifi.RogueAP: | ||||||
| 		// r.addRogueAP()
 | 		// r.addRogueAP()
 | ||||||
|  |  | ||||||
|  | @ -8,7 +8,7 @@ import ( | ||||||
| ) | ) | ||||||
| 
 | 
 | ||||||
| // Logf logs a message.
 | // 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{ | 	webserver.NewOutputEvent(PluginName, PluginName, &webserver.Event{ | ||||||
| 		Ts:   time.Now(), | 		Ts:   time.Now(), | ||||||
| 		Msg:  fmt.Sprintf(msg, v...), | 		Msg:  fmt.Sprintf(msg, v...), | ||||||
|  | @ -18,7 +18,7 @@ func (u *promUnifi) Logf(msg string, v ...interface{}) { | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| // LogErrorf logs an error message.
 | // 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{ | 	webserver.NewOutputEvent(PluginName, PluginName, &webserver.Event{ | ||||||
| 		Ts:   time.Now(), | 		Ts:   time.Now(), | ||||||
| 		Msg:  fmt.Sprintf(msg, v...), | 		Msg:  fmt.Sprintf(msg, v...), | ||||||
|  | @ -28,7 +28,7 @@ func (u *promUnifi) LogErrorf(msg string, v ...interface{}) { | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| // LogDebugf logs a debug message.
 | // 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{ | 	webserver.NewOutputEvent(PluginName, PluginName, &webserver.Event{ | ||||||
| 		Ts:   time.Now(), | 		Ts:   time.Now(), | ||||||
| 		Msg:  fmt.Sprintf(msg, v...), | 		Msg:  fmt.Sprintf(msg, v...), | ||||||
|  |  | ||||||
|  | @ -18,7 +18,7 @@ type report interface { | ||||||
| 	metrics() *poller.Metrics | 	metrics() *poller.Metrics | ||||||
| 	report(c poller.Logger, descs map[*prometheus.Desc]bool) | 	report(c poller.Logger, descs map[*prometheus.Desc]bool) | ||||||
| 	export(m *metric, v float64) prometheus.Metric | 	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() | 	addUDM() | ||||||
| 	addUXG() | 	addUXG() | ||||||
| 	addUSG() | 	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...) | 	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++ | 	r.Errors++ | ||||||
| 
 | 
 | ||||||
| 	if r.ReportErrors { | 	if r.ReportErrors { | ||||||
|  |  | ||||||
|  | @ -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) | 	s, ok := v.(*unifi.DPITable) | ||||||
| 	if !ok { | 	if !ok { | ||||||
| 		u.LogErrorf("invalid type given to SiteDPI: %T", v) | 		u.LogErrorf("invalid type given to SiteDPI: %T", v) | ||||||
|  |  | ||||||
|  | @ -39,7 +39,7 @@ func (s *Server) handleConfig(w http.ResponseWriter, r *http.Request) { | ||||||
| 
 | 
 | ||||||
| 	switch vars["sub"] { | 	switch vars["sub"] { | ||||||
| 	case "": | 	case "": | ||||||
| 		data := map[string]interface{}{ | 		data := map[string]any{ | ||||||
| 			"inputs":  s.Collect.Inputs(), | 			"inputs":  s.Collect.Inputs(), | ||||||
| 			"outputs": s.Collect.Outputs(), | 			"outputs": s.Collect.Outputs(), | ||||||
| 			"poller":  s.Collect.Poller(), | 			"poller":  s.Collect.Poller(), | ||||||
|  |  | ||||||
|  | @ -6,7 +6,7 @@ import ( | ||||||
| ) | ) | ||||||
| 
 | 
 | ||||||
| // Logf logs a message.
 | // Logf logs a message.
 | ||||||
| func (s *Server) Logf(msg string, v ...interface{}) { | func (s *Server) Logf(msg string, v ...any) { | ||||||
| 	NewOutputEvent(PluginName, PluginName, &Event{ | 	NewOutputEvent(PluginName, PluginName, &Event{ | ||||||
| 		Ts:   time.Now(), | 		Ts:   time.Now(), | ||||||
| 		Msg:  fmt.Sprintf(msg, v...), | 		Msg:  fmt.Sprintf(msg, v...), | ||||||
|  | @ -16,7 +16,7 @@ func (s *Server) Logf(msg string, v ...interface{}) { | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| // LogErrorf logs an error message.
 | // 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{ | 	NewOutputEvent(PluginName, PluginName, &Event{ | ||||||
| 		Ts:   time.Now(), | 		Ts:   time.Now(), | ||||||
| 		Msg:  fmt.Sprintf(msg, v...), | 		Msg:  fmt.Sprintf(msg, v...), | ||||||
|  | @ -26,7 +26,7 @@ func (s *Server) LogErrorf(msg string, v ...interface{}) { | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| // LogDebugf logs a debug message.
 | // 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{ | 	NewOutputEvent(PluginName, PluginName, &Event{ | ||||||
| 		Ts:   time.Now(), | 		Ts:   time.Now(), | ||||||
| 		Msg:  fmt.Sprintf(msg, v...), | 		Msg:  fmt.Sprintf(msg, v...), | ||||||
|  |  | ||||||
|  | @ -15,7 +15,7 @@ type Input struct { | ||||||
| 	Events       Events | 	Events       Events | ||||||
| 	Devices      Devices | 	Devices      Devices | ||||||
| 	Clients      Clients | 	Clients      Clients | ||||||
| 	Config       interface{} | 	Config       any | ||||||
| 	Counter      map[string]int64 | 	Counter      map[string]int64 | ||||||
| 	sync.RWMutex // Locks this data structure.
 | 	sync.RWMutex // Locks this data structure.
 | ||||||
| } | } | ||||||
|  | @ -27,7 +27,7 @@ type Input struct { | ||||||
| type Output struct { | type Output struct { | ||||||
| 	Name         string | 	Name         string | ||||||
| 	Events       Events | 	Events       Events | ||||||
| 	Config       interface{} | 	Config       any | ||||||
| 	Counter      map[string]int64 | 	Counter      map[string]int64 | ||||||
| 	sync.RWMutex // Locks this data structure.
 | 	sync.RWMutex // Locks this data structure.
 | ||||||
| } | } | ||||||
|  | @ -105,7 +105,7 @@ type Device struct { | ||||||
| 	Type       string `json:"type"` | 	Type       string `json:"type"` | ||||||
| 	Model      string `json:"model"` | 	Model      string `json:"model"` | ||||||
| 	Version    string `json:"version"` | 	Version    string `json:"version"` | ||||||
| 	Config     interface{} `json:"config,omitempty"` | 	Config     any    `json:"config,omitempty"` | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| func (c Devices) Filter(siteid string) (devices []*Device) { | func (c Devices) Filter(siteid string) (devices []*Device) { | ||||||
|  |  | ||||||
|  | @ -89,7 +89,7 @@ func (s *Server) handleDone(w http.ResponseWriter, b []byte, cType string) { | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| // handleJSON sends a json-formatted data reply.
 | // 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) | 	b, err := json.Marshal(data) | ||||||
| 	if err != nil { | 	if err != nil { | ||||||
| 		s.handleError(w, err) | 		s.handleError(w, err) | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue