@cryptotaxi247 / netdata-1 / commits / e00e85a63

chore(go.d/snmp): add _vnode_type host label and rm duplicates (#20754)

Ilya Mashchenko committed Aug 4, 2025 at 11:19 UTC e00e85a630e4070fc190e57218f63ca83ddc8bba
1 file changed +29 -21
src/go/plugin/go.d/collector/snmp/collect.go
+29 -21
@@ -6,6 +6,7 @@ import (
6 "errors"
7 "fmt"
8 "log/slog"
9 + "maps"
10 "path/filepath"
11 "slices"
12 "strings"
@@ -108,36 +109,43 @@ func (c *Collector) setupVnode(si *snmpsd.SysInfo, deviceMeta map[string]map[str
109 c.Vnode.GUID = uuid.NewSHA1(uuid.NameSpaceDNS, []byte(c.Hostname)).String()
110 }
111
111 - hostnames := []string{c.Vnode.Hostname, si.Name, "snmp-device"}
112 + hostnames := []string{
113 + c.Vnode.Hostname,
114 + si.Name,
115 + "snmp-device",
116 + }
117 i := slices.IndexFunc(hostnames, func(s string) bool { return s != "" })
113 -
118 c.Vnode.Hostname = fmt.Sprintf("%s(%s)", hostnames[i], c.Hostname)
119
116 - labels := make(map[string]string)
120 + labels := map[string]string{
121 + "hostname": c.Hostname,
122 + "_vnode_type": "snmp",
123 + }
124 +
125 + maps.Copy(labels, c.Vnode.Labels)
126 + for _, meta := range deviceMeta {
127 + maps.Copy(labels, meta)
128 + }
129
118 - for k, v := range c.Vnode.Labels {
119 - labels[k] = v
130 + if _, ok := labels["sys_object_id"]; !ok {
131 + labels["sys_object_id"] = si.SysObjectID
132 }
121 - if si.Descr != "" {
122 - labels["sysDescr"] = si.Descr
133 + if _, ok := labels["name"]; !ok {
134 + labels["name"] = si.Name
135 }
124 - if si.Contact != "" {
125 - labels["sysContact"] = si.Contact
136 + if _, ok := labels["description"]; !ok && si.Descr != "" {
137 + labels["description"] = si.Descr
138 }
127 - if si.Location != "" {
128 - labels["sysLocation"] = si.Location
139 + if _, ok := labels["contact"]; !ok && si.Contact != "" {
140 + labels["contact"] = si.Contact
141 }
130 -
131 - labels["vendor"] = si.Organization
132 - if v, ok := orgToVendorMap[si.Organization]; ok {
133 - labels["vendor"] = v
142 + if _, ok := labels["location"]; !ok && si.Location != "" {
143 + labels["location"] = si.Location
144 }
135 -
136 - for _, meta := range deviceMeta {
137 - for k, v := range meta {
138 - if _, ok := labels[k]; !ok {
139 - labels[k] = v
140 - }
145 + if _, ok := labels["vendor"]; !ok && si.Organization != "" {
146 + labels["vendor"] = si.Organization
147 + if v, ok := orgToVendorMap[si.Organization]; ok {
148 + labels["vendor"] = v
149 }
150 }
151