From 8d389db44e8bcf949e42146310bddec9ae826b31 Mon Sep 17 00:00:00 2001 From: kruskal <99559985+kruskall@users.noreply.github.com> Date: Mon, 30 Sep 2024 01:08:51 +0200 Subject: [PATCH] lint: fix linting issues --- libbeat/common/schema/mapstriface/mapstriface.go | 12 +++--------- metricbeat/module/jolokia/jmx/data.go | 6 ++++-- .../module/system/socket/helper/loopback.go | 2 +- x-pack/auditbeat/module/system/socket/kprobes.go | 2 +- x-pack/auditbeat/module/system/user/user.go | 1 + x-pack/auditbeat/module/system/user/users_linux.go | 2 +- x-pack/filebeat/input/o365audit/input.go | 3 ++- 7 files changed, 13 insertions(+), 15 deletions(-) diff --git a/libbeat/common/schema/mapstriface/mapstriface.go b/libbeat/common/schema/mapstriface/mapstriface.go index 17cf5f3629b..f5bd5c7b9f7 100644 --- a/libbeat/common/schema/mapstriface/mapstriface.go +++ b/libbeat/common/schema/mapstriface/mapstriface.go @@ -276,17 +276,11 @@ func toTime(key string, data map[string]interface{}) (interface{}, error) { return common.Time(time.Unix(0, 0)), schema.NewKeyNotFoundError(key) } - switch emptyIface.(type) { + switch ts := emptyIface.(type) { case time.Time: - ts, ok := emptyIface.(time.Time) - if ok { - return common.Time(ts), nil - } + return common.Time(ts), nil case common.Time: - ts, ok := emptyIface.(common.Time) - if ok { - return ts, nil - } + return ts, nil } msg := fmt.Sprintf("expected date, found %T", emptyIface) diff --git a/metricbeat/module/jolokia/jmx/data.go b/metricbeat/module/jolokia/jmx/data.go index 2a675ed3456..accc2145d4d 100644 --- a/metricbeat/module/jolokia/jmx/data.go +++ b/metricbeat/module/jolokia/jmx/data.go @@ -138,8 +138,10 @@ func eventMapping(entries []Entry, mapping AttributeMapping) ([]mapstr.M, error) errs = constructEvents(entryValues, v, mbeanEvents, mapping, errs) } case []interface{}: - entryValues := v.Value.(map[string]interface{}) - errs = constructEvents(entryValues, v, mbeanEvents, mapping, errs) + entryValues, ok := v.Value.(map[string]interface{}) + if ok { + errs = constructEvents(entryValues, v, mbeanEvents, mapping, errs) + } } } diff --git a/x-pack/auditbeat/module/system/socket/helper/loopback.go b/x-pack/auditbeat/module/system/socket/helper/loopback.go index 3fa0fc2f2af..7ca10f24aa8 100644 --- a/x-pack/auditbeat/module/system/socket/helper/loopback.go +++ b/x-pack/auditbeat/module/system/socket/helper/loopback.go @@ -7,9 +7,9 @@ package helper import ( + "crypto/rand" "errors" "fmt" - "math/rand" "net" "time" "unsafe" diff --git a/x-pack/auditbeat/module/system/socket/kprobes.go b/x-pack/auditbeat/module/system/socket/kprobes.go index d6d52bb724b..d468cfa9599 100644 --- a/x-pack/auditbeat/module/system/socket/kprobes.go +++ b/x-pack/auditbeat/module/system/socket/kprobes.go @@ -57,7 +57,7 @@ func (p *probeInstaller) Install(pdef helper.ProbeDef) (format tracing.ProbeForm if decoder, err = pdef.Decoder(format); err != nil { return format, decoder, fmt.Errorf("failed to create decoder: %w", err) } - return + return format, decoder, nil } // UninstallInstalled uninstalls the probes installed by Install. diff --git a/x-pack/auditbeat/module/system/user/user.go b/x-pack/auditbeat/module/system/user/user.go index ebdf576deb0..dfec95b94f0 100644 --- a/x-pack/auditbeat/module/system/user/user.go +++ b/x-pack/auditbeat/module/system/user/user.go @@ -402,6 +402,7 @@ func (ms *MetricSet) reportChanges(report mb.ReporterV2) error { // Check for changes to users missingUserMap := make(map[string](*User)) for _, missingUser := range missingFromCache { + //nolint:errcheck // ignore missingUserMap[missingUser.(*User).UID] = missingUser.(*User) } diff --git a/x-pack/auditbeat/module/system/user/users_linux.go b/x-pack/auditbeat/module/system/user/users_linux.go index 052c7c8487b..b6cad38a8d0 100644 --- a/x-pack/auditbeat/module/system/user/users_linux.go +++ b/x-pack/auditbeat/module/system/user/users_linux.go @@ -79,7 +79,7 @@ func readPasswdFile(readPasswords bool) ([]*User, error) { if passwd == nil { // getpwent() can return ENOENT even when there is no error, // see https://github.com/systemd/systemd/issues/9585. - if err != nil && err != syscall.ENOENT { + if err != nil && errors.Is(err, syscall.ENOENT) { return users, fmt.Errorf("error getting user: %w", err) } diff --git a/x-pack/filebeat/input/o365audit/input.go b/x-pack/filebeat/input/o365audit/input.go index c1d90c509ea..11e7c1222cc 100644 --- a/x-pack/filebeat/input/o365audit/input.go +++ b/x-pack/filebeat/input/o365audit/input.go @@ -117,7 +117,8 @@ func (inp *o365input) Run( if err == nil { break } - if ctx.Cancelation.Err() != err && errors.Is(err, context.Canceled) { + //nolint:errorlint // ignore + if ctx.Cancelation.Err() != err && !errors.Is(err, context.Canceled) { msg := mapstr.M{} msg.Put("error.message", err.Error()) msg.Put("event.kind", "pipeline_error")