@cryptotaxi247 / netdata-1 / commits / a54b3e03c

fix(go.d/sd/snmp): fix snmpv3 credentials (#20247)

Ilya Mashchenko committed May 7, 2025 at 13:15 UTC a54b3e03c9d1fb4b964bd06a2c6bb8afabfea86f
4 files changed +45 -24
src/go/plugin/go.d/agent/discovery/sd/discoverer/snmpsd/config.go
+7 -7
@@ -49,12 +49,12 @@ type (
49 SecurityLevel string `yaml:"security_level"`
50 // AuthProtocol must be one of: "md5", "sha", "sha224", "sha256", "sha384", "sha512" (for SNMPv3)
51 AuthProtocol string `yaml:"auth_protocol"`
52 - // AuthPassphrase is the authentication passphrase (for SNMPv3)
53 - AuthPassphrase string `yaml:"auth_passphrase"`
52 + // AuthPassword is the authentication passphrase (for SNMPv3)
53 + AuthPassword string `yaml:"auth_password"`
54 // PrivacyProtocol must be one of: "des", "aes", "aes192", "aes256", "aes192C", "aes256C" (for SNMPv3)
55 - PrivacyProtocol string `yaml:"privacy_protocol"`
56 - // PrivacyPassphrase is the privacy passphrase (for SNMPv3)
57 - PrivacyPassphrase string `yaml:"privacy_passphrase"`
55 + PrivacyProtocol string `yaml:"priv_protocol"`
56 + // PrivacyPassword is the privacy passphrase (for SNMPv3)
57 + PrivacyPassword string `yaml:"priv_password"`
58 }
59 )
60
@@ -136,9 +136,9 @@ func setCredential(client gosnmp.Handler, cred CredentialConfig) {
136 client.SetSecurityParameters(&gosnmp.UsmSecurityParameters{
137 UserName: cred.UserName,
138 AuthenticationProtocol: parseSNMPv3AuthProtocol(cred),
139 - AuthenticationPassphrase: cred.AuthPassphrase,
139 + AuthenticationPassphrase: cred.AuthPassword,
140 PrivacyProtocol: parseSNMPv3PrivProtocol(cred),
141 - PrivacyPassphrase: cred.PrivacyPassphrase,
141 + PrivacyPassphrase: cred.PrivacyPassword,
142 })
143 }
144 }
src/go/plugin/go.d/agent/discovery/sd/discoverer/snmpsd/discoverer.go
+21
@@ -6,6 +6,7 @@ import (
6 "context"
7 "fmt"
8 "log/slog"
9 + "strings"
10 "time"
11
12 "github.com/gohugoio/hashstructure"
@@ -171,6 +172,14 @@ func (d *Discoverer) discoverNetwork(ctx context.Context, in chan<- []model.Targ
172 }
173 p := pool.New().WithMaxGoroutines(d.parallelScansPerNetwork)
174
175 + client, cleanup := d.newSnmpClient()
176 + defer cleanup()
177 +
178 + client.SetTimeout(d.timeout)
179 + client.SetRetries(0)
180 + setCredential(client, sub.credential)
181 + d.Debugf("SNMP client info for '%s': %s", sub.str, snmpClientConnInfo(client))
182 +
183 for ip := range sub.ips.Iterate() {
184 ipAddr := ip.String()
185
@@ -272,3 +281,15 @@ func isDone(ctx context.Context) bool {
281 return false
282 }
283 }
284 +
285 +func snmpClientConnInfo(c gosnmp.Handler) string {
286 + var info strings.Builder
287 + info.WriteString(fmt.Sprintf("hostname='%s',port='%d',snmp_version='%s'", c.Target(), c.Port(), c.Version()))
288 + switch c.Version() {
289 + case gosnmp.Version1, gosnmp.Version2c:
290 + info.WriteString(fmt.Sprintf(",community='%s'", c.Community()))
291 + case gosnmp.Version3:
292 + info.WriteString(fmt.Sprintf(",security_level='%d,%s'", c.MsgFlags(), c.SecurityParameters().Description()))
293 + }
294 + return info.String()
295 +}
src/go/plugin/go.d/agent/discovery/sd/discoverer/snmpsd/discoverer_test.go
+16 -16
@@ -45,14 +45,14 @@ func TestNewDiscoverer(t *testing.T) {
45 cfg: Config{
46 Credentials: []CredentialConfig{
47 {
48 - Name: "v3cred",
49 - Version: "3",
50 - UserName: "user",
51 - SecurityLevel: "authPriv",
52 - AuthProtocol: "sha",
53 - AuthPassphrase: "authpass",
54 - PrivacyProtocol: "aes",
55 - PrivacyPassphrase: "privpass",
48 + Name: "v3cred",
49 + Version: "3",
50 + UserName: "user",
51 + SecurityLevel: "authPriv",
52 + AuthProtocol: "sha",
53 + AuthPassword: "authpass",
54 + PrivacyProtocol: "aes",
55 + PrivacyPassword: "privpass",
56 },
57 },
58 Networks: []NetworkConfig{
@@ -66,14 +66,14 @@ func TestNewDiscoverer(t *testing.T) {
66 {Name: "v1cred", Version: "1", Community: "public"},
67 {Name: "v2cred", Version: "2c", Community: "private"},
68 {
69 - Name: "v3cred",
70 - Version: "3",
71 - UserName: "user",
72 - SecurityLevel: "authPriv",
73 - AuthProtocol: "sha",
74 - AuthPassphrase: "authpass",
75 - PrivacyProtocol: "aes",
76 - PrivacyPassphrase: "privpass",
69 + Name: "v3cred",
70 + Version: "3",
71 + UserName: "user",
72 + SecurityLevel: "authPriv",
73 + AuthProtocol: "sha",
74 + AuthPassword: "authpass",
75 + PrivacyProtocol: "aes",
76 + PrivacyPassword: "privpass",
77 },
78 },
79 Networks: []NetworkConfig{
src/go/plugin/go.d/agent/discovery/sd/sd.go
+1 -1
@@ -108,7 +108,7 @@ func (d *ServiceDiscovery) addPipeline(ctx context.Context, conf confFile, in ch
108 var cfg pipeline.Config
109
110 if err := yaml.Unmarshal(conf.content, &cfg); err != nil {
111 - d.Error(err)
111 + d.Errorf("failed to unmarshal pipeline config '%s' (%s): %v", cfg.Name, conf.source, err)
112 return
113 }
114