master
go 74 lines 1.97 KB
Raw
1 // SPDX-License-Identifier: GPL-3.0-or-later
2
3 package snmp
4
5 import (
6 "fmt"
7 "maps"
8
9 "github.com/netdata/netdata/go/plugins/plugin/go.d/collector/snmp/ddsnmp"
10 "github.com/netdata/netdata/go/plugins/plugin/go.d/pkg/snmputils"
11 )
12
13 func firstVendor(values ...string) string {
14 for _, v := range values {
15 if v != "" {
16 return v
17 }
18 }
19 return ""
20 }
21
22 func (c *Collector) vnodeGUID() string {
23 if c.vnode != nil {
24 return c.vnode.GUID
25 }
26 return ""
27 }
28
29 func (c *Collector) vnodeLabels() map[string]string {
30 if c.vnode != nil && len(c.vnode.Labels) > 0 {
31 cp := make(map[string]string, len(c.vnode.Labels))
32 maps.Copy(cp, c.vnode.Labels)
33 return cp
34 }
35 return nil
36 }
37
38 func (c *Collector) deviceRegistryKey() string {
39 return fmt.Sprintf("%p:%s:%d", c, c.Hostname, c.Options.Port)
40 }
41
42 // registerDeviceForTopology exposes the already-configured SNMP job to the
43 // snmp_topology collector without duplicating job configuration.
44 func (c *Collector) registerDeviceForTopology(si *snmputils.SysInfo) {
45 ddsnmp.DeviceRegistry.Register(c.deviceRegistryKey(), ddsnmp.DeviceConnectionInfo{
46 Hostname: c.Hostname,
47 Port: c.Options.Port,
48 SNMPVersion: c.Options.Version,
49 Community: c.Community,
50 V3User: c.User.Name,
51 V3SecurityLevel: c.User.SecurityLevel,
52 V3AuthProto: c.User.AuthProto,
53 V3AuthKey: c.User.AuthKey,
54 V3PrivProto: c.User.PrivProto,
55 V3PrivKey: c.User.PrivKey,
56 V3ContextName: c.User.ContextName,
57 MaxRepetitions: c.adjMaxRepetitions,
58 MaxOIDs: c.Options.MaxOIDs,
59 Timeout: c.Options.Timeout,
60 Retries: c.Options.Retries,
61 SysObjectID: si.SysObjectID,
62 SysDescr: si.Descr,
63 SysName: si.Name,
64 SysContact: si.Contact,
65 SysLocation: si.Location,
66 Vendor: firstVendor(si.Vendor, si.Organization),
67 Model: si.Model,
68
69 DisableBulkWalk: c.disableBulkWalk,
70 ManualProfiles: c.ManualProfiles,
71 VnodeGUID: c.vnodeGUID(),
72 VnodeLabels: c.vnodeLabels(),
73 })
74 }