From a7e7306e112607a2788310a84277a4c03ce6f291 Mon Sep 17 00:00:00 2001 From: mikameyer Date: Mon, 10 May 2021 13:29:47 +0200 Subject: [PATCH] logging cleanup --- core/communicator/create.go | 4 ---- core/communicator/device_class.go | 18 ++++++++---------- .../device_class_to_code_communicator.go | 11 ----------- core/request/get_communicator.go | 4 ---- 4 files changed, 8 insertions(+), 29 deletions(-) diff --git a/core/communicator/create.go b/core/communicator/create.go index aa9aa17..420d8e0 100644 --- a/core/communicator/create.go +++ b/core/communicator/create.go @@ -5,14 +5,12 @@ import ( "github.com/inexio/thola/core/network" "github.com/inexio/thola/core/tholaerr" "github.com/pkg/errors" - "github.com/rs/zerolog/log" ) // CreateNetworkDeviceCommunicator creates a communicator. func CreateNetworkDeviceCommunicator(ctx context.Context, deviceClassIdentifier string) (NetworkDeviceCommunicator, error) { deviceClass, err := getDeviceClass(deviceClassIdentifier) if err != nil { - log.Ctx(ctx).Error().Err(err).Msg("failed to get device class") return nil, errors.Wrap(err, "error during GetDeviceClasses") } return createCommunicatorByDeviceClass(ctx, deviceClass) @@ -22,7 +20,6 @@ func CreateNetworkDeviceCommunicator(ctx context.Context, deviceClassIdentifier func IdentifyNetworkDeviceCommunicator(ctx context.Context) (NetworkDeviceCommunicator, error) { deviceClass, err := identifyDeviceClass(ctx) if err != nil { - log.Ctx(ctx).Error().Err(err).Msg("failed to identify device class") return nil, errors.Wrap(err, "error during IdentifyDeviceClass") } com, err := createCommunicatorByDeviceClass(ctx, deviceClass) @@ -36,7 +33,6 @@ func IdentifyNetworkDeviceCommunicator(ctx context.Context) (NetworkDeviceCommun func MatchDeviceClass(ctx context.Context, identifier string) (bool, error) { deviceClass, err := getDeviceClass(identifier) if err != nil { - log.Ctx(ctx).Error().Err(err).Msg("failed to get device class") return false, errors.Wrap(err, "error during GetDeviceClasses") } return deviceClass.matchDevice(ctx) diff --git a/core/communicator/device_class.go b/core/communicator/device_class.go index d7c31b9..d41d531 100644 --- a/core/communicator/device_class.go +++ b/core/communicator/device_class.go @@ -289,7 +289,6 @@ var genericDeviceClass struct { func identifyDeviceClass(ctx context.Context) (*deviceClass, error) { deviceClasses, err := getDeviceClasses() if err != nil { - log.Ctx(ctx).Error().Err(err).Msg("failed to load device classes") return nil, errors.Wrap(err, "error during getDeviceClasses") } @@ -325,7 +324,6 @@ func identifyDeviceClassRecursive(ctx context.Context, devClass map[string]*devi log.Ctx(ctx).Trace().Msgf("starting device class match (%s)", devClass.getName()) match, err := devClass.matchDevice(ctx) if err != nil { - log.Ctx(ctx).Error().Err(err).Msg("error during device class match") return nil, errors.Wrap(err, "error while trying to match device class: "+devClass.getName()) } @@ -755,8 +753,8 @@ func (y *yamlComponentsOID) convert() (deviceClassOID, error) { }, nil } -func (d *deviceClassOID) validate() error { - if err := d.OID.Validate(); err != nil { +func (y *yamlComponentsOID) validate() error { + if err := y.OID.Validate(); err != nil { return errors.Wrap(err, "oid is invalid") } return nil @@ -1703,12 +1701,12 @@ func interface2GroupPropertyReader(i interface{}, parentGroupPropertyReader grou if _, ok := m["values"]; !ok { return nil, errors.New("values are missing") } - oidReader, err := interface2oidReader(m["values"]) + reader, err := interface2oidReader(m["values"]) if err != nil { return nil, errors.Wrap(err, "failed to parse oid reader") } - devClassOIDs, ok := oidReader.(*deviceClassOIDs) + devClassOIDs, ok := reader.(*deviceClassOIDs) if !ok { return nil, errors.New("oid reader is no list of oids") } @@ -1766,13 +1764,13 @@ func interface2oidReader(i interface{}) (oidReader, error) { if err != nil { return nil, errors.Wrap(err, "failed to decode values map to yamlComponentsOIDs") } - devClassOID, err := oid.convert() + err = oid.validate() if err != nil { - return nil, errors.Wrap(err, "failed to convert yaml OID to device class OID") + return nil, errors.Wrapf(err, "oid reader for %s is invalid", valString) } - err = devClassOID.validate() + devClassOID, err := oid.convert() if err != nil { - return nil, errors.Wrap(err, "snmpwalk group property reader is invalid") + return nil, errors.Wrap(err, "failed to convert yaml OID to device class OID") } result[valString] = &devClassOID } diff --git a/core/communicator/device_class_to_code_communicator.go b/core/communicator/device_class_to_code_communicator.go index 0a91a93..f3b8bff 100644 --- a/core/communicator/device_class_to_code_communicator.go +++ b/core/communicator/device_class_to_code_communicator.go @@ -30,14 +30,3 @@ func getCodeCommunicator(classIdentifier string, rel *relatedNetworkDeviceCommun } return nil, tholaerr.NewNotFoundError(fmt.Sprintf("no communicator found for device class identifier '%s'", classIdentifier)) } - -/* -func addCodePropertyReader(class string, reader string) -var codePropertyReaderMappings = make(map[string]map[string]propertyReader) -var copeGroupPropertyReaderMappings = map[string]map[string]groupPropertyReader{ - "ceraos/ip10": { - "IfTable": &ceraosIP10GetIfTableGPR{}, - }, -} - -*/ diff --git a/core/request/get_communicator.go b/core/request/get_communicator.go index d8ab8c8..f19d6e5 100644 --- a/core/request/get_communicator.go +++ b/core/request/get_communicator.go @@ -16,7 +16,6 @@ import ( func GetCommunicator(ctx context.Context, baseRequest BaseRequest) (communicator.NetworkDeviceCommunicator, error) { db, err := database.GetDB(ctx) if err != nil { - log.Ctx(ctx).Error().Err(err).Msg("failed to get DB") return nil, errors.Wrap(err, "failed to get DB") } @@ -24,7 +23,6 @@ func GetCommunicator(ctx context.Context, baseRequest BaseRequest) (communicator deviceProperties, err := db.GetDeviceProperties(ctx, baseRequest.DeviceData.IPAddress) if err != nil { if !tholaerr.IsNotFoundError(err) { - log.Ctx(ctx).Error().Err(err).Msg("failed to get device properties from cache") return nil, errors.Wrap(err, "failed to get device properties from cache") } log.Ctx(ctx).Trace().Msg("no device properties found in cache") @@ -33,7 +31,6 @@ func GetCommunicator(ctx context.Context, baseRequest BaseRequest) (communicator log.Ctx(ctx).Trace().Msg("found device properties in cache, starting to validate") res, err := communicator.MatchDeviceClass(ctx, deviceProperties.Class) if err != nil { - log.Ctx(ctx).Error().Err(err).Msg("failed to match device class") return nil, errors.Wrap(err, "failed to match device class") } if invalidCache = !res; invalidCache { @@ -46,7 +43,6 @@ func GetCommunicator(ctx context.Context, baseRequest BaseRequest) (communicator identifyRequest := IdentifyRequest{BaseRequest: baseRequest} res, err := identifyRequest.process(ctx) if err != nil { - log.Ctx(ctx).Error().Err(err).Msg("failed to run identify") return nil, errors.Wrap(err, "failed to run identify") } deviceProperties = res.(*IdentifyResponse).Device