Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

expose more params for snmp #760

Merged
merged 2 commits into from Jan 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions go.mod
Expand Up @@ -18,7 +18,7 @@ require (
github.com/gogo/protobuf v1.3.2
github.com/golang/protobuf v1.5.3
github.com/golang/snappy v0.0.4
github.com/gosnmp/gosnmp v1.35.0
github.com/gosnmp/gosnmp v1.37.0
github.com/hashicorp/consul/api v1.15.3
github.com/influxdata/line-protocol/v2 v2.2.1
github.com/jackc/pgx/v4 v4.17.2
Expand Down Expand Up @@ -232,7 +232,7 @@ require (
github.com/golang-sql/sqlexp v0.1.0 // indirect
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da
github.com/google/gnostic v0.5.7-v3refs // indirect
github.com/google/go-cmp v0.5.9
github.com/google/go-cmp v0.6.0
github.com/google/go-querystring v1.1.0 // indirect
github.com/google/gofuzz v1.2.0 // indirect
github.com/google/gopacket v1.1.19
Expand Down
8 changes: 4 additions & 4 deletions go.sum
Expand Up @@ -602,8 +602,8 @@ github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/
github.com/google/go-cmp v0.5.6/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-cmp v0.5.7/go.mod h1:n+brtR0CgQNWTVd5ZUFpTBC8YFBDLK/h/bpaJ8/DtOE=
github.com/google/go-cmp v0.5.8/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38=
github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
github.com/google/go-querystring v1.1.0 h1:AnCroh3fv4ZBgVIf1Iwtovgjaw/GiKJo8M8yD/fhyJ8=
github.com/google/go-querystring v1.1.0/go.mod h1:Kcdr2DB4koayq7X8pmAG4sNG59So17icRSOU623lUBU=
github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
Expand Down Expand Up @@ -656,8 +656,8 @@ github.com/gorilla/sessions v1.2.1/go.mod h1:dk2InVEVJ0sfLlnXv9EAgkf6ecYs/i80K/z
github.com/gorilla/websocket v0.0.0-20170926233335-4201258b820c/go.mod h1:E7qHFY5m1UJ88s3WnNqhKjPHQ0heANvMoAMk2YaljkQ=
github.com/gorilla/websocket v1.4.2 h1:+/TMaTYc4QFitKJxsQ7Yye35DkWvkdLcvGKqM+x0Ufc=
github.com/gorilla/websocket v1.4.2/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
github.com/gosnmp/gosnmp v1.35.0 h1:EuWWNPxTCdAUx2/NbQcSa3WdNxjzpy4Phv57b4MWpJM=
github.com/gosnmp/gosnmp v1.35.0/go.mod h1:2AvKZ3n9aEl5TJEo/fFmf/FGO4Nj4cVeEc5yuk88CYc=
github.com/gosnmp/gosnmp v1.37.0 h1:/Tf8D3b9wrnNuf/SfbvO+44mPrjVphBhRtcGg22V07Y=
github.com/gosnmp/gosnmp v1.37.0/go.mod h1:GDH9vNqpsD7f2HvZhKs5dlqSEcAS6s6Qp099oZRCR+M=
github.com/grafana/regexp v0.0.0-20220304095617-2e8d9baf4ac2 h1:uirlL/j72L93RhV4+mkWhjv0cov2I0MIgPOG9rMDr1k=
github.com/grafana/regexp v0.0.0-20220304095617-2e8d9baf4ac2/go.mod h1:M5qHK+eWfAv8VR/265dIuEpL3fNfeC21tXXp9itM24A=
github.com/gregjones/httpcache v0.0.0-20180305231024-9cad4c3443a7/go.mod h1:FecbI9+v66THATjSRHfNgh1IVFe/9kFxbXtjV0ctIMA=
Expand Down
4 changes: 4 additions & 0 deletions inputs/snmp/snmp.go
Expand Up @@ -58,6 +58,10 @@ type ClientConfig struct {
EngineID string `toml:"-"`
EngineBoots uint32 `toml:"-"`
EngineTime uint32 `toml:"-"`

// AppOpts
AppOpts map[string]interface{} `toml:"app_opts"`
MaxOids int `toml:"max_oids"`
}

// Snmp holds the configuration for the plugin.
Expand Down
26 changes: 18 additions & 8 deletions inputs/snmp/wrapper.go
Expand Up @@ -2,12 +2,16 @@ package snmp

import (
"fmt"
"log"
"net/url"
"os"
"strconv"
"strings"
"time"

"github.com/gosnmp/gosnmp"

coreconfig "flashcat.cloud/categraf/config"
)

// GosnmpWrapper wraps a *gosnmp.GoSNMP object so we can use it as a snmpConnection.
Expand All @@ -30,17 +34,25 @@ func (gs GosnmpWrapper) Walk(oid string, fn gosnmp.WalkFunc) error {
}

func NewWrapper(s ClientConfig) (GosnmpWrapper, error) {
var logger gosnmp.Logger
if coreconfig.Config.DebugMode {
logger = gosnmp.NewLogger(log.New(os.Stdout, "", 0))
}

gs := GosnmpWrapper{&gosnmp.GoSNMP{
Timeout: 5 * time.Second,
Timeout: time.Duration(s.Timeout),
AppOpts: s.AppOpts,
Logger: logger,
MaxOids: s.MaxOids,
MaxRepetitions: s.MaxRepetitions,
Retries: s.Retries,
UseUnconnectedUDPSocket: s.UnconnectedUDPSocket,
}}

if s.Timeout != 0 {
gs.Timeout = time.Duration(s.Timeout)
if gs.Timeout == 0 {
gs.Timeout = 6 * time.Second
}

gs.Retries = s.Retries
gs.UseUnconnectedUDPSocket = s.UnconnectedUDPSocket

switch s.Version {
case 3:
gs.Version = gosnmp.Version3
Expand All @@ -60,8 +72,6 @@ func NewWrapper(s ClientConfig) (GosnmpWrapper, error) {
}
}

gs.MaxRepetitions = s.MaxRepetitions

if s.Version == 3 {
gs.ContextName = s.ContextName

Expand Down