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

Extended SNMPv3 Polling privProtocol Support #8541

Merged
merged 1 commit into from
Dec 23, 2020
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions internal/snmp/wrapper.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,14 @@ func NewWrapper(s ClientConfig) (GosnmpWrapper, error) {
sp.PrivacyProtocol = gosnmp.DES
case "aes":
sp.PrivacyProtocol = gosnmp.AES
case "aes192":
sp.PrivacyProtocol = gosnmp.AES192
case "aes192c":
sp.PrivacyProtocol = gosnmp.AES192C
case "aes256":
sp.PrivacyProtocol = gosnmp.AES256
case "aes256c":
sp.PrivacyProtocol = gosnmp.AES256C
case "":
sp.PrivacyProtocol = gosnmp.NoPriv
default:
Expand Down
4 changes: 3 additions & 1 deletion plugins/inputs/snmp/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,9 @@ information.
# sec_level = "authNoPriv"
## Context Name.
# context_name = ""
## Privacy protocol used for encrypted messages; one of "DES", "AES" or "".
## Privacy protocol used for encrypted messages; one of "DES", "AES", "AES192", "AES192C", "AES256", "AES256C", or "".
### Protocols "AES192", "AES192", "AES256", and "AES256C" require the underlying net-snmp tools
### to be compiled with --enable-blumenthal-aes (http://www.net-snmp.org/docs/INSTALL.html)
# priv_protocol = ""
## Privacy password used for encrypted messages.
# priv_password = ""
Expand Down
119 changes: 119 additions & 0 deletions plugins/inputs/snmp/snmp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,125 @@ func TestGetSNMPConnection_v3(t *testing.T) {
assert.EqualValues(t, 2, sp.AuthoritativeEngineTime)
}

func TestGetSNMPConnection_v3_blumenthal(t *testing.T) {
testCases := []struct {
Name string
Algorithm gosnmp.SnmpV3PrivProtocol
Config *Snmp
}{
{
Name: "AES192",
Algorithm: gosnmp.AES192,
Config: &Snmp{
Agents: []string{"1.2.3.4"},
ClientConfig: config.ClientConfig{
Version: 3,
MaxRepetitions: 20,
ContextName: "mycontext",
SecLevel: "authPriv",
SecName: "myuser",
AuthProtocol: "md5",
AuthPassword: "password123",
PrivProtocol: "AES192",
PrivPassword: "password123",
EngineID: "myengineid",
EngineBoots: 1,
EngineTime: 2,
},
},
},
{
Name: "AES192C",
Algorithm: gosnmp.AES192C,
Config: &Snmp{
Agents: []string{"1.2.3.4"},
ClientConfig: config.ClientConfig{
Version: 3,
MaxRepetitions: 20,
ContextName: "mycontext",
SecLevel: "authPriv",
SecName: "myuser",
AuthProtocol: "md5",
AuthPassword: "password123",
PrivProtocol: "AES192C",
PrivPassword: "password123",
EngineID: "myengineid",
EngineBoots: 1,
EngineTime: 2,
},
},
},
{
Name: "AES256",
Algorithm: gosnmp.AES256,
Config: &Snmp{
Agents: []string{"1.2.3.4"},
ClientConfig: config.ClientConfig{
Version: 3,
MaxRepetitions: 20,
ContextName: "mycontext",
SecLevel: "authPriv",
SecName: "myuser",
AuthProtocol: "md5",
AuthPassword: "password123",
PrivProtocol: "AES256",
PrivPassword: "password123",
EngineID: "myengineid",
EngineBoots: 1,
EngineTime: 2,
},
},
},
{
Name: "AES256C",
Algorithm: gosnmp.AES256C,
Config: &Snmp{
Agents: []string{"1.2.3.4"},
ClientConfig: config.ClientConfig{
Version: 3,
MaxRepetitions: 20,
ContextName: "mycontext",
SecLevel: "authPriv",
SecName: "myuser",
AuthProtocol: "md5",
AuthPassword: "password123",
PrivProtocol: "AES256C",
PrivPassword: "password123",
EngineID: "myengineid",
EngineBoots: 1,
EngineTime: 2,
},
},
},
}

for _, tc := range testCases {
t.Run(tc.Name, func(t *testing.T) {
s := tc.Config
err := s.init()
require.NoError(t, err)

gsc, err := s.getConnection(0)
require.NoError(t, err)
gs := gsc.(snmp.GosnmpWrapper)
assert.Equal(t, gs.Version, gosnmp.Version3)
sp := gs.SecurityParameters.(*gosnmp.UsmSecurityParameters)
assert.Equal(t, "1.2.3.4", gsc.Host())
assert.EqualValues(t, 20, gs.MaxRepetitions)
assert.Equal(t, "mycontext", gs.ContextName)
assert.Equal(t, gosnmp.AuthPriv, gs.MsgFlags&gosnmp.AuthPriv)
assert.Equal(t, "myuser", sp.UserName)
assert.Equal(t, gosnmp.MD5, sp.AuthenticationProtocol)
assert.Equal(t, "password123", sp.AuthenticationPassphrase)
assert.Equal(t, tc.Algorithm, sp.PrivacyProtocol)
assert.Equal(t, "password123", sp.PrivacyPassphrase)
assert.Equal(t, "myengineid", sp.AuthoritativeEngineID)
assert.EqualValues(t, 1, sp.AuthoritativeEngineBoots)
assert.EqualValues(t, 2, sp.AuthoritativeEngineTime)
})
}
}

func TestGetSNMPConnection_caching(t *testing.T) {
s := &Snmp{
Agents: []string{"1.2.3.4", "1.2.3.5", "1.2.3.5"},
Expand Down