Skip to content

Commit

Permalink
cpu component for ios
Browse files Browse the repository at this point in the history
  • Loading branch information
babos77 committed Dec 9, 2020
1 parent 3ba1e42 commit a352ab7
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 1 deletion.
1 change: 0 additions & 1 deletion core/communicator/ceraos-ip10.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ type ceraosIP10Communicator struct {
}

func (c *ceraosIP10Communicator) GetIfTable(ctx context.Context) ([]device.Interface, error) {

subInterfaces, err := c.sub.GetIfTable(ctx)
if err != nil {
return nil, errors.Wrap(err, "an unexpected error occurred while trying to get ifTable of sub communicator")
Expand Down
2 changes: 2 additions & 0 deletions core/communicator/device_class_to_code_communicator.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ func getCodeCommunicator(classIdentifier string, rel *relatedNetworkDeviceCommun
return &poweronePCCCommunicator{baseCommunicator{rel}}, nil
case "ironware":
return &ironwareCommunicator{baseCommunicator{rel}}, nil
case "ios":
return &iosCommunicator{baseCommunicator{rel}}, nil
}
return nil, tholaerr.NewNotFoundError(fmt.Sprintf("no communicator found for device class identifier '%s'", classIdentifier))
}
34 changes: 34 additions & 0 deletions core/communicator/ios.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package communicator

import (
"context"
"github.com/inexio/thola/core/network"
"github.com/pkg/errors"
"strconv"
)

type iosCommunicator struct {
baseCommunicator
}

func (c *iosCommunicator) GetCPUComponentCPULoad(ctx context.Context) ([]float64, error) {
con, ok := network.DeviceConnectionFromContext(ctx)
if !ok || con.SNMP == nil {
return nil, errors.New("no device connection available")
}
var cpus []float64

res, _ := con.SNMP.SnmpClient.SNMPWalk(ctx, "1.3.6.1.4.1.9.9.109.1.1.1.1.5")
for _, snmpres := range res {
s, err := snmpres.GetValueString()
if err != nil {
return nil, err
}
f, err := strconv.ParseFloat(s, 64)
if err != nil {
return nil, errors.Wrap(err, "failed to parse snmp response to float64")
}
cpus = append(cpus, f)
}
return cpus, nil
}
2 changes: 2 additions & 0 deletions core/config/device-classes/generic/ios.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ name: ios
config:
snmp:
max_repetitions: 1
components:
cpuComponent: true

match:
conditions:
Expand Down

0 comments on commit a352ab7

Please sign in to comment.