diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 6c8e4c2..99f4f36 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -16,6 +16,15 @@ jobs: - name: Build run: go build ./cmd/snmp-proxy + build-no-netsnmp: + name: Build without netsnmp + runs-on: ubuntu-18.04 + steps: + - uses: actions/checkout@v2 + - uses: actions/setup-go@v2 + - name: Build + run: go build -tags=nonetsnmp ./cmd/snmp-proxy + test: name: Test runs-on: ubuntu-18.04 @@ -29,6 +38,19 @@ jobs: - name: Run tests run: make test + test-no-netsnmp: + name: Test without netsnmp + runs-on: ubuntu-18.04 + steps: + - uses: actions/checkout@v2 + - uses: actions/setup-go@v2 + - name: Install dependencies + run: sudo apt update && sudo apt install python3-pip + - name: Install snmpsim + run: sudo pip3 install snmpsim + - name: Run tests + run: GO_TEST_FLAGS=-tags=nonetsnmp make test + coverage: name: Code Coverage runs-on: ubuntu-18.04 @@ -42,7 +64,7 @@ jobs: - name: Download go-acc run: GO111MODULE=off go get -u github.com/ory/go-acc - name: Generate Code Coverage - run: $(go env GOPATH)/bin/go-acc --covermode set --output coverage.cov ./... + run: GO_ACC="$(go env GOPATH)/bin/go-acc" make coverage - name: Send coverage uses: shogo82148/actions-goveralls@v1 with: diff --git a/.goreleaser.yaml b/.goreleaser.yaml index df9cc5c..b267672 100644 --- a/.goreleaser.yaml +++ b/.goreleaser.yaml @@ -1,14 +1,27 @@ archives: - - files: + - builds: + - default + files: - LICENSE - README.md - config.toml.dist - - id: binary + - builds: + - default + id: binary format: binary name_template: snmp-proxy + - id: no-netsnmp + builds: + - no-netsnmp + files: + - LICENSE + - README.md + - config.toml.dist + name_template: "{{ .ProjectName }}-no-netsnmp_{{ .Version }}_{{ .Os }}_{{ .Arch }}" builds: - - main: ./cmd/snmp-proxy + - id: default + main: ./cmd/snmp-proxy binary: snmp-proxy env: - CGO_ENABLED=1 @@ -17,6 +30,18 @@ builds: goarch: - amd64 + - id: no-netsnmp + main: ./cmd/snmp-proxy + binary: snmp-proxy + flags: + - -tags=nonetsnmp + goos: + - linux + - darwin +# - windows # todo need to figure out how to deal with panicwatch + goarch: + - amd64 + checksum: name_template: 'checksums.txt' diff --git a/Makefile b/Makefile index 9ba492e..fd8c183 100644 --- a/Makefile +++ b/Makefile @@ -1,3 +1,4 @@ +GO_ACC ?= go-acc export BIN = ${PWD}/bin export GOBIN = $(BIN) @@ -20,9 +21,17 @@ fix: $(BIN)/golangci-lint .PHONY: test test: - timeout 300 go test ./... - timeout 300 go test --race ./... - timeout 300 go test --count 100 ./... + timeout 300 go test $(GO_TEST_FLAGS) ./... + timeout 300 go test $(GO_TEST_FLAGS) --race ./... + timeout 300 go test $(GO_TEST_FLAGS) --count 100 ./... + +.PHONY: coverage +coverage: + $(GO_ACC) --covermode set --output coverage.cov --ignore ./snmpproxy/mib ./... + $(GO_ACC) --covermode set --output coverage-netsnmp.cov ./snmpproxy/mib + $(GO_ACC) --covermode set --output coverage-nonetsnmp.cov ./snmpproxy/mib -- -tags=nonetsnmp + cat coverage-netsnmp.cov coverage-nonetsnmp.cov | grep -v 'mode: ' >> coverage.cov + rm coverage-netsnmp.cov coverage-nonetsnmp.cov .PHONY: clean clean: diff --git a/README.md b/README.md index b8c656b..7b79b11 100644 --- a/README.md +++ b/README.md @@ -107,6 +107,9 @@ so that it knows how to format them. MIB parsing was inspired by In case that OID is of the type OctetString, and it isn't found in the MIBs, then we try to detect whether the string is printable (utf8 valid + all characters are printable). If it isn't, it's formatted as `AB C0 D5 D6...`. +MIBs parsing can be skipped by using a binary built with `-tags=nonetsnmp`. +These binaries are also available in the [Releases](https://github.com/grongor/go-snmp-proxy/releases). + Metrics ------- @@ -117,11 +120,14 @@ of `POST /snmp-proxy` requests (count, durations). Shared libraries ---------------- -You will have to install a shared library for the `snmp-proxy`: `libsnmp` (contained in `libsnmp-dev`). +Unless you use binary built with `-tags=nonetsnmp`, you will have to install a shared library for the `snmp-proxy`: +`libsnmp` (contained in `libsnmp-dev`). Binaries available in the [Releases](https://github.com/grongor/go-snmp-proxy/releases) will be built on the Ubuntu LTS and thus compatible with the version of this library available in the Ubuntu LTS (and stable Debian). -If you that doesn't match your target system, you can: +If that doesn't match your target system, you can: - install the expected version of `libsnmp` (you will usually have the newer version, but it should be possible to install older one) - build the `snmp-proxy` yourself in the same environment as you expected the `snmp-proxy` to run + - use binary built with `-tags=nonetsnmp`, also available in the + [Releases](https://github.com/grongor/go-snmp-proxy/releases) diff --git a/cmd/snmp-proxy/snmp-proxy.go b/cmd/snmp-proxy/snmp-proxy.go index a330079..440d9d5 100644 --- a/cmd/snmp-proxy/snmp-proxy.go +++ b/cmd/snmp-proxy/snmp-proxy.go @@ -10,6 +10,7 @@ import ( "github.com/grongor/go-snmp-proxy/metrics" "github.com/grongor/go-snmp-proxy/snmpproxy" + "github.com/grongor/go-snmp-proxy/snmpproxy/mib" ) func main() { @@ -25,14 +26,14 @@ func main() { validator := snmpproxy.NewRequestValidator(config.Snmp.MaxTimeoutSeconds, config.Snmp.MaxRetries) - mibParser := snmpproxy.NewNetsnmpMibParser(config.Logger, config.Snmp.StrictMibParsing) + mibParser := mib.NewNetsnmpMibParser(config.Logger, config.Snmp.StrictMibParsing) displayHints, err := mibParser.Parse() if err != nil { config.Logger.Fatalw("mib parser error: ", zap.Error(err)) } - mibDataProvider := snmpproxy.NewMibDataProvider(displayHints) + mibDataProvider := mib.NewDataProvider(displayHints) requester := snmpproxy.NewGosnmpRequester(mibDataProvider) apiListener := snmpproxy.NewApiListener(validator, requester, config.Logger, config.Api.Listen) diff --git a/snmpproxy/mib/mib.go b/snmpproxy/mib/mib.go new file mode 100644 index 0000000..fedba30 --- /dev/null +++ b/snmpproxy/mib/mib.go @@ -0,0 +1,37 @@ +package mib + +import ( + "strings" +) + +type DisplayHint uint8 + +const ( + DisplayHintUnknown = DisplayHint(iota) + DisplayHintString + DisplayHintHexadecimal +) + +type DisplayHints map[string]DisplayHint + +type Parser interface { + Parse() (DisplayHints, error) +} + +type DataProvider struct { + displayHints DisplayHints +} + +func (p *DataProvider) GetDisplayHint(oid string) DisplayHint { + for length := len(oid); length > 7; length = strings.LastIndex(oid[:length], ".") { + if displayHint, ok := p.displayHints[oid[:length]]; ok { + return displayHint + } + } + + return DisplayHintUnknown +} + +func NewDataProvider(displayHints DisplayHints) *DataProvider { + return &DataProvider{displayHints: displayHints} +} diff --git a/snmpproxy/mib/mib_test.go b/snmpproxy/mib/mib_test.go new file mode 100644 index 0000000..17c87ae --- /dev/null +++ b/snmpproxy/mib/mib_test.go @@ -0,0 +1,60 @@ +package mib_test + +import ( + "testing" + + "github.com/stretchr/testify/require" + + "github.com/grongor/go-snmp-proxy/snmpproxy/mib" +) + +func TestMibDataProvider_GetStringType(t *testing.T) { + tests := []struct { + name string + stringTypes mib.DisplayHints + oid string + expected mib.DisplayHint + }{ + { + name: "exact match", + stringTypes: mib.DisplayHints{ + ".1.2.3.1.1.5.15.2": mib.DisplayHintString, + ".1.2.3.1.1.5.15": mib.DisplayHintHexadecimal, + }, + oid: ".1.2.3.1.1.5.15.2", + expected: mib.DisplayHintString, + }, + { + name: "parent matched", + stringTypes: mib.DisplayHints{ + ".1.2.3.1.1.5.15.22": mib.DisplayHintHexadecimal, + ".1.2.3.1.1.5.15": mib.DisplayHintString, + }, + oid: ".1.2.3.1.1.5.15.2", + expected: mib.DisplayHintString, + }, + { + name: "parent matched (multiple steps back)", + stringTypes: mib.DisplayHints{ + ".1.2.3.1.1.5.15.22": mib.DisplayHintString, + ".1.2.3.1.1.5.1": mib.DisplayHintString, + ".1.2.3.1.1.1": mib.DisplayHintString, + ".1.2.3.1.11": mib.DisplayHintString, + ".1.2.3.1": mib.DisplayHintHexadecimal, + }, + oid: ".1.2.3.1.1.5.15.2", + expected: mib.DisplayHintHexadecimal, + }, + { + name: "OID is too short to consider -> unknown type", + stringTypes: mib.DisplayHints{".1.2.3": mib.DisplayHintHexadecimal}, + oid: ".1.2.3", + expected: mib.DisplayHintUnknown, + }, + } + for _, test := range tests { + t.Run(test.name, func(t *testing.T) { + require.Equal(t, test.expected, mib.NewDataProvider(test.stringTypes).GetDisplayHint(test.oid)) + }) + } +} diff --git a/snmpproxy/mib.go b/snmpproxy/mib/netsnmp.go similarity index 79% rename from snmpproxy/mib.go rename to snmpproxy/mib/netsnmp.go index b55309a..1914403 100644 --- a/snmpproxy/mib.go +++ b/snmpproxy/mib/netsnmp.go @@ -1,4 +1,6 @@ -package snmpproxy +// +build !nonetsnmp + +package mib /* #cgo LDFLAGS: -lnetsnmp -L/usr/local/lib @@ -19,20 +21,6 @@ import ( "go.uber.org/zap" ) -type DisplayHint uint8 - -const ( - DisplayHintUnknown = DisplayHint(iota) - DisplayHintString - DisplayHintHexadecimal -) - -type DisplayHints map[string]DisplayHint - -type MibParser interface { - Parse() (DisplayHints, error) -} - // This parser was inspired by https://github.com/prometheus/snmp_exporter/tree/master/generator type NetsnmpMibParser struct { logger *zap.SugaredLogger @@ -140,21 +128,3 @@ func (p *NetsnmpMibParser) findStringTypesDisplayHints(displayHints DisplayHints func NewNetsnmpMibParser(logger *zap.SugaredLogger, strictParsing bool) *NetsnmpMibParser { return &NetsnmpMibParser{logger: logger, strictParsing: strictParsing} } - -type MibDataProvider struct { - displayHints DisplayHints -} - -func (p *MibDataProvider) GetDisplayHint(oid string) DisplayHint { - for length := len(oid); length > 7; length = strings.LastIndex(oid[:length], ".") { - if displayHint, ok := p.displayHints[oid[:length]]; ok { - return displayHint - } - } - - return DisplayHintUnknown -} - -func NewMibDataProvider(displayHints DisplayHints) *MibDataProvider { - return &MibDataProvider{displayHints: displayHints} -} diff --git a/snmpproxy/mib/netsnmp_test.go b/snmpproxy/mib/netsnmp_test.go new file mode 100644 index 0000000..4d2e1e5 --- /dev/null +++ b/snmpproxy/mib/netsnmp_test.go @@ -0,0 +1,24 @@ +// +build !nonetsnmp + +package mib_test + +import ( + "testing" + + "github.com/stretchr/testify/require" + "go.uber.org/zap" + + "github.com/grongor/go-snmp-proxy/snmpproxy/mib" +) + +func TestNetsnmpMibParser_Parse(t *testing.T) { + require := require.New(t) + + mibParser := mib.NewNetsnmpMibParser(zap.NewNop().Sugar(), false) + displayHints, err := mibParser.Parse() + + require.NoError(err) + require.NotEmpty(displayHints) + require.Equal(mib.DisplayHintString, displayHints[".1.3.6.1.2.1.2.2.1.2"]) + require.Equal(mib.DisplayHintHexadecimal, displayHints[".1.3.6.1.2.1.4.22.1.2"]) +} diff --git a/snmpproxy/mib/nonetsnmp.go b/snmpproxy/mib/nonetsnmp.go new file mode 100644 index 0000000..47fd704 --- /dev/null +++ b/snmpproxy/mib/nonetsnmp.go @@ -0,0 +1,22 @@ +// +build nonetsnmp + +package mib + +import ( + "go.uber.org/zap" +) + +type NopMibParser struct { +} + +func (n NopMibParser) Parse() (DisplayHints, error) { + return nil, nil +} + +func NewNopMibParser() *NopMibParser { + return &NopMibParser{} +} + +func NewNetsnmpMibParser(*zap.SugaredLogger, bool) Parser { + return NewNopMibParser() +} diff --git a/snmpproxy/mib/nonetsnmp_test.go b/snmpproxy/mib/nonetsnmp_test.go new file mode 100644 index 0000000..c844313 --- /dev/null +++ b/snmpproxy/mib/nonetsnmp_test.go @@ -0,0 +1,18 @@ +// +build nonetsnmp + +package mib_test + +import ( + "testing" + + "github.com/stretchr/testify/require" + + "github.com/grongor/go-snmp-proxy/snmpproxy/mib" +) + +func TestNopMibParser_Parse(t *testing.T) { + parser := mib.NewNetsnmpMibParser(nil, false) + hints, err := parser.Parse() + require.Nil(t, hints) + require.Nil(t, err) +} diff --git a/snmpproxy/mib_test.go b/snmpproxy/mib_test.go deleted file mode 100644 index ff53d56..0000000 --- a/snmpproxy/mib_test.go +++ /dev/null @@ -1,73 +0,0 @@ -package snmpproxy_test - -import ( - "testing" - - "github.com/stretchr/testify/require" - "go.uber.org/zap" - - "github.com/grongor/go-snmp-proxy/snmpproxy" -) - -func TestNetsnmpMibParser_Parse(t *testing.T) { - require := require.New(t) - - mibParser := snmpproxy.NewNetsnmpMibParser(zap.NewNop().Sugar(), false) - displayHints, err := mibParser.Parse() - - require.NoError(err) - require.NotEmpty(displayHints) - require.Equal(snmpproxy.DisplayHintString, displayHints[".1.3.6.1.2.1.2.2.1.2"]) - require.Equal(snmpproxy.DisplayHintHexadecimal, displayHints[".1.3.6.1.2.1.4.22.1.2"]) -} - -func TestMibDataProvider_GetStringType(t *testing.T) { - tests := []struct { - name string - stringTypes snmpproxy.DisplayHints - oid string - expected snmpproxy.DisplayHint - }{ - { - name: "exact match", - stringTypes: snmpproxy.DisplayHints{ - ".1.2.3.1.1.5.15.2": snmpproxy.DisplayHintString, - ".1.2.3.1.1.5.15": snmpproxy.DisplayHintHexadecimal, - }, - oid: ".1.2.3.1.1.5.15.2", - expected: snmpproxy.DisplayHintString, - }, - { - name: "parent matched", - stringTypes: snmpproxy.DisplayHints{ - ".1.2.3.1.1.5.15.22": snmpproxy.DisplayHintHexadecimal, - ".1.2.3.1.1.5.15": snmpproxy.DisplayHintString, - }, - oid: ".1.2.3.1.1.5.15.2", - expected: snmpproxy.DisplayHintString, - }, - { - name: "parent matched (multiple steps back)", - stringTypes: snmpproxy.DisplayHints{ - ".1.2.3.1.1.5.15.22": snmpproxy.DisplayHintString, - ".1.2.3.1.1.5.1": snmpproxy.DisplayHintString, - ".1.2.3.1.1.1": snmpproxy.DisplayHintString, - ".1.2.3.1.11": snmpproxy.DisplayHintString, - ".1.2.3.1": snmpproxy.DisplayHintHexadecimal, - }, - oid: ".1.2.3.1.1.5.15.2", - expected: snmpproxy.DisplayHintHexadecimal, - }, - { - name: "OID is too short to consider -> unknown type", - stringTypes: snmpproxy.DisplayHints{".1.2.3": snmpproxy.DisplayHintHexadecimal}, - oid: ".1.2.3", - expected: snmpproxy.DisplayHintUnknown, - }, - } - for _, test := range tests { - t.Run(test.name, func(t *testing.T) { - require.Equal(t, test.expected, snmpproxy.NewMibDataProvider(test.stringTypes).GetDisplayHint(test.oid)) - }) - } -} diff --git a/snmpproxy/requester.go b/snmpproxy/requester.go index 0df5160..7d0b501 100644 --- a/snmpproxy/requester.go +++ b/snmpproxy/requester.go @@ -9,6 +9,8 @@ import ( "unicode/utf8" "github.com/soniah/gosnmp" + + "github.com/grongor/go-snmp-proxy/snmpproxy/mib" ) type requestResult struct { @@ -22,7 +24,7 @@ type Requester interface { } type GosnmpRequester struct { - mibDataProvider *MibDataProvider + mibDataProvider *mib.DataProvider } func (r *GosnmpRequester) ExecuteRequest(apiRequest *ApiRequest) ([][]interface{}, error) { @@ -245,9 +247,9 @@ func (r *GosnmpRequester) getPduValue(dataUnit gosnmp.SnmpPDU) interface{} { switch dataUnit.Type { case gosnmp.OctetString: displayHint := r.mibDataProvider.GetDisplayHint(dataUnit.Name) - if displayHint == DisplayHintString || + if displayHint == mib.DisplayHintString || // best effort to display octet strings correctly without the MIBs - displayHint == DisplayHintUnknown && r.isStringPrintable(dataUnit.Value.([]byte)) { + displayHint == mib.DisplayHintUnknown && r.isStringPrintable(dataUnit.Value.([]byte)) { return string(dataUnit.Value.([]byte)) } @@ -273,6 +275,6 @@ func (r *GosnmpRequester) isStringPrintable(value []byte) bool { return true } -func NewGosnmpRequester(mibDataProvider *MibDataProvider) *GosnmpRequester { +func NewGosnmpRequester(mibDataProvider *mib.DataProvider) *GosnmpRequester { return &GosnmpRequester{mibDataProvider: mibDataProvider} } diff --git a/snmpproxy/requester_test.go b/snmpproxy/requester_test.go index e549593..c798e86 100644 --- a/snmpproxy/requester_test.go +++ b/snmpproxy/requester_test.go @@ -15,6 +15,7 @@ import ( "github.com/stretchr/testify/require" "github.com/grongor/go-snmp-proxy/snmpproxy" + "github.com/grongor/go-snmp-proxy/snmpproxy/mib" ) type syncBuffer struct { @@ -82,7 +83,7 @@ func TestGet(t *testing.T) { apiRequest := apiRequest(get([]string{".1.3.6.1.2.1.25.2.3.1.2.1", ".1.3.6.1.2.1.25.2.3.1.2.4"})) - requester := snmpproxy.NewGosnmpRequester(snmpproxy.NewMibDataProvider(nil)) + requester := snmpproxy.NewGosnmpRequester(mib.NewDataProvider(nil)) result, err := requester.ExecuteRequest(apiRequest) require.NoError(err) @@ -102,7 +103,7 @@ func TestGetStringDisplayHintGuessedString(t *testing.T) { apiRequest := apiRequest(get([]string{".1.3.6.1.2.1.2.2.1.2.48"})) - requester := snmpproxy.NewGosnmpRequester(snmpproxy.NewMibDataProvider(nil)) + requester := snmpproxy.NewGosnmpRequester(mib.NewDataProvider(nil)) result, err := requester.ExecuteRequest(apiRequest) require.NoError(err) @@ -117,7 +118,7 @@ func TestGetStringDisplayHintGuessedHexadecimalBecauseNotUtf8Valid(t *testing.T) apiRequest := apiRequest(get([]string{".1.3.6.1.2.1.4.22.1.2.2000955.185.152.67.97"})) - requester := snmpproxy.NewGosnmpRequester(snmpproxy.NewMibDataProvider(nil)) + requester := snmpproxy.NewGosnmpRequester(mib.NewDataProvider(nil)) result, err := requester.ExecuteRequest(apiRequest) require.NoError(err) @@ -132,7 +133,7 @@ func TestGetStringDisplayHintGuessedHexadecimalBecauseNotPrintable(t *testing.T) apiRequest := apiRequest(get([]string{".1.3.6.1.2.1.4.22.1.2.2000955.185.152.67.100"})) - requester := snmpproxy.NewGosnmpRequester(snmpproxy.NewMibDataProvider(nil)) + requester := snmpproxy.NewGosnmpRequester(mib.NewDataProvider(nil)) result, err := requester.ExecuteRequest(apiRequest) require.NoError(err) @@ -149,7 +150,7 @@ func TestGetNext(t *testing.T) { apiRequest := apiRequest(getNext([]string{".1.3.6.1.2.1.25.2.3.1.2", ".1.3.6.1.2.1.25.2.3.1.2.3"})) - requester := snmpproxy.NewGosnmpRequester(snmpproxy.NewMibDataProvider(nil)) + requester := snmpproxy.NewGosnmpRequester(mib.NewDataProvider(nil)) result, err := requester.ExecuteRequest(apiRequest) require.NoError(err) @@ -169,7 +170,7 @@ func TestWalk(t *testing.T) { apiRequest := apiRequest(walk(".1.3.6.1.2.1.31.1.1.1.15")) - requester := snmpproxy.NewGosnmpRequester(snmpproxy.NewMibDataProvider(nil)) + requester := snmpproxy.NewGosnmpRequester(mib.NewDataProvider(nil)) result, err := requester.ExecuteRequest(apiRequest) require.NoError(err) @@ -191,7 +192,7 @@ func TestWalkWithSnmpVersion1(t *testing.T) { apiRequest := apiRequest(walk(".1.3.6.1.2.1.31.1.1.1.15")) apiRequest.Version = snmpproxy.SnmpVersion(gosnmp.Version1) - requester := snmpproxy.NewGosnmpRequester(snmpproxy.NewMibDataProvider(nil)) + requester := snmpproxy.NewGosnmpRequester(mib.NewDataProvider(nil)) result, err := requester.ExecuteRequest(apiRequest) require.NoError(err) @@ -212,9 +213,9 @@ func TestWalkWholeTree(t *testing.T) { apiRequest := apiRequest(walk(".1.3")) - mibDataProvider := snmpproxy.NewMibDataProvider(snmpproxy.DisplayHints{ - ".1.3.6.1.2.1.2.2.1.2": snmpproxy.DisplayHintString, - ".1.3.6.1.2.1.4.22.1.2": snmpproxy.DisplayHintHexadecimal, + mibDataProvider := mib.NewDataProvider(mib.DisplayHints{ + ".1.3.6.1.2.1.2.2.1.2": mib.DisplayHintString, + ".1.3.6.1.2.1.4.22.1.2": mib.DisplayHintHexadecimal, }) requester := snmpproxy.NewGosnmpRequester(mibDataProvider) @@ -277,7 +278,7 @@ func TestWalkLastMibElement(t *testing.T) { apiRequest := apiRequest(walk(".1.7")) - requester := snmpproxy.NewGosnmpRequester(snmpproxy.NewMibDataProvider(nil)) + requester := snmpproxy.NewGosnmpRequester(mib.NewDataProvider(nil)) result, err := requester.ExecuteRequest(apiRequest) require.NoError(err) @@ -291,7 +292,7 @@ func TestWalkLastMibElementAndSnmpVersion1(t *testing.T) { apiRequest := apiRequest(walk(".1.7")) apiRequest.Version = snmpproxy.SnmpVersion(gosnmp.Version1) - requester := snmpproxy.NewGosnmpRequester(snmpproxy.NewMibDataProvider(nil)) + requester := snmpproxy.NewGosnmpRequester(mib.NewDataProvider(nil)) result, err := requester.ExecuteRequest(apiRequest) require.NoError(err) @@ -308,7 +309,7 @@ func TestMultipleRequests(t *testing.T) { getNext([]string{".1.3.6.1.2.1.2.2.1.14.9", ".1.3.6.1.2.1.2.2.1.14.10"}), ) - requester := snmpproxy.NewGosnmpRequester(snmpproxy.NewMibDataProvider(nil)) + requester := snmpproxy.NewGosnmpRequester(mib.NewDataProvider(nil)) result, err := requester.ExecuteRequest(apiRequest) require.NoError(err) @@ -335,7 +336,7 @@ func TestMultipleRequestsWithSingleError(t *testing.T) { getNext([]string{".1.3.6.1.2.1.2.2.1.14.9", ".1.7.9"}), ) - requester := snmpproxy.NewGosnmpRequester(snmpproxy.NewMibDataProvider(nil)) + requester := snmpproxy.NewGosnmpRequester(mib.NewDataProvider(nil)) result, err := requester.ExecuteRequest(apiRequest) require.Nil(result) @@ -351,7 +352,7 @@ func TestMultipleRequestsAllError(t *testing.T) { getNext([]string{".1.3.6.1.2.1.2.2.1.14.9", ".1.7.9"}), ) - requester := snmpproxy.NewGosnmpRequester(snmpproxy.NewMibDataProvider(nil)) + requester := snmpproxy.NewGosnmpRequester(mib.NewDataProvider(nil)) result, err := requester.ExecuteRequest(apiRequest) require.Nil(result) @@ -364,7 +365,7 @@ func TestWalkWithNoSuchInstanceError(t *testing.T) { apiRequest := apiRequest(walk(".1.3.5")) - requester := snmpproxy.NewGosnmpRequester(snmpproxy.NewMibDataProvider(nil)) + requester := snmpproxy.NewGosnmpRequester(mib.NewDataProvider(nil)) result, err := requester.ExecuteRequest(apiRequest) require.Nil(result) require.EqualError(err, "no such instance: .1.3.5") @@ -376,7 +377,7 @@ func TestWalkWithSnmpVersion1AndNoSuchInstanceError(t *testing.T) { apiRequest := apiRequest(walk(".1.3.5")) apiRequest.Version = snmpproxy.SnmpVersion(gosnmp.Version1) - requester := snmpproxy.NewGosnmpRequester(snmpproxy.NewMibDataProvider(nil)) + requester := snmpproxy.NewGosnmpRequester(mib.NewDataProvider(nil)) result, err := requester.ExecuteRequest(apiRequest) require.Nil(result) require.EqualError(err, "no such instance: .1.3.5") @@ -387,7 +388,7 @@ func TestWalkWithEndOfMibError(t *testing.T) { apiRequest := apiRequest(walk(".1.15")) - requester := snmpproxy.NewGosnmpRequester(snmpproxy.NewMibDataProvider(nil)) + requester := snmpproxy.NewGosnmpRequester(mib.NewDataProvider(nil)) result, err := requester.ExecuteRequest(apiRequest) require.Nil(result) require.EqualError(err, "end of mib: .1.15") @@ -399,7 +400,7 @@ func TestWalkWithSnmpVersion1AndEndOfMibError(t *testing.T) { apiRequest := apiRequest(walk(".1.15")) apiRequest.Version = snmpproxy.SnmpVersion(gosnmp.Version1) - requester := snmpproxy.NewGosnmpRequester(snmpproxy.NewMibDataProvider(nil)) + requester := snmpproxy.NewGosnmpRequester(mib.NewDataProvider(nil)) result, err := requester.ExecuteRequest(apiRequest) require.Nil(result) require.EqualError(err, "end of mib: .1.15") @@ -410,7 +411,7 @@ func TestGetWithNoSuchInstanceError(t *testing.T) { apiRequest := apiRequest(get([]string{".1.3.5"})) - requester := snmpproxy.NewGosnmpRequester(snmpproxy.NewMibDataProvider(nil)) + requester := snmpproxy.NewGosnmpRequester(mib.NewDataProvider(nil)) result, err := requester.ExecuteRequest(apiRequest) require.Nil(result) require.EqualError(err, "no such instance: .1.3.5") @@ -422,7 +423,7 @@ func TestGetWithSnmpVersion1AndNoSuchInstanceError(t *testing.T) { apiRequest := apiRequest(get([]string{".1.3.5"})) apiRequest.Version = snmpproxy.SnmpVersion(gosnmp.Version1) - requester := snmpproxy.NewGosnmpRequester(snmpproxy.NewMibDataProvider(nil)) + requester := snmpproxy.NewGosnmpRequester(mib.NewDataProvider(nil)) result, err := requester.ExecuteRequest(apiRequest) require.Nil(result) require.EqualError(err, "no such instance: .1.3.5") @@ -434,7 +435,7 @@ func TestGetWithMultipleOidsAndSnmpVersion1AndNoSuchInstanceError(t *testing.T) apiRequest := apiRequest(get([]string{".1.3.5", "1.3.2"})) apiRequest.Version = snmpproxy.SnmpVersion(gosnmp.Version1) - requester := snmpproxy.NewGosnmpRequester(snmpproxy.NewMibDataProvider(nil)) + requester := snmpproxy.NewGosnmpRequester(mib.NewDataProvider(nil)) result, err := requester.ExecuteRequest(apiRequest) require.Nil(result) require.EqualError(err, "no such instance: one of .1.3.5 1.3.2") @@ -445,7 +446,7 @@ func TestGetNextWithEndOfMib(t *testing.T) { apiRequest := apiRequest(getNext([]string{".1.15"})) - requester := snmpproxy.NewGosnmpRequester(snmpproxy.NewMibDataProvider(nil)) + requester := snmpproxy.NewGosnmpRequester(mib.NewDataProvider(nil)) result, err := requester.ExecuteRequest(apiRequest) require.Nil(result) require.EqualError(err, "end of mib: .1.15") @@ -457,7 +458,7 @@ func TestGetNextWithSnmpVersion1AndEndOfMib(t *testing.T) { apiRequest := apiRequest(getNext([]string{".1.15"})) apiRequest.Version = snmpproxy.SnmpVersion(gosnmp.Version1) - requester := snmpproxy.NewGosnmpRequester(snmpproxy.NewMibDataProvider(nil)) + requester := snmpproxy.NewGosnmpRequester(mib.NewDataProvider(nil)) result, err := requester.ExecuteRequest(apiRequest) require.Nil(result) require.EqualError(err, "end of mib: .1.15") @@ -469,7 +470,7 @@ func TestGetWithSnmpError(t *testing.T) { apiRequest := apiRequest(get([]string{".1.1"})) apiRequest.Host = "localhost" - requester := snmpproxy.NewGosnmpRequester(snmpproxy.NewMibDataProvider(nil)) + requester := snmpproxy.NewGosnmpRequester(mib.NewDataProvider(nil)) result, err := requester.ExecuteRequest(apiRequest) require.Nil(result) require.Error(err) @@ -482,7 +483,7 @@ func TestWalkWithSnmpError(t *testing.T) { apiRequest := apiRequest(walk("")) apiRequest.Host = "localhost" - requester := snmpproxy.NewGosnmpRequester(snmpproxy.NewMibDataProvider(nil)) + requester := snmpproxy.NewGosnmpRequester(mib.NewDataProvider(nil)) result, err := requester.ExecuteRequest(apiRequest) require.Nil(result) require.Error(err) @@ -519,7 +520,7 @@ func TestInvalidHost(t *testing.T) { apiRequest := apiRequest(get([]string{}), walk("")) apiRequest.Host = test.host - requester := snmpproxy.NewGosnmpRequester(snmpproxy.NewMibDataProvider(nil)) + requester := snmpproxy.NewGosnmpRequester(mib.NewDataProvider(nil)) result, err := requester.ExecuteRequest(apiRequest) require.Nil(result) require.Error(err)