Repository: kentik/ktranslate
Pull request #130 (2021-09-14 00:18:55)

Updated snmp engine. 
Update snmp engine to point to mainline gosnmp/gosnmp. 


Patch:
diff --git a/go.mod b/go.mod
index 135b350..feb93c0 100644
--- a/go.mod
+++ b/go.mod
@@ -16,13 +16,13 @@ require (
 	github.com/go-ole/go-ole v1.2.5 // indirect
 	github.com/google/uuid v1.2.0
 	github.com/gorilla/mux v1.8.0
+	github.com/gosnmp/gosnmp v1.32.0 // indirect
 	github.com/grpc-ecosystem/grpc-gateway/v2 v2.3.0 // indirect
 	github.com/honeycombio/libhoney-go v1.15.2
 	github.com/json-iterator/go v1.1.10
 	github.com/kentik/api-schema-public v0.0.0-20210428232153-25f1622f6b13
 	github.com/kentik/go-metrics v0.0.0-20200109025407-4bfd4a9b42c5
 	github.com/kentik/golog v0.0.0-20210617234020-0acbd1400e72 // indirect
-	github.com/kentik/gosnmp v0.0.0-20210316190950-425ee043d4b7
 	github.com/kentik/patricia v0.0.0-20201202224819-f9447a6e25f1
 	github.com/liamg/furious v0.0.0-20191231090757-c295c872d6c1
 	github.com/linkedin/goavro/v2 v2.10.0
diff --git a/go.sum b/go.sum
index 9cbaa3e..473a53e 100644
--- a/go.sum
+++ b/go.sum
@@ -373,6 +373,8 @@ github.com/gorilla/mux v1.8.0/go.mod h1:DVbg23sWSpFRCP0SfiEN6jmj59UnW/n46BH5rLB7
 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.32.0 h1:gctewmZx5qFI0oHMzRnjETqIZ093d9NgZy9TQr3V0iA=
+github.com/gosnmp/gosnmp v1.32.0/go.mod h1:EIp+qkEpXoVsyZxXKy0AmXQx0mCHMMcIhXXvNDMpgF0=
 github.com/grpc-ecosystem/go-grpc-middleware v1.0.0 h1:Iju5GlWwrvL6UBg4zJJt3btmonfrMlCDdsejg4CZE7c=
 github.com/grpc-ecosystem/go-grpc-middleware v1.0.0/go.mod h1:FiyG127CGDf3tlThmgyCl78X/SZQqEOJBCDaAfeWzPs=
 github.com/grpc-ecosystem/go-grpc-middleware v1.0.1-0.20190118093823-f849b5445de4/go.mod h1:FiyG127CGDf3tlThmgyCl78X/SZQqEOJBCDaAfeWzPs=
@@ -474,8 +476,6 @@ github.com/kentik/golog v0.0.0-20210617232342-903603c744fa h1:4ajJAtHFHXQuxNcK2p
 github.com/kentik/golog v0.0.0-20210617232342-903603c744fa/go.mod h1:1Ig79IyA5/TB06yCWphpLeZjcKcDZ5wZ/sLAbU6YZYs=
 github.com/kentik/golog v0.0.0-20210617234020-0acbd1400e72 h1:npaew2XG6lRz52Y/3MGkCJVwYdQv0Dfxd9cdCfgxodw=
 github.com/kentik/golog v0.0.0-20210617234020-0acbd1400e72/go.mod h1:1Ig79IyA5/TB06yCWphpLeZjcKcDZ5wZ/sLAbU6YZYs=
-github.com/kentik/gosnmp v0.0.0-20210316190950-425ee043d4b7 h1:Xw1iroIxua7NgsQDJGdPYWnYee1z4bIPmePbI6ry+cU=
-github.com/kentik/gosnmp v0.0.0-20210316190950-425ee043d4b7/go.mod h1:5H44C2CAU7KmoDNXcXEYU0OkFtVEfe7SPLrI+GU9uds=
 github.com/kentik/patricia v0.0.0-20201202224819-f9447a6e25f1 h1:D7qhJP3R49ZjUzpzKQ6B2H3lgejPs6DTO5gRomhhOpE=
 github.com/kentik/patricia v0.0.0-20201202224819-f9447a6e25f1/go.mod h1:2OfLA+0esiUJpwMjrH39pEk79cb8MvGTBS9YlZpejJ4=
 github.com/kisielk/errcheck v1.1.0/go.mod h1:EZBBE59ingxPouuu3KfxchcWSUPOHkagtvWXihfKN4Q=
diff --git a/pkg/formats/nrm/events/events.go b/pkg/formats/nrm/events/events.go
index 53ced95..f5a0eb7 100644
--- a/pkg/formats/nrm/events/events.go
+++ b/pkg/formats/nrm/events/events.go
@@ -8,6 +8,10 @@ import (
 	"github.com/kentik/ktranslate/pkg/kt"
 )
 
+const (
+	InstNameSnmpTrapEvent = "snmp-trap-events"
+)
+
 func SendEvent(msg *kt.JCHF, doGz bool, evts chan []byte) error {
 	res, err := toRawJson(msg, doGz)
 	if err != nil {
@@ -75,4 +79,6 @@ func strip(in map[string]interface{}) {
 		}
 	}
 	in["instrumentation.provider"] = kt.InstProvider // Let them know who sent this.
+	in["instrumentation.name"] = InstNameSnmpTrapEvent
+	in["collector.name"] = kt.CollectorName
 }
diff --git a/pkg/formats/util/util.go b/pkg/formats/util/util.go
index 12e7237..ac23e02 100644
--- a/pkg/formats/util/util.go
+++ b/pkg/formats/util/util.go
@@ -122,7 +122,7 @@ func SetAttr(attr map[string]interface{}, in *kt.JCHF, metrics map[string]kt.Met
 		// Finally, drop any values which do not match the whitelist.
 		if lastMetadata.MatchAttr != nil {
 			dropOnAdminStatus := false // Default this false.
-			keepForOtherMatch := false // We use inverse of this, so default is to allow flow.
+			keepForOtherMatch := false // We use inverse of this, so default is to drop flow. BUT, need to have a match set else all flow passes.
 			seenAdminStatus := false
 			for k, re := range lastMetadata.MatchAttr {
 				if v, ok := attr[k]; ok {
diff --git a/pkg/inputs/snmp/metadata/device_metadata.go b/pkg/inputs/snmp/metadata/device_metadata.go
index ab4bf53..93b6047 100644
--- a/pkg/inputs/snmp/metadata/device_metadata.go
+++ b/pkg/inputs/snmp/metadata/device_metadata.go
@@ -6,7 +6,7 @@ import (
 
 	"github.com/elliotchance/orderedmap"
 
-	"github.com/kentik/gosnmp"
+	"github.com/gosnmp/gosnmp"
 	"github.com/kentik/ktranslate/pkg/eggs/logger"
 	snmp_util "github.com/kentik/ktranslate/pkg/inputs/snmp/util"
 	"github.com/kentik/ktranslate/pkg/kt"
diff --git a/pkg/inputs/snmp/metadata/interface_metadata.go b/pkg/inputs/snmp/metadata/interface_metadata.go
index a67e36f..b061ed0 100644
--- a/pkg/inputs/snmp/metadata/interface_metadata.go
+++ b/pkg/inputs/snmp/metadata/interface_metadata.go
@@ -11,7 +11,7 @@ import (
 
 	"github.com/elliotchance/orderedmap"
 
-	"github.com/kentik/gosnmp"
+	"github.com/gosnmp/gosnmp"
 
 	"github.com/kentik/ktranslate/pkg/eggs/logger"
 	snmp_util "github.com/kentik/ktranslate/pkg/inputs/snmp/util"
diff --git a/pkg/inputs/snmp/metadata/poll.go b/pkg/inputs/snmp/metadata/poll.go
index 7af5c35..5b3dcf3 100644
--- a/pkg/inputs/snmp/metadata/poll.go
+++ b/pkg/inputs/snmp/metadata/poll.go
@@ -7,7 +7,7 @@ import (
 	"strings"
 	"time"
 
-	"github.com/kentik/gosnmp"
+	"github.com/gosnmp/gosnmp"
 
 	"github.com/kentik/ktranslate/pkg/eggs/logger"
 	"github.com/kentik/ktranslate/pkg/inputs/snmp/mibs"
diff --git a/pkg/inputs/snmp/metrics/device_metrics.go b/pkg/inputs/snmp/metrics/device_metrics.go
index ae19c54..fa87401 100644
--- a/pkg/inputs/snmp/metrics/device_metrics.go
+++ b/pkg/inputs/snmp/metrics/device_metrics.go
@@ -7,7 +7,7 @@ import (
 	"strings"
 	"time"
 
-	"github.com/kentik/gosnmp"
+	"github.com/gosnmp/gosnmp"
 	"github.com/kentik/ktranslate/pkg/eggs/logger"
 	"github.com/kentik/ktranslate/pkg/inputs/snmp/mibs"
 	"github.com/kentik/ktranslate/pkg/kt"
diff --git a/pkg/inputs/snmp/metrics/interface_metrics.go b/pkg/inputs/snmp/metrics/interface_metrics.go
index 0cc94a0..543fc2b 100644
--- a/pkg/inputs/snmp/metrics/interface_metrics.go
+++ b/pkg/inputs/snmp/metrics/interface_metrics.go
@@ -7,7 +7,7 @@ import (
 	"sync"
 	"time"
 
-	"github.com/kentik/gosnmp"
+	"github.com/gosnmp/gosnmp"
 
 	"github.com/kentik/ktranslate/pkg/eggs/logger"
 	"github.com/kentik/ktranslate/pkg/inputs/snmp/mibs"
diff --git a/pkg/inputs/snmp/metrics/poll.go b/pkg/inputs/snmp/metrics/poll.go
index ebba01e..17d8a30 100644
--- a/pkg/inputs/snmp/metrics/poll.go
+++ b/pkg/inputs/snmp/metrics/poll.go
@@ -5,7 +5,7 @@ import (
 	"math/rand"
 	"time"
 
-	"github.com/kentik/gosnmp"
+	"github.com/gosnmp/gosnmp"
 	"github.com/kentik/ktranslate/pkg/eggs/logger"
 	"github.com/kentik/ktranslate/pkg/inputs/snmp/mibs"
 	"github.com/kentik/ktranslate/pkg/kt"
diff --git a/pkg/inputs/snmp/snmp.go b/pkg/inputs/snmp/snmp.go
index d28bfec..10ec377 100644
--- a/pkg/inputs/snmp/snmp.go
+++ b/pkg/inputs/snmp/snmp.go
@@ -29,7 +29,7 @@ var (
 	flowOnly       = flag.Bool("flow_only", false, "If true, don't poll snmp devices.")
 	jsonToYaml     = flag.String("snmp_json2yaml", "", "If set, convert the passed in json file to a yaml profile.")
 	snmpWalk       = flag.String("snmp_do_walk", "", "If set, try to perform a snmp walk against the targeted device.")
-	snmpWalkOid    = flag.String("snmp_walk_oid", ".1.3.6.1", "Walk this oid if -snmp_do_walk is set.")
+	snmpWalkOid    = flag.String("snmp_walk_oid", ".1.3.6.1.2.1", "Walk this oid if -snmp_do_walk is set.")
 	snmpWalkFormat = flag.String("snmp_walk_format", "", "use this format for walked values if -snmp_do_walk is set.")
 )
 
diff --git a/pkg/inputs/snmp/traps/traps.go b/pkg/inputs/snmp/traps/traps.go
index e8ac736..baa5a07 100644
--- a/pkg/inputs/snmp/traps/traps.go
+++ b/pkg/inputs/snmp/traps/traps.go
@@ -8,7 +8,7 @@ import (
 	"sync"
 	"time"
 
-	"github.com/kentik/gosnmp"
+	"github.com/gosnmp/gosnmp"
 
 	"github.com/kentik/ktranslate/pkg/eggs/logger"
 	"github.com/kentik/ktranslate/pkg/inputs/snmp/mibs"
@@ -90,14 +90,14 @@ func NewSnmpTrapListener(conf *kt.SnmpConfig, jchfChan chan []*kt.JCHF, metrics
 		return nil, fmt.Errorf("Invalid trap version: %s", conf.Trap.Version)
 	}
 
-	tl.Params.Logger = logWrapper{
+	tl.Params.Logger = gosnmp.NewLogger(logWrapper{
 		print: func(v ...interface{}) {
 			log.Debugf("GoSNMP Trap:" + fmt.Sprint(v...))
 		},
 		printf: func(format string, v ...interface{}) {
 			log.Debugf("GoSNMP Trap:  "+format, v...)
 		},
-	}
+	})
 	st.tl = tl
 
 	for _, device := range conf.Devices {
diff --git a/pkg/inputs/snmp/util/adaptor.go b/pkg/inputs/snmp/util/adaptor.go
index 4f85c94..65f52c7 100644
--- a/pkg/inputs/snmp/util/adaptor.go
+++ b/pkg/inputs/snmp/util/adaptor.go
@@ -5,7 +5,7 @@ import (
 	"fmt"
 	"time"
 
-	"github.com/kentik/gosnmp"
+	"github.com/gosnmp/gosnmp"
 	"github.com/kentik/ktranslate/pkg/eggs/logger"
 	"github.com/kentik/ktranslate/pkg/kt"
 )
@@ -57,8 +57,16 @@ func parseV3Config(v3config *kt.V3SNMPConfig) (*gosnmp.UsmSecurityParameters, go
 		params.AuthenticationProtocol = gosnmp.MD5
 	case "SHA":
 		params.AuthenticationProtocol = gosnmp.SHA
+	case "SHA224":
+		params.AuthenticationProtocol = gosnmp.SHA224
+	case "SHA256":
+		params.AuthenticationProtocol = gosnmp.SHA256
+	case "SHA384":
+		params.AuthenticationProtocol = gosnmp.SHA384
+	case "SHA512":
+		params.AuthenticationProtocol = gosnmp.SHA512
 	default:
-		return nil, gosnmp.AuthNoPriv, "", "", fmt.Errorf("invalid v3 authentication_protocol: %s. valid options: NoAuth|MD5|SHA", v3config.AuthenticationProtocol)
+		return nil, gosnmp.AuthNoPriv, "", "", fmt.Errorf("invalid v3 authentication_protocol: %s. valid options: NoAuth|MD5|SHA|SHA224|SHA256|SHA384|SHA512", v3config.AuthenticationProtocol)
 	}
 
 	return &params, flags, v3config.ContextEngineID, v3config.ContextName, nil
@@ -124,7 +132,7 @@ func InitSNMP(device *kt.SnmpDeviceConfig, connectTimeout time.Duration, retries
 			return nil, err
 		}
 
-		log.Infof("%s Running with SNMP v3", posit)
+		log.Infof("%s Running with SNMP v3: Priv: %s Auth: %s", posit, params.PrivacyProtocol, params.AuthenticationProtocol)
 		server.Version = gosnmp.Version3
 		server.ContextEngineID = contextEngineID
 		server.ContextName = contextName
@@ -134,14 +142,14 @@ func InitSNMP(device *kt.SnmpDeviceConfig, connectTimeout time.Duration, retries
 	}
 
 	if device.Debug {
-		server.Logger = logWrapper{
+		server.Logger = gosnmp.NewLogger(logWrapper{
 			print: func(v ...interface{}) {
 				log.Debugf("GoSNMP:" + fmt.Sprint(v...))
 			},
 			printf: func(format string, v ...interface{}) {
 				log.Debugf("GoSNMP:  "+format, v...)
 			},
-		}
+		})
 	}
 
 	// We have everything we need -- start connect.
diff --git a/pkg/inputs/snmp/util/util.go b/pkg/inputs/snmp/util/util.go
index fbb3529..d5676ea 100644
--- a/pkg/inputs/snmp/util/util.go
+++ b/pkg/inputs/snmp/util/util.go
@@ -11,7 +11,7 @@ import (
 	"strings"
 	"time"
 
-	"github.com/kentik/gosnmp"
+	"github.com/gosnmp/gosnmp"
 	"github.com/kentik/ktranslate/pkg/eggs/logger"
 	"github.com/kentik/ktranslate/pkg/kt"
 )


Test patch:
diff --git a/pkg/formats/util/util_test.go b/pkg/formats/util/util_test.go
index f0561be..8b09d7b 100644
--- a/pkg/formats/util/util_test.go
+++ b/pkg/formats/util/util_test.go
@@ -122,6 +122,40 @@ func TestSetAttrDrop(t *testing.T) {
 			},
 			false,
 		},
+		{
+			map[string]interface{}{
+				kt.AdminStatus: "up",
+				"foo":          "bar",
+				"aaa":          "aaa",
+			},
+			kt.NewJCHF(),
+			map[string]kt.MetricInfo{},
+			kt.LastMetadata{
+				MatchAttr: map[string]*regexp.Regexp{
+					"foo":          regexp.MustCompile("no"),
+					"aaa":          regexp.MustCompile("no"),
+					kt.AdminStatus: regexp.MustCompile("up"),
+				},
+			},
+			true, // Drop because neither foo or aaa match even though admin is up.
+		},
+		{
+			map[string]interface{}{
+				kt.AdminStatus: "up",
+				"foo":          "bar",
+				"aaa":          "aaa",
+			},
+			kt.NewJCHF(),
+			map[string]kt.MetricInfo{},
+			kt.LastMetadata{
+				MatchAttr: map[string]*regexp.Regexp{
+					"foo":          regexp.MustCompile("no"),
+					"aaa":          regexp.MustCompile("aa"),
+					kt.AdminStatus: regexp.MustCompile("up"),
+				},
+			},
+			false, // Keep because aaa matches and admin is up.
+		},
 	}
 
 	for i, test := range tests {
diff --git a/pkg/inputs/snmp/util/util_test.go b/pkg/inputs/snmp/util/util_test.go
index 9014e56..4ddc8ee 100644
--- a/pkg/inputs/snmp/util/util_test.go
+++ b/pkg/inputs/snmp/util/util_test.go
@@ -9,7 +9,7 @@ import (
 
 	"github.com/kentik/ktranslate/pkg/eggs/logger"
 	lt "github.com/kentik/ktranslate/pkg/eggs/logger/testing"
-	"github.com/kentik/gosnmp"
+	"github.com/gosnmp/gosnmp"
 )
 
 type testWalker struct {