Skip to content

Commit

Permalink
logging cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
TheFireMike committed May 10, 2021
1 parent 1633ac5 commit a7e7306
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 29 deletions.
4 changes: 0 additions & 4 deletions core/communicator/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand Down
18 changes: 8 additions & 10 deletions core/communicator/device_class.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}

Expand Down Expand Up @@ -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())
}

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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")
}
Expand Down Expand Up @@ -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
}
Expand Down
11 changes: 0 additions & 11 deletions core/communicator/device_class_to_code_communicator.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{},
},
}
*/
4 changes: 0 additions & 4 deletions core/request/get_communicator.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,13 @@ 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")
}

var invalidCache bool
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")
Expand All @@ -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 {
Expand All @@ -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
Expand Down

0 comments on commit a7e7306

Please sign in to comment.