Merge pull request #447 from unpoller/interface-to-any

go 1.19 interface{} -> any
This commit is contained in:
Cody Lee 2022-12-03 17:35:08 -05:00 committed by GitHub
commit 85e4bbefd8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
36 changed files with 120 additions and 120 deletions

View File

@ -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)

View File

@ -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)

View File

@ -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...)
}

View File

@ -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)
}

View File

@ -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)
}

View File

@ -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] {

View File

@ -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,

View File

@ -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,

View File

@ -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:

View File

@ -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)

View File

@ -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...),

View File

@ -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,

View File

@ -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,

View File

@ -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,

View File

@ -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,

View File

@ -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,

View File

@ -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,

View File

@ -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)

View File

@ -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{}

View File

@ -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...),

View File

@ -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)

View File

@ -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...),

View File

@ -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

View File

@ -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)

View File

@ -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
}

View File

@ -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...))
}

View File

@ -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.
}

View File

@ -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)

View File

@ -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()

View File

@ -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...),

View File

@ -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 {

View File

@ -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)

View File

@ -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(),

View File

@ -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...),

View File

@ -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) {

View File

@ -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)