@cryptotaxi247 / netdata-1 / commits / aeca973ea

fix(go.d/snmp): fix nil dereferencing when no profiles found (#21557)

Ilya Mashchenko committed Jan 14, 2026 at 18:10 UTC aeca973ea0932adbd37a3529addfd3d4f32ece0c
1 file changed +18 -6
src/go/plugin/go.d/collector/snmp/collect.go
+18 -6
@@ -112,12 +112,20 @@ func (c *Collector) ensureInitialized() error {
112 })
113 }
114
115 + if c.ddSnmpColl == nil && !c.Ping.Enabled {
116 + return errors.New("no profiles found and ping disabled")
117 + }
118 +
119 if c.CreateVnode {
116 - deviceMeta, err := c.ddSnmpColl.CollectDeviceMetadata()
117 - if err != nil {
118 - return err
120 + if c.ddSnmpColl == nil {
121 + c.vnode = c.setupVnode(si, nil)
122 + } else {
123 + deviceMeta, err := c.ddSnmpColl.CollectDeviceMetadata()
124 + if err != nil {
125 + return err
126 + }
127 + c.vnode = c.setupVnode(si, deviceMeta)
128 }
120 - c.vnode = c.setupVnode(si, deviceMeta)
129 }
130
131 c.sysInfo = si
@@ -199,8 +207,12 @@ func (c *Collector) setupProfiles(si *snmputils.SysInfo) []*ddsnmp.Profile {
207 }
208 }
209
202 - c.Infof("device matched %d profile(s): %s (sysObjectID: '%s')",
203 - len(snmpProfiles), strings.Join(profInfo, ", "), si.SysObjectID)
210 + msg := fmt.Sprintf("device matched %d profile(s): %s (sysObjectID: '%s')", len(snmpProfiles), strings.Join(profInfo, ", "), si.SysObjectID)
211 + if len(snmpProfiles) == 0 {
212 + c.Warning(msg)
213 + } else {
214 + c.Info(msg)
215 + }
216
217 return snmpProfiles
218 }