go.d add vnode guid validation (#18531)
Ilya Mashchenko committed
Sep 11, 2024 at 23:58 UTC
aa77ae98fd48514022d3e97e9b7220e1741b5632
3 files changed
+14
-6
src/go/plugin/go.d/agent/vnodes/vnodes.go
+6
-1
@@ -11,6 +11,7 @@ import (
11
12
"github.com/netdata/netdata/go/plugins/logger"
13
14
+ "github.com/google/uuid"
15
"gopkg.in/yaml.v2"
16
)
17
@@ -99,7 +100,11 @@ func (vn *Vnodes) readConfDir() {
100
101
for _, v := range cfg {
102
if v.Hostname == "" || v.GUID == "" {
102
- vn.Warningf("skipping virtual node '%+v': some required fields are missing (%s)", v, path)
103
+ vn.Warningf("skipping virtual node '%+v': required fields are missing (%s)", v, path)
104
+ continue
105
+ }
106
+ if err := uuid.Validate(v.GUID); err != nil {
107
+ vn.Warningf("skipping virtual node '%+v': invalid GUID: %v (%s)", v, err, path)
108
continue
109
}
110
if _, ok := vn.vnodes[v.Hostname]; ok {
src/go/plugin/go.d/modules/snmp/collect_sys_info.go
+2
-5
@@ -52,11 +52,8 @@ func (s *SNMP) getSysInfo() (*sysInfo, error) {
52
case oidSysObject:
53
var sysObj string
54
if sysObj, err = pduToString(pdu); err == nil {
55
- org := entnum.LookupBySysObject(sysObj)
56
- s.Debugf("device sysObject '%s', organization '%s'", sysObj, org)
57
- if org != "" {
58
- si.organization = org
59
- }
55
+ si.organization = entnum.LookupBySysObject(sysObj)
56
+ s.Debugf("device sysObject '%s', organization '%s'", sysObj, si.organization)
57
}
58
case oidSysContact:
59
si.contact, err = pduToString(pdu)
src/go/plugin/go.d/modules/snmp/init.go
+6
@@ -8,6 +8,7 @@ import (
8
"strings"
9
"time"
10
11
+ "github.com/google/uuid"
12
"github.com/netdata/netdata/go/plugins/plugin/go.d/pkg/matcher"
13
14
"github.com/gosnmp/gosnmp"
@@ -17,6 +18,11 @@ func (s *SNMP) validateConfig() error {
18
if s.Hostname == "" {
19
return errors.New("SNMP hostname is required")
20
}
21
+ if s.Vnode.GUID != "" {
22
+ if err := uuid.Validate(s.Vnode.GUID); err != nil {
23
+ return fmt.Errorf("invalid Vnode GUID: %v", err)
24
+ }
25
+ }
26
return nil
27
}
28