Skip to content

Commit

Permalink
Merge pull request #69 from inexio/pre-release
Browse files Browse the repository at this point in the history
Pre release
  • Loading branch information
TheFireMike authored Aug 24, 2021
2 parents 5af65f1 + 5d5a039 commit b0cfaaf
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 16 deletions.
22 changes: 11 additions & 11 deletions config/codecommunicator/adva.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,18 @@ func (c *advaCommunicator) GetInterfaces(ctx context.Context) ([]device.Interfac
return nil, err
}

if err = advaGetDWDMInterfaces(ctx, interfaces); err != nil {
if err = c.getDWDMInterfaces(ctx, interfaces); err != nil {
return nil, err
}

if err = advaGetChannels(ctx, interfaces); err != nil {
if err = c.getChannels(ctx, interfaces); err != nil {
return nil, err
}

return normalizeAdvaInterfaces(interfaces), nil
return c.normalizeInterfaces(interfaces), nil
}

func advaGetDWDMInterfaces(ctx context.Context, interfaces []device.Interface) error {
func (c *advaCommunicator) getDWDMInterfaces(ctx context.Context, interfaces []device.Interface) error {
con, ok := network.DeviceConnectionFromContext(ctx)
if !ok || con.SNMP == nil {
return errors.New("no device connection available")
Expand Down Expand Up @@ -80,12 +80,12 @@ func advaGetDWDMInterfaces(ctx context.Context, interfaces []device.Interface) e
txPower[oid[len(oid)-1]], _ = txValue.Mul(decimal.NewFromFloat(0.1)).Float64()
}

rx100Values, err := advaGetPowerValues(ctx, ".1.3.6.1.4.1.2544.1.11.11.7.2.1.1.1.21")
rx100Values, err := c.getPowerValues(ctx, ".1.3.6.1.4.1.2544.1.11.11.7.2.1.1.1.21")
if err != nil {
log.Ctx(ctx).Debug().Err(err).Msg("failed to get rx 100 values")
}

tx100Values, err := advaGetPowerValues(ctx, ".1.3.6.1.4.1.2544.1.11.11.7.2.1.1.1.22")
tx100Values, err := c.getPowerValues(ctx, ".1.3.6.1.4.1.2544.1.11.11.7.2.1.1.1.22")
if err != nil {
log.Ctx(ctx).Debug().Err(err).Msg("failed to get tx 100 values")
}
Expand Down Expand Up @@ -220,7 +220,7 @@ func advaGetDWDMInterfaces(ctx context.Context, interfaces []device.Interface) e
return nil
}

func advaGetChannels(ctx context.Context, interfaces []device.Interface) error {
func (c *advaCommunicator) getChannels(ctx context.Context, interfaces []device.Interface) error {
con, ok := network.DeviceConnectionFromContext(ctx)
if !ok || con.SNMP == nil {
return errors.New("no device connection available")
Expand All @@ -236,7 +236,7 @@ func advaGetChannels(ctx context.Context, interfaces []device.Interface) error {

for _, res := range facilityPhysInstValueInputPowerValues {
subtree := strings.TrimPrefix(res.GetOID(), facilityPhysInstValueInputPower)
if s := strings.Split(strings.Trim(subtree, "."), "."); len(s) > 2 && s[len(s)-2] != "0" {
if s := strings.Split(strings.Trim(subtree, "."), "."); len(s) > 3 && s[len(s)-2] != "0" && s[len(s)-3] == "33152" {
val, err := res.GetValueString()
if err != nil {
return errors.Wrap(err, "failed to get rx value of channel "+subtree)
Expand All @@ -263,7 +263,7 @@ func advaGetChannels(ctx context.Context, interfaces []device.Interface) error {

for _, res := range facilityPhysInstValueOutputPowerValues {
subtree := strings.TrimPrefix(res.GetOID(), facilityPhysInstValueOutputPower)
if s := strings.Split(strings.Trim(subtree, "."), "."); len(s) > 2 && s[len(s)-2] != "0" {
if s := strings.Split(strings.Trim(subtree, "."), "."); len(s) > 3 && s[len(s)-2] != "0" && s[len(s)-3] == "33152" {
val, err := res.GetValueString()
if err != nil {
return errors.Wrap(err, "failed to get tx value of channel "+subtree)
Expand Down Expand Up @@ -306,7 +306,7 @@ func advaGetChannels(ctx context.Context, interfaces []device.Interface) error {
return nil
}

func advaGetPowerValues(ctx context.Context, oid string) (map[string]float64, error) {
func (c *advaCommunicator) getPowerValues(ctx context.Context, oid string) (map[string]float64, error) {
con, ok := network.DeviceConnectionFromContext(ctx)
if !ok || con.SNMP == nil {
return nil, errors.New("no device connection available")
Expand Down Expand Up @@ -347,7 +347,7 @@ func advaGetPowerValues(ctx context.Context, oid string) (map[string]float64, er
return descrToValues, nil
}

func normalizeAdvaInterfaces(interfaces []device.Interface) []device.Interface {
func (c *advaCommunicator) normalizeInterfaces(interfaces []device.Interface) []device.Interface {
var res []device.Interface

for _, interf := range interfaces {
Expand Down
4 changes: 3 additions & 1 deletion config/codecommunicator/ekinops_module_reader_amplifier.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"github.com/inexio/thola/internal/device"
"github.com/inexio/thola/internal/network"
"github.com/pkg/errors"
"github.com/rs/zerolog/log"
"strconv"
"strings"
)
Expand Down Expand Up @@ -52,7 +53,8 @@ func (m *ekinopsModuleReaderAmplifier) readModuleMetrics(ctx context.Context, in
identifier := m.slotIdentifier + "/" + m.moduleName + "/" + strings.Split(*opticalAmplifierInterface.Identifier, "(")[0]
idx, ok := mappings[identifier]
if !ok {
return nil, fmt.Errorf("interface for identifier '%s' not found", identifier)
log.Ctx(ctx).Debug().Msgf("interface for identifier '%s' not found", identifier)
continue
}
interfaces[idx].OpticalAmplifier = &opticalAmplifierInterfaces[i]
interfaces[idx].IfAlias = interfaces[idx].OpticalAmplifier.Label
Expand Down
4 changes: 3 additions & 1 deletion config/codecommunicator/ekinops_module_reader_opm.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"github.com/inexio/thola/internal/device"
"github.com/inexio/thola/internal/network"
"github.com/pkg/errors"
"github.com/rs/zerolog/log"
"strconv"
"strings"
)
Expand Down Expand Up @@ -39,7 +40,8 @@ func (m *ekinopsModuleReaderOPM8) readModuleMetrics(ctx context.Context, interfa
identifier := m.slotIdentifier + "/" + m.moduleName + "/" + strings.Split(*opticalOPMInterface.Identifier, "(")[0]
idx, ok := mappings[identifier]
if !ok {
return nil, fmt.Errorf("interface for identifier '%s' not found", identifier)
log.Ctx(ctx).Debug().Msgf("interface for identifier '%s' not found", identifier)
continue
}
interfaces[idx].OpticalOPM = &opticalOPMInterfaces[i]
interfaces[idx].IfAlias = interfaces[idx].OpticalOPM.Label
Expand Down
5 changes: 3 additions & 2 deletions config/codecommunicator/ekinops_module_reader_transponder.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ package codecommunicator

import (
"context"
"fmt"
"github.com/inexio/thola/internal/device"
"github.com/inexio/thola/internal/network"
"github.com/pkg/errors"
"github.com/rs/zerolog/log"
"strconv"
"strings"
)
Expand Down Expand Up @@ -53,7 +53,8 @@ func (m *ekinopsModuleReaderTransponder) readModuleMetrics(ctx context.Context,
identifier := m.slotIdentifier + "/" + m.moduleName + "/" + strings.Split(*opticalTransponderInterface.Identifier, "(")[0]
idx, ok := mappings[identifier]
if !ok {
return nil, fmt.Errorf("interface for identifier '%s' not found", identifier)
log.Ctx(ctx).Debug().Msgf("interface for identifier '%s' not found", identifier)
continue
}
interfaces[idx].OpticalTransponder = &OpticalTransponderInterfaces[i]
interfaces[idx].IfAlias = interfaces[idx].OpticalTransponder.Label
Expand Down
4 changes: 3 additions & 1 deletion config/codecommunicator/timos.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"github.com/inexio/thola/internal/device"
"github.com/inexio/thola/internal/network"
"github.com/pkg/errors"
"github.com/rs/zerolog/log"
"strconv"
"strings"
)
Expand Down Expand Up @@ -38,7 +39,8 @@ func (c *timosCommunicator) GetInterfaces(ctx context.Context) ([]device.Interfa
sapDescriptionsOID := ".1.3.6.1.4.1.6527.3.1.2.4.3.2.1.5"
sapDescriptions, err := con.SNMP.SnmpClient.SNMPWalk(ctx, sapDescriptionsOID)
if err != nil {
return nil, errors.Wrap(err, "snmpwalk failed")
log.Ctx(ctx).Debug().Err(err).Msg("sap interfaces are not available on this device")
return interfaces, nil
}

for _, response := range sapDescriptions {
Expand Down

0 comments on commit b0cfaaf

Please sign in to comment.