Skip to content

Commit

Permalink
Merge branch 'main' into feature-snmpv3
Browse files Browse the repository at this point in the history
  • Loading branch information
TheFireMike authored May 5, 2021
2 parents cf14584 + 2b73c3e commit 700eaad
Showing 1 changed file with 6 additions and 29 deletions.
35 changes: 6 additions & 29 deletions core/network/snmp_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,9 @@ import (

// SNMPClient is used to communicate via snmp.
type SNMPClient struct {
client *gosnmp.GoSNMP
useCache bool
getCache requestCache
walkCache requestCache
client *gosnmp.GoSNMP
useCache bool
getCache requestCache
}

type snmpClientCreation struct {
Expand Down Expand Up @@ -270,10 +269,9 @@ func newSNMPClientTestConnection(client *gosnmp.GoSNMP) (*SNMPClient, error) {
client.ExponentialTimeout = true

return &SNMPClient{
client: client,
useCache: true,
getCache: newRequestCache(),
walkCache: newRequestCache(),
client: client,
useCache: true,
getCache: newRequestCache(),
}, nil
}

Expand Down Expand Up @@ -415,17 +413,6 @@ func (s *SNMPClient) SNMPGet(ctx context.Context, oid ...string) ([]SNMPResponse

// SNMPWalk sends a snmpwalk request to the specified oid.
func (s *SNMPClient) SNMPWalk(ctx context.Context, oid string) ([]SNMPResponse, error) {
if s.useCache {
x, err := s.walkCache.get(oid)
if err == nil {
res, ok := x.res.([]SNMPResponse)
if !ok {
return nil, errors.New("cached snmp result is not a snmp response")
}
return res, nil
}
}

s.client.Context = ctx

var response []gosnmp.SnmpPDU
Expand All @@ -441,17 +428,11 @@ func (s *SNMPClient) SNMPWalk(ctx context.Context, oid string) ([]SNMPResponse,
}
if err != nil {
err = errors.Wrap(err, "snmpwalk failed")
if s.useCache {
s.walkCache.add(oid, nil, err)
}
return nil, err
}

if response == nil {
err = tholaerr.NewNotFoundError("No Such Object available on this agent at this OID")
if s.useCache {
s.walkCache.add(oid, nil, err)
}
return nil, err
}

Expand All @@ -473,10 +454,6 @@ func (s *SNMPClient) SNMPWalk(ctx context.Context, oid string) ([]SNMPResponse,
}
}

if s.useCache {
s.walkCache.add(oid, res, nil)
}

return res, nil
}

Expand Down

0 comments on commit 700eaad

Please sign in to comment.