Skip to content

Commit

Permalink
Merge pull request #92 from inexio/pre-release
Browse files Browse the repository at this point in the history
Pre release
  • Loading branch information
TheFireMike authored Dec 15, 2021
2 parents fb69565 + c04cd5c commit 4be94c5
Show file tree
Hide file tree
Showing 9 changed files with 250 additions and 20 deletions.
6 changes: 3 additions & 3 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -205,20 +205,20 @@ func handleRequest(r request.Request) {

db, err := database.GetDB(ctx)
if err != nil {
handleError(ctx, err)
handleError(ctx, err, r)
os.Exit(3)
}

resp, err := request.ProcessRequest(ctx, r)
if err != nil {
handleError(ctx, err)
handleError(ctx, err, r)
_ = db.CloseConnection(ctx)
os.Exit(3)
}

err = db.CloseConnection(ctx)
if err != nil {
handleError(ctx, err)
handleError(ctx, err, r)
os.Exit(3)
}

Expand Down
2 changes: 1 addition & 1 deletion cmd/root_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ func handleRequest(r request.Request) {

resp, err := request.ProcessRequest(ctx, r)
if err != nil {
handleError(ctx, err)
handleError(ctx, err, r)
os.Exit(3)
}

Expand Down
11 changes: 9 additions & 2 deletions cmd/shared.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,15 @@ func getBaseRequest(host string) request.BaseRequest {
}
}

func handleError(ctx context.Context, err error) {
b, err := parser.Parse(err, viper.GetString("format"))
func handleError(ctx context.Context, err error, r request.Request) {
var v interface{}
res, err2 := r.HandlePreProcessError(err)
if err2 != nil {
v = err2
} else {
v = res
}
b, err := parser.Parse(v, viper.GetString("format"))
if err != nil {
log.Ctx(ctx).Error().AnErr("parse_error", err).AnErr("original_error", err).Msg("failed to parse error")
} else {
Expand Down
168 changes: 160 additions & 8 deletions config/codecommunicator/aviat.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ import (
"github.com/inexio/thola/internal/deviceclass/groupproperty"
"github.com/inexio/thola/internal/network"
"github.com/pkg/errors"
"strings"
"github.com/rs/zerolog/log"
"strconv"
)

type aviatCommunicator struct {
Expand All @@ -24,10 +25,29 @@ func (c *aviatCommunicator) GetInterfaces(ctx context.Context, filter ...grouppr
return nil, errors.New("snmp client is empty")
}

var channels []device.RadioChannel

// entPhysicalName
res, err := con.SNMP.SnmpClient.SNMPWalk(ctx, "1.3.6.1.2.1.47.1.1.1.1.7")
if err != nil {
log.Ctx(ctx).Debug().Err(err).Msg("failed to get entPhysicalName")
return interfaces, nil
}

names := make(map[string]string)
for _, r := range res {
nameVal, err := r.GetValue()
if err != nil {
return nil, errors.Wrap(err, "failed to get entPhysicalName value")
}
names[r.GetOID().GetIndex()] = nameVal.String()
}

// aviatModemStatusMaxCapacity
res, err := con.SNMP.SnmpClient.SNMPWalk(ctx, "1.3.6.1.4.1.2509.9.3.2.4.1.1")
res, err = con.SNMP.SnmpClient.SNMPWalk(ctx, "1.3.6.1.4.1.2509.9.3.2.4.1.1")
if err != nil {
return nil, errors.Wrap(err, "failed to get aviatModemStatusMaxCapacity")
log.Ctx(ctx).Debug().Err(err).Msg("failed to get aviatModemStatusMaxCapacity")
return interfaces, nil
}

var maxCapacity uint64
Expand All @@ -46,7 +66,8 @@ func (c *aviatCommunicator) GetInterfaces(ctx context.Context, filter ...grouppr
// aviatModemCurCapacityTx
res, err = con.SNMP.SnmpClient.SNMPWalk(ctx, "1.3.6.1.4.1.2509.9.3.2.1.1.11")
if err != nil {
return nil, errors.Wrap(err, "failed to get aviatModemCurCapacityTx")
log.Ctx(ctx).Debug().Err(err).Msg("failed to get aviatModemCurCapacityTx")
return interfaces, nil
}

var maxBitRateTx uint64
Expand All @@ -59,13 +80,31 @@ func (c *aviatCommunicator) GetInterfaces(ctx context.Context, filter ...grouppr
if err != nil {
return nil, errors.Wrap(err, "failed to parse aviatModemCurCapacityTx value")
}
maxBitRateTx += bitRate * 1000
bitRate = bitRate * 1000
maxBitRateTx += bitRate

target := names[r.GetOID().GetIndex()]
found := false
for i, channel := range channels {
if channel.Channel != nil && *channel.Channel == target {
channels[i].MaxbitrateOut = &bitRate
found = true
break
}
}
if !found {
channels = append(channels, device.RadioChannel{
Channel: &target,
MaxbitrateOut: &bitRate,
})
}
}

// aviatModemCurCapacityRx
res, err = con.SNMP.SnmpClient.SNMPWalk(ctx, "1.3.6.1.4.1.2509.9.3.2.1.1.12")
if err != nil {
return nil, errors.Wrap(err, "failed to get aviatModemCurCapacityRx")
log.Ctx(ctx).Debug().Err(err).Msg("failed to get aviatModemCurCapacityRx")
return interfaces, nil
}

var maxBitRateRx uint64
Expand All @@ -78,16 +117,129 @@ func (c *aviatCommunicator) GetInterfaces(ctx context.Context, filter ...grouppr
if err != nil {
return nil, errors.Wrap(err, "failed to parse aviatModemCurCapacityRx value")
}
maxBitRateRx += bitRate * 1000
bitRate = bitRate * 1000
maxBitRateRx += bitRate

target := names[r.GetOID().GetIndex()]
found := false
for i, channel := range channels {
if channel.Channel != nil && *channel.Channel == target {
channels[i].MaxbitrateIn = &bitRate
found = true
break
}
}
if !found {
channels = append(channels, device.RadioChannel{
Channel: &target,
MaxbitrateIn: &bitRate,
})
}
}

// aviatRxPerformRslReadingCurrent
res, err = con.SNMP.SnmpClient.SNMPWalk(ctx, "1.3.6.1.4.1.2509.9.15.2.2.1.4")
if err != nil {
log.Ctx(ctx).Debug().Err(err).Msg("failed to get aviatRxPerformRslReadingCurrent")
return interfaces, nil
}

for _, r := range res {
levelInVal, err := r.GetValue()
if err != nil {
return nil, errors.Wrap(err, "failed to get aviatRxPerformRslReadingCurrent value")
}
levelIn, err := levelInVal.Float64()
if err != nil {
return nil, errors.Wrap(err, "failed to parse aviatRxPerformRslReadingCurrent value")
}
levelIn = levelIn / 10

target := names[r.GetOID().GetIndex()]
found := false
for i, channel := range channels {
if channel.Channel != nil && *channel.Channel == target {
channels[i].LevelIn = &levelIn
found = true
break
}
}
if !found {
channels = append(channels, device.RadioChannel{
Channel: &target,
LevelIn: &levelIn,
})
}
}

// aviatRxPerformTxpowReadingCurrent
res, err = con.SNMP.SnmpClient.SNMPWalk(ctx, "1.3.6.1.4.1.2509.9.33.2.2.1.7")
if err != nil {
log.Ctx(ctx).Debug().Err(err).Msg("failed to get aviatRxPerformTxpowReadingCurrent")
return interfaces, nil
}

for _, r := range res {
levelOutVal, err := r.GetValue()
if err != nil {
return nil, errors.Wrap(err, "failed to get aviatRxPerformTxpowReadingCurrent value")
}
levelOut, err := levelOutVal.Float64()
if err != nil {
return nil, errors.Wrap(err, "failed to parse aviatRxPerformTxpowReadingCurrent value")
}
levelOut = levelOut / 10

target := names[r.GetOID().GetIndex()]
found := false
for i, channel := range channels {
if channel.Channel != nil && *channel.Channel == target {
channels[i].LevelOut = &levelOut
found = true
break
}
}
if !found {
channels = append(channels, device.RadioChannel{
Channel: &target,
LevelOut: &levelOut,
})
}
}

var radioIfIndex *uint64

// ifType
res, err = con.SNMP.SnmpClient.SNMPWalk(ctx, "1.3.6.1.2.1.2.2.1.3")
if err != nil {
log.Ctx(ctx).Debug().Err(err).Msg("failed to get ifType")
return interfaces, nil
}

for _, r := range res {
ifTypeVal, err := r.GetValue()
if err != nil {
return nil, errors.Wrap(err, "failed to get ifType value")
}

if ifTypeVal.String() == "188" {
ifIndex, err := strconv.ParseUint(r.GetOID().GetIndex(), 10, 64)
if err != nil {
return nil, errors.Wrap(err, "failed to parse ifIndex value")
}
radioIfIndex = &ifIndex
break
}
}

for i, interf := range interfaces {
if interf.IfName != nil && strings.HasPrefix(*interf.IfName, "Radio") {
if interf.IfIndex != nil && radioIfIndex != nil && *interf.IfIndex == *radioIfIndex {
interfaces[i].MaxSpeedIn = &maxCapacity
interfaces[i].MaxSpeedOut = &maxCapacity
interfaces[i].Radio = &device.RadioInterface{
MaxbitrateOut: &maxBitRateTx,
MaxbitrateIn: &maxBitRateRx,
Channels: channels,
}
}
}
Expand Down
16 changes: 16 additions & 0 deletions config/deviceclass/generic/ceraos.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,22 @@ components:
value:
detection: constant
value: 1000
rx_frequency:
oid: 1.3.6.1.4.1.2281.10.5.2.1.4
operators:
- type: modify
modify_method: divide
value:
detection: constant
value: 1000
tx_frequency:
oid: 1.3.6.1.4.1.2281.10.5.2.1.3
operators:
- type: modify
modify_method: divide
value:
detection: constant
value: 1000

memory:
properties:
Expand Down
24 changes: 20 additions & 4 deletions internal/device/device.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,10 +169,26 @@ type EthernetLikeInterface struct {
//
// swagger:model
type RadioInterface struct {
LevelOut *int64 `yaml:"level_out" json:"level_out" xml:"level_out" mapstructure:"level_out"`
LevelIn *int64 `yaml:"level_in" json:"level_in" xml:"level_in" mapstructure:"level_in"`
MaxbitrateOut *uint64 `yaml:"maxbitrate_out" json:"maxbitrate_out" xml:"maxbitrate_out" mapstructure:"maxbitrate_out"`
MaxbitrateIn *uint64 `yaml:"maxbitrate_in" json:"maxbitrate_in" xml:"maxbitrate_in" mapstructure:"maxbitrate_in"`
LevelIn *int64 `yaml:"level_in" json:"level_in" xml:"level_in" mapstructure:"level_in"`
LevelOut *int64 `yaml:"level_out" json:"level_out" xml:"level_out" mapstructure:"level_out"`
MaxbitrateIn *uint64 `yaml:"maxbitrate_in" json:"maxbitrate_in" xml:"maxbitrate_in" mapstructure:"maxbitrate_in"`
MaxbitrateOut *uint64 `yaml:"maxbitrate_out" json:"maxbitrate_out" xml:"maxbitrate_out" mapstructure:"maxbitrate_out"`
RXFrequency *float64 `yaml:"rx_frequency" json:"rx_frequency" xml:"rx_frequency" mapstructure:"rx_frequency"`
TXFrequency *float64 `yaml:"tx_frequency" json:"tx_frequency" xml:"tx_frequency" mapstructure:"tx_frequency"`
Channels []RadioChannel `yaml:"channels" json:"channels" xml:"channels" mapstructure:"channels"`
}

// RadioChannel
//
// RadioChannel represents a radio channel.
//
// swagger:model
type RadioChannel struct {
Channel *string `yaml:"channel" json:"channel" xml:"channel" mapstructure:"channel"`
LevelIn *float64 `yaml:"level_in" json:"level_in" xml:"level_in" mapstructure:"level_in"`
LevelOut *float64 `yaml:"level_out" json:"level_out" xml:"level_out" mapstructure:"level_out"`
MaxbitrateIn *uint64 `yaml:"maxbitrate_in" json:"maxbitrate_in" xml:"maxbitrate_in" mapstructure:"maxbitrate_in"`
MaxbitrateOut *uint64 `yaml:"maxbitrate_out" json:"maxbitrate_out" xml:"maxbitrate_out" mapstructure:"maxbitrate_out"`
}

// DWDMInterface
Expand Down
35 changes: 35 additions & 0 deletions internal/request/check_interface_metrics_process.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,9 @@ func (r *CheckInterfaceMetricsRequest) getFilter() []groupproperty.Filter {
groupproperty.GetValueFilter([]string{"ifSpecific"}),
// VLANs
groupproperty.GetValueFilter([]string{"vlan"}),
// Radio
groupproperty.GetValueFilter([]string{"radio", "rx_frequency"}),
groupproperty.GetValueFilter([]string{"radio", "tx_frequency"}),
}

if !r.PrintInterfaces {
Expand Down Expand Up @@ -431,6 +434,38 @@ func addCheckInterfacePerformanceData(interfaces []device.Interface, r *monitori
return err
}
}

for _, channel := range i.Radio.Channels {
if channel.Channel != nil {
if channel.LevelIn != nil {
err := r.AddPerformanceDataPoint(monitoringplugin.NewPerformanceDataPoint("level_in", *channel.LevelIn).SetLabel(*i.IfDescr + "_" + *channel.Channel))
if err != nil {
return err
}
}

if channel.LevelOut != nil {
err := r.AddPerformanceDataPoint(monitoringplugin.NewPerformanceDataPoint("level_out", *channel.LevelOut).SetLabel(*i.IfDescr + "_" + *channel.Channel))
if err != nil {
return err
}
}

if channel.MaxbitrateIn != nil {
err := r.AddPerformanceDataPoint(monitoringplugin.NewPerformanceDataPoint("interface_maxbitrate_in", *channel.MaxbitrateIn).SetLabel(*i.IfDescr + "_" + *channel.Channel))
if err != nil {
return err
}
}

if channel.MaxbitrateOut != nil {
err := r.AddPerformanceDataPoint(monitoringplugin.NewPerformanceDataPoint("interface_maxbitrate_out", *channel.MaxbitrateOut).SetLabel(*i.IfDescr + "_" + *channel.Channel))
if err != nil {
return err
}
}
}
}
}

//DWDM interface metrics
Expand Down
4 changes: 4 additions & 0 deletions test/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,10 @@ func sendRequests(input chan testDevice, output chan statistics) {
for {
select {
case testDevice := <-input:
if len(testDevice.requestTypes) == 0 {
stats.success[testDevice.info.getIdentifier()] = "success"
continue
}
r, err := testDevice.info.generateRequest(testDevice.requestTypes[0])
if err != nil {
stats.failed[testDevice.info.getIdentifier()] = fmt.Sprintf("generating new request failed: %s", err.Error())
Expand Down
4 changes: 2 additions & 2 deletions test/testdata/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ services:
- snmpsim1
- snmpsim2
snmpsim1:
image: thola/snmpsim:latest
image: ghcr.io/inexio/snmpsim:latest
volumes:
- ${THOLA_TEST_SNMPRECDIR}:/usr/local/snmpsim/data/
snmpsim2:
image: thola/snmpsim:latest
image: ghcr.io/inexio/snmpsim:latest
volumes:
- ${THOLA_TEST_SNMPRECDIR}:/usr/local/snmpsim/data/

0 comments on commit 4be94c5

Please sign in to comment.