Skip to content

Commit

Permalink
Merge pull request #80 from inexio/pre-release
Browse files Browse the repository at this point in the history
Pre release
  • Loading branch information
TheFireMike authored Sep 30, 2021
2 parents d91be08 + 7ba02f6 commit 0103769
Show file tree
Hide file tree
Showing 28 changed files with 454 additions and 445 deletions.
70 changes: 35 additions & 35 deletions config/codecommunicator/adva.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,15 +49,15 @@ func (c *advaCommunicator) getDWDMInterfaces(ctx context.Context, interfaces []d
rxPower := make(map[string]float64)

for _, resp := range rxPowerRaw {
res, err := resp.GetValueString()
res, err := resp.GetValue()
if err != nil {
return errors.Wrap(err, "failed to convert rx power to string")
}
rxValue, err := decimal.NewFromString(res)
rxValue, err := decimal.NewFromString(res.String())
if err != nil {
return errors.Wrap(err, "failed to convert rx power to decimal")
}
oid := strings.Split(resp.GetOID(), ".")
oid := strings.Split(resp.GetOID().String(), ".")
rxPower[oid[len(oid)-1]], _ = rxValue.Mul(decimal.NewFromFloat(0.1)).Float64()
}

Expand All @@ -69,15 +69,15 @@ func (c *advaCommunicator) getDWDMInterfaces(ctx context.Context, interfaces []d
txPower := make(map[string]float64)

for _, resp := range txPowerRaw {
res, err := resp.GetValueString()
res, err := resp.GetValue()
if err != nil {
return errors.Wrap(err, "failed to convert tx power to string")
}
txValue, err := decimal.NewFromString(res)
txValue, err := decimal.NewFromString(res.String())
if err != nil {
return errors.Wrap(err, "failed to convert tx power to decimal")
}
oid := strings.Split(resp.GetOID(), ".")
oid := strings.Split(resp.GetOID().String(), ".")
txPower[oid[len(oid)-1]], _ = txValue.Mul(decimal.NewFromFloat(0.1)).Float64()
}

Expand Down Expand Up @@ -110,14 +110,14 @@ func (c *advaCommunicator) getDWDMInterfaces(ctx context.Context, interfaces []d
}

// corrected fec 15m
res, err := con.SNMP.SnmpClient.SNMPGet(ctx, ".1.3.6.1.4.1.2544.1.11.2.6.2.180.1.2."+fmt.Sprint(*interf.IfIndex)+".1")
res, err := con.SNMP.SnmpClient.SNMPGet(ctx, network.OID(".1.3.6.1.4.1.2544.1.11.2.6.2.180.1.2.").AddSuffix(fmt.Sprint(*interf.IfIndex)+".1"))
if err == nil && len(res) == 1 {
valString, err := res[0].GetValueString()
val, err := res[0].GetValue()
if err != nil {
return errors.Wrap(err, "failed to get corrected 15m bit error rate string value for interface "+fmt.Sprint(*interf.IfIndex))
}

val, err := strconv.ParseFloat(valString, 64)
valFloat, err := val.Float64()
if err != nil {
return errors.Wrap(err, "failed to parse corrected 15m bit error rate for interface "+fmt.Sprint(*interf.IfIndex))
}
Expand All @@ -128,19 +128,19 @@ func (c *advaCommunicator) getDWDMInterfaces(ctx context.Context, interfaces []d

interfaces[i].DWDM.CorrectedFEC = append(interfaces[i].DWDM.CorrectedFEC, device.Rate{
Time: "15m",
Value: val,
Value: valFloat,
})
}

// uncorrected fec 15m
res, err = con.SNMP.SnmpClient.SNMPGet(ctx, ".1.3.6.1.4.1.2544.1.11.2.6.2.180.1.3."+fmt.Sprint(*interf.IfIndex)+".1")
res, err = con.SNMP.SnmpClient.SNMPGet(ctx, network.OID(".1.3.6.1.4.1.2544.1.11.2.6.2.180.1.3.").AddSuffix(fmt.Sprint(*interf.IfIndex)+".1"))
if err == nil && len(res) == 1 {
valString, err := res[0].GetValueString()
val, err := res[0].GetValue()
if err != nil {
return errors.Wrap(err, "failed to get uncorrected 15m bit error rate string value for interface "+fmt.Sprint(*interf.IfIndex))
}

val, err := strconv.ParseFloat(valString, 64)
valFloat, err := val.Float64()
if err != nil {
return errors.Wrap(err, "failed to parse uncorrected 15m bit error rate for interface "+fmt.Sprint(*interf.IfIndex))
}
Expand All @@ -151,19 +151,19 @@ func (c *advaCommunicator) getDWDMInterfaces(ctx context.Context, interfaces []d

interfaces[i].DWDM.UncorrectedFEC = append(interfaces[i].DWDM.UncorrectedFEC, device.Rate{
Time: "15m",
Value: val,
Value: valFloat,
})
}

// corrected fec 1d
res, err = con.SNMP.SnmpClient.SNMPGet(ctx, ".1.3.6.1.4.1.2544.1.11.2.6.2.181.1.2."+fmt.Sprint(*interf.IfIndex)+".1")
res, err = con.SNMP.SnmpClient.SNMPGet(ctx, network.OID(".1.3.6.1.4.1.2544.1.11.2.6.2.181.1.2.").AddSuffix(fmt.Sprint(*interf.IfIndex)+".1"))
if err == nil && len(res) == 1 {
valString, err := res[0].GetValueString()
val, err := res[0].GetValue()
if err != nil {
return errors.Wrap(err, "failed to get corrected 1d bit error rate string value for interface "+fmt.Sprint(*interf.IfIndex))
}

val, err := strconv.ParseFloat(valString, 64)
valFloat, err := val.Float64()
if err != nil {
return errors.Wrap(err, "failed to parse corrected 1d bit error rate for interface "+fmt.Sprint(*interf.IfIndex))
}
Expand All @@ -174,19 +174,19 @@ func (c *advaCommunicator) getDWDMInterfaces(ctx context.Context, interfaces []d

interfaces[i].DWDM.CorrectedFEC = append(interfaces[i].DWDM.CorrectedFEC, device.Rate{
Time: "1d",
Value: val,
Value: valFloat,
})
}

// uncorrected fec 1d
res, err = con.SNMP.SnmpClient.SNMPGet(ctx, ".1.3.6.1.4.1.2544.1.11.2.6.2.181.1.3."+fmt.Sprint(*interf.IfIndex)+".1")
res, err = con.SNMP.SnmpClient.SNMPGet(ctx, network.OID(".1.3.6.1.4.1.2544.1.11.2.6.2.181.1.3.").AddSuffix(fmt.Sprint(*interf.IfIndex)+".1"))
if err == nil && len(res) == 1 {
valString, err := res[0].GetValueString()
valFloat, err := res[0].GetValue()
if err != nil {
return errors.Wrap(err, "failed to get uncorrected 1d bit error rate string value for interface "+fmt.Sprint(*interf.IfIndex))
}

val, err := strconv.ParseFloat(valString, 64)
val, err := valFloat.Float64()
if err != nil {
return errors.Wrap(err, "failed to parse uncorrected 1d bit error rate for interface "+fmt.Sprint(*interf.IfIndex))
}
Expand Down Expand Up @@ -229,20 +229,20 @@ func (c *advaCommunicator) getChannels(ctx context.Context, interfaces []device.

channels := make(map[string]device.OpticalChannel)

facilityPhysInstValueInputPower := ".1.3.6.1.4.1.2544.1.11.11.7.2.1.1.1.2"
facilityPhysInstValueInputPower := network.OID(".1.3.6.1.4.1.2544.1.11.11.7.2.1.1.1.2")
facilityPhysInstValueInputPowerValues, err := con.SNMP.SnmpClient.SNMPWalk(ctx, facilityPhysInstValueInputPower)
if err != nil {
log.Ctx(ctx).Debug().Err(err).Msg("failed to walk facilityPhysInstValueInputPower")
}

for _, res := range facilityPhysInstValueInputPowerValues {
subtree := strings.TrimPrefix(res.GetOID(), facilityPhysInstValueInputPower)
subtree := strings.TrimPrefix(res.GetOID().String(), facilityPhysInstValueInputPower.String())
if s := strings.Split(strings.Trim(subtree, "."), "."); len(s) > 3 && s[len(s)-2] != "0" && s[len(s)-3] == "33152" {
val, err := res.GetValueString()
val, err := res.GetValue()
if err != nil {
return errors.Wrap(err, "failed to get rx value of channel "+subtree)
}
a, err := decimal.NewFromString(val)
a, err := decimal.NewFromString(val.String())
if err != nil {
return errors.Wrap(err, "failed to parse rx value of channel "+subtree)
}
Expand All @@ -256,20 +256,20 @@ func (c *advaCommunicator) getChannels(ctx context.Context, interfaces []device.
}
}

facilityPhysInstValueOutputPower := ".1.3.6.1.4.1.2544.1.11.11.7.2.1.1.1.1"
facilityPhysInstValueOutputPower := network.OID(".1.3.6.1.4.1.2544.1.11.11.7.2.1.1.1.1")
facilityPhysInstValueOutputPowerValues, err := con.SNMP.SnmpClient.SNMPWalk(ctx, facilityPhysInstValueOutputPower)
if err != nil {
log.Ctx(ctx).Debug().Err(err).Msg("failed to walk facilityPhysInstValueOutputPower")
}

for _, res := range facilityPhysInstValueOutputPowerValues {
subtree := strings.TrimPrefix(res.GetOID(), facilityPhysInstValueOutputPower)
subtree := strings.TrimPrefix(res.GetOID().String(), facilityPhysInstValueOutputPower.String())
if s := strings.Split(strings.Trim(subtree, "."), "."); len(s) > 3 && s[len(s)-2] != "0" && s[len(s)-3] == "33152" {
val, err := res.GetValueString()
val, err := res.GetValue()
if err != nil {
return errors.Wrap(err, "failed to get tx value of channel "+subtree)
}
a, err := decimal.NewFromString(val)
a, err := decimal.NewFromString(val.String())
if err != nil {
return errors.Wrap(err, "failed to parse tx value of channel "+subtree)
}
Expand Down Expand Up @@ -307,31 +307,31 @@ func (c *advaCommunicator) getChannels(ctx context.Context, interfaces []device.
return nil
}

func (c *advaCommunicator) getPowerValues(ctx context.Context, oid string) (map[string]float64, error) {
func (c *advaCommunicator) getPowerValues(ctx context.Context, oid network.OID) (map[string]float64, error) {
con, ok := network.DeviceConnectionFromContext(ctx)
if !ok || con.SNMP == nil {
return nil, errors.New("no device connection available")
}

values, err := con.SNMP.SnmpClient.SNMPWalk(ctx, oid)
if err != nil {
return nil, errors.Wrap(err, "failed to walk "+oid)
return nil, errors.Wrap(err, "failed to walk "+oid.String())
}

descrToValues := make(map[string]float64)

for _, val := range values {
subtree := strings.TrimPrefix(val.GetOID(), oid)
subtree := strings.TrimPrefix(val.GetOID().String(), oid.String())
subtreeSplit := strings.Split(strings.Trim(subtree, "."), ".")
if len(subtreeSplit) < 3 {
return nil, errors.New("invalid value for oid " + oid)
return nil, errors.New("invalid value for oid " + oid.String())
}

valueString, err := val.GetValueString()
value, err := val.GetValue()
if err != nil {
return nil, errors.Wrap(err, "failed to get rx value")
}
valueDecimal, err := decimal.NewFromString(valueString)
valueDecimal, err := decimal.NewFromString(value.String())
if err != nil {
return nil, errors.Wrap(err, "failed to parse rx value")
}
Expand Down
13 changes: 6 additions & 7 deletions config/codecommunicator/aviat.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"github.com/inexio/thola/internal/deviceclass/groupproperty"
"github.com/inexio/thola/internal/network"
"github.com/pkg/errors"
"strconv"
"strings"
)

Expand All @@ -33,11 +32,11 @@ func (c *aviatCommunicator) GetInterfaces(ctx context.Context, filter ...grouppr

var maxCapacity uint64
for _, r := range res {
capacityString, err := r.GetValueString()
capacityVal, err := r.GetValue()
if err != nil {
return nil, errors.Wrap(err, "failed to get aviatModemStatusMaxCapacity value")
}
capacity, err := strconv.ParseUint(capacityString, 10, 64)
capacity, err := capacityVal.UInt64()
if err != nil {
return nil, errors.Wrap(err, "failed to parse aviatModemStatusMaxCapacity value")
}
Expand All @@ -52,11 +51,11 @@ func (c *aviatCommunicator) GetInterfaces(ctx context.Context, filter ...grouppr

var maxBitRateTx uint64
for _, r := range res {
bitRateString, err := r.GetValueString()
bitRateVal, err := r.GetValue()
if err != nil {
return nil, errors.Wrap(err, "failed to get aviatModemCurCapacityTx value")
}
bitRate, err := strconv.ParseUint(bitRateString, 10, 64)
bitRate, err := bitRateVal.UInt64()
if err != nil {
return nil, errors.Wrap(err, "failed to parse aviatModemCurCapacityTx value")
}
Expand All @@ -71,11 +70,11 @@ func (c *aviatCommunicator) GetInterfaces(ctx context.Context, filter ...grouppr

var maxBitRateRx uint64
for _, r := range res {
bitRateString, err := r.GetValueString()
bitRateVal, err := r.GetValue()
if err != nil {
return nil, errors.Wrap(err, "failed to get aviatModemCurCapacityRx value")
}
bitRate, err := strconv.ParseUint(bitRateString, 10, 64)
bitRate, err := bitRateVal.UInt64()
if err != nil {
return nil, errors.Wrap(err, "failed to parse aviatModemCurCapacityRx value")
}
Expand Down
6 changes: 3 additions & 3 deletions config/codecommunicator/ekinops.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,17 +44,17 @@ func (c *ekinopsCommunicator) GetInterfaces(ctx context.Context, filter ...group
var moduleReaders []ekinopsModuleReader

for k, slotResult := range slotResults {
slotIdentifier, err := slotResult.GetValueString()
slotIdentifier, err := slotResult.GetValue()
if err != nil {
return nil, errors.Wrap(err, "failed to get snmp result as string")
}

module, err := moduleResults[k].GetValueString()
module, err := moduleResults[k].GetValue()
if err != nil {
return nil, errors.Wrap(err, "failed to get module result as string")
}

moduleReader, err := ekinopsGetModuleReader(slotIdentifier, module)
moduleReader, err := ekinopsGetModuleReader(slotIdentifier.String(), module.String())
if err != nil {
log.Ctx(ctx).Debug().Err(err).Msgf("no information for reading out ekinops module '%s' available", module)
continue
Expand Down
33 changes: 17 additions & 16 deletions config/codecommunicator/ekinops_module_reader_amplifier.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"github.com/inexio/thola/internal/network"
"github.com/pkg/errors"
"github.com/rs/zerolog/log"
"strconv"
"strings"
)

Expand All @@ -18,11 +17,11 @@ type ekinopsModuleReaderAmplifier struct {
}

type ekinopsAmplifierOIDs struct {
identifierOID string
labelOID string
txPowerOID string
rxPowerOID string
gainOID string
identifierOID network.OID
labelOID network.OID
txPowerOID network.OID
rxPowerOID network.OID
gainOID network.OID

powerTransformFunc ekinopsPowerTransformFunc
}
Expand Down Expand Up @@ -81,16 +80,18 @@ func ekinopsReadAmplifierMetrics(ctx context.Context, oids ekinopsAmplifierOIDs)
var opticalAmplifierInterfaces []device.OpticalAmplifierInterface
for k, identifierResult := range identifierResults {
var opticalAmplifierInterface device.OpticalAmplifierInterface
identifier, err := identifierResult.GetValueString()
identifier, err := identifierResult.GetValue()
if err != nil {
return nil, errors.Wrap(err, "failed to get identifier for optical amplifier interface")
}
label, err := labelResults[k].GetValueString()
identifierString := identifier.String()
label, err := labelResults[k].GetValue()
if err != nil {
return nil, errors.Wrap(err, "failed to get label for optical amplifier interface")
}
opticalAmplifierInterface.Identifier = &identifier
opticalAmplifierInterface.Label = &label
labelString := label.String()
opticalAmplifierInterface.Identifier = &identifierString
opticalAmplifierInterface.Label = &labelString
opticalAmplifierInterfaces = append(opticalAmplifierInterfaces, opticalAmplifierInterface)
}

Expand All @@ -103,11 +104,11 @@ func ekinopsReadAmplifierMetrics(ctx context.Context, oids ekinopsAmplifierOIDs)
if err != nil {
return nil, errors.Wrap(err, "snmpget failed for tx power oid failed")
}
avStr, err := txPowerResult[0].GetValueString()
avVal, err := txPowerResult[0].GetValue()
if err != nil {
return nil, errors.Wrap(err, "snmpget failed for tx power oid failed")
}
av, err := strconv.ParseFloat(avStr, 64)
av, err := avVal.Float64()
if err != nil {
return nil, errors.Wrap(err, "failed to parse snmp response to float64")
}
Expand All @@ -119,11 +120,11 @@ func ekinopsReadAmplifierMetrics(ctx context.Context, oids ekinopsAmplifierOIDs)
if err != nil {
return nil, errors.Wrap(err, "snmpget failed for rx power oid failed")
}
avStr, err = rxPowerResult[0].GetValueString()
avVal, err = rxPowerResult[0].GetValue()
if err != nil {
return nil, errors.Wrap(err, "snmpget failed for rx power oid failed")
}
av, err = strconv.ParseFloat(avStr, 64)
av, err = avVal.Float64()
if err != nil {
return nil, errors.Wrap(err, "failed to parse snmp response to float64")
}
Expand All @@ -135,11 +136,11 @@ func ekinopsReadAmplifierMetrics(ctx context.Context, oids ekinopsAmplifierOIDs)
if err != nil {
return nil, errors.Wrap(err, "snmpget failed for gain oid failed")
}
avStr, err = gainResult[0].GetValueString()
avVal, err = gainResult[0].GetValue()
if err != nil {
return nil, errors.Wrap(err, "snmpget failed for gain oid failed")
}
av, err = strconv.ParseFloat(avStr, 64)
av, err = avVal.Float64()
if err != nil {
return nil, errors.Wrap(err, "failed to parse gain to float64")
}
Expand Down
Loading

0 comments on commit 0103769

Please sign in to comment.