Skip to content
This repository has been archived by the owner on Sep 19, 2023. It is now read-only.

Commit

Permalink
Merge pull request #85 from GuessWhoSamFoo/vio-2303
Browse files Browse the repository at this point in the history
Fallback to non-bulk snmp walk on initial failure
  • Loading branch information
GuessWhoSamFoo authored Jun 3, 2022
2 parents 40f5f8b + f22a709 commit b9a2523
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
17 changes: 14 additions & 3 deletions pkg/snmp/core/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,7 @@ func (d *DeviceConfig) ToMap() (m map[string]interface{}, err error) {
// SnmpClient is a thin wrapper around gosnmp.
type SnmpClient struct {
DeviceConfig *DeviceConfig
SupportBulk bool
}

// NewSnmpClient constructs SnmpClient.
Expand All @@ -295,6 +296,7 @@ func NewSnmpClient(deviceConfig *DeviceConfig) (*SnmpClient, error) {

return &SnmpClient{
DeviceConfig: deviceConfig,
SupportBulk: true,
}, nil
}

Expand Down Expand Up @@ -346,9 +348,18 @@ func (client *SnmpClient) Walk(rootOid string) (results []ReadResult, err error)
return nil, err
}

resultSet, err := goSnmp.BulkWalkAll(rootOid)
if err != nil {
return nil, err
var resultSet []gosnmp.SnmpPDU

if client.SupportBulk {
resultSet, err = goSnmp.BulkWalkAll(rootOid)
if err != nil {
client.SupportBulk = false
}
} else {
resultSet, err = goSnmp.WalkAll(rootOid)
if err != nil {
return nil, err
}
}

defer func() {
Expand Down
4 changes: 2 additions & 2 deletions pkg/snmp/servers/snmp_server_factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ package servers

import (
"fmt"
"strings"
log "github.com/sirupsen/logrus"
"strings"
)

// CreateSnmpServer creates a SnmpServer from the configuration data model string.
Expand Down Expand Up @@ -39,7 +39,7 @@ func CreateSnmpServer(data map[string]interface{}) (server *SnmpServer, err erro
if model == "SU10000RT3UPM" {
var trippliteups *TrippliteUps
trippliteups, err = NewTrippliteUps(data)
log.Debugf("Error is: [%s]", err)
log.Errorf("Error is: [%s]", err)
if err == nil {
server = trippliteups.SnmpServer
return
Expand Down

0 comments on commit b9a2523

Please sign in to comment.