chore(go.d/snmp): remove/disable legacy components (#21026)
Ilya Mashchenko committed
Sep 22, 2025 at 13:41 UTC
be5c623c6fcda5915fb9719db1fc0a5ea157fef3
13 files changed
+43
-876
src/go/plugin/go.d/collector/snmp/charts.go
+1
-189
@@ -13,197 +13,9 @@ import (
13
)
14
15
const (
16
- prioNetIfaceTraffic = module.Priority + iota
17
- prioNetIfaceUnicast
18
- prioNetIfaceMulticast
19
- prioNetIfaceBroadcast
20
- prioNetIfaceErrors
21
- prioNetIfaceDiscards
22
- prioNetIfaceAdminStatus
23
- prioNetIfaceOperStatus
24
- prioSysUptime
25
-
26
- prioProfileChart
27
-)
28
-
29
-var netIfaceChartsTmpl = module.Charts{
30
- netIfaceTrafficChartTmpl.Copy(),
31
- netIfacePacketsChartTmpl.Copy(),
32
- netIfaceMulticastChartTmpl.Copy(),
33
- netIfaceBroadcastChartTmpl.Copy(),
34
- netIfaceErrorsChartTmpl.Copy(),
35
- netIfaceDiscardsChartTmpl.Copy(),
36
- netIfaceAdminStatusChartTmpl.Copy(),
37
- netIfaceOperStatusChartTmpl.Copy(),
38
-}
39
-
40
-var (
41
- netIfaceTrafficChartTmpl = module.Chart{
42
- ID: "snmp_device_net_iface_%s_traffic",
43
- Title: "SNMP device network interface traffic",
44
- Units: "kilobits/s",
45
- Fam: "traffic",
46
- Ctx: "snmp.device_net_interface_traffic",
47
- Priority: prioNetIfaceTraffic,
48
- Type: module.Area,
49
- Dims: module.Dims{
50
- {ID: "net_iface_%s_traffic_in", Name: "received", Algo: module.Incremental},
51
- {ID: "net_iface_%s_traffic_out", Name: "sent", Mul: -1, Algo: module.Incremental},
52
- },
53
- }
54
-
55
- netIfacePacketsChartTmpl = module.Chart{
56
- ID: "snmp_device_net_iface_%s_unicast",
57
- Title: "SNMP device network interface unicast packets",
58
- Units: "packets/s",
59
- Fam: "packets",
60
- Ctx: "snmp.device_net_interface_unicast",
61
- Priority: prioNetIfaceUnicast,
62
- Dims: module.Dims{
63
- {ID: "net_iface_%s_ucast_in", Name: "received", Algo: module.Incremental},
64
- {ID: "net_iface_%s_ucast_out", Name: "sent", Mul: -1, Algo: module.Incremental},
65
- },
66
- }
67
- netIfaceMulticastChartTmpl = module.Chart{
68
- ID: "snmp_device_net_iface_%s_multicast",
69
- Title: "SNMP device network interface multicast packets",
70
- Units: "packets/s",
71
- Fam: "packets",
72
- Ctx: "snmp.device_net_interface_multicast",
73
- Priority: prioNetIfaceMulticast,
74
- Dims: module.Dims{
75
- {ID: "net_iface_%s_mcast_in", Name: "received", Algo: module.Incremental},
76
- {ID: "net_iface_%s_mcast_out", Name: "sent", Mul: -1, Algo: module.Incremental},
77
- },
78
- }
79
- netIfaceBroadcastChartTmpl = module.Chart{
80
- ID: "snmp_device_net_iface_%s_broadcast",
81
- Title: "SNMP device network interface broadcast packets",
82
- Units: "packets/s",
83
- Fam: "packets",
84
- Ctx: "snmp.device_net_interface_broadcast",
85
- Priority: prioNetIfaceBroadcast,
86
- Dims: module.Dims{
87
- {ID: "net_iface_%s_bcast_in", Name: "received", Algo: module.Incremental},
88
- {ID: "net_iface_%s_bcast_out", Name: "sent", Mul: -1, Algo: module.Incremental},
89
- },
90
- }
91
-
92
- netIfaceErrorsChartTmpl = module.Chart{
93
- ID: "snmp_device_net_iface_%s_errors",
94
- Title: "SNMP device network interface errors",
95
- Units: "errors/s",
96
- Fam: "errors",
97
- Ctx: "snmp.device_net_interface_errors",
98
- Priority: prioNetIfaceErrors,
99
- Dims: module.Dims{
100
- {ID: "net_iface_%s_errors_in", Name: "inbound", Algo: module.Incremental},
101
- {ID: "net_iface_%s_errors_out", Name: "outbound", Mul: -1, Algo: module.Incremental},
102
- },
103
- }
104
-
105
- netIfaceDiscardsChartTmpl = module.Chart{
106
- ID: "snmp_device_net_iface_%s_discards",
107
- Title: "SNMP device network interface discards",
108
- Units: "discards/s",
109
- Fam: "discards",
110
- Ctx: "snmp.device_net_interface_discards",
111
- Priority: prioNetIfaceDiscards,
112
- Dims: module.Dims{
113
- {ID: "net_iface_%s_discards_in", Name: "inbound", Algo: module.Incremental},
114
- {ID: "net_iface_%s_discards_out", Name: "outbound", Mul: -1, Algo: module.Incremental},
115
- },
116
- }
117
-
118
- netIfaceAdminStatusChartTmpl = module.Chart{
119
- ID: "snmp_device_net_iface_%s_admin_status",
120
- Title: "SNMP device network interface administrative status",
121
- Units: "status",
122
- Fam: "status",
123
- Ctx: "snmp.device_net_interface_admin_status",
124
- Priority: prioNetIfaceAdminStatus,
125
- Dims: module.Dims{
126
- {ID: "net_iface_%s_admin_status_up", Name: "up"},
127
- {ID: "net_iface_%s_admin_status_down", Name: "down"},
128
- {ID: "net_iface_%s_admin_status_testing", Name: "testing"},
129
- },
130
- }
131
- netIfaceOperStatusChartTmpl = module.Chart{
132
- ID: "snmp_device_net_iface_%s_oper_status",
133
- Title: "SNMP device network interface operational status",
134
- Units: "status",
135
- Fam: "status",
136
- Ctx: "snmp.device_net_interface_oper_status",
137
- Priority: prioNetIfaceOperStatus,
138
- Dims: module.Dims{
139
- {ID: "net_iface_%s_oper_status_up", Name: "up"},
140
- {ID: "net_iface_%s_oper_status_down", Name: "down"},
141
- {ID: "net_iface_%s_oper_status_testing", Name: "testing"},
142
- {ID: "net_iface_%s_oper_status_unknown", Name: "unknown"},
143
- {ID: "net_iface_%s_oper_status_dormant", Name: "dormant"},
144
- {ID: "net_iface_%s_oper_status_notPresent", Name: "not_present"},
145
- {ID: "net_iface_%s_oper_status_lowerLayerDown", Name: "lower_layer_down"},
146
- },
147
- }
16
+ prioProfileChart = module.Priority
17
)
18
150
-var (
151
- uptimeChart = module.Chart{
152
- ID: "snmp_device_uptime",
153
- Title: "SNMP device uptime",
154
- Units: "seconds",
155
- Fam: "uptime",
156
- Ctx: "snmp.device_uptime",
157
- Priority: prioSysUptime,
158
- Dims: module.Dims{
159
- {ID: "uptime", Name: "uptime"},
160
- },
161
- }
162
-)
163
-
164
-func (c *Collector) addNetIfaceCharts(iface *netInterface) {
165
- charts := netIfaceChartsTmpl.Copy()
166
-
167
- for _, chart := range *charts {
168
- chart.ID = fmt.Sprintf(chart.ID, cleanMetricName.Replace(iface.ifName))
169
- chart.Labels = []module.Label{
170
- {Key: "vendor", Value: c.sysInfo.Organization},
171
- {Key: "sysName", Value: c.sysInfo.Name},
172
- {Key: "ifDescr", Value: iface.ifDescr},
173
- {Key: "ifName", Value: iface.ifName},
174
- {Key: "ifType", Value: ifTypeMapping[iface.ifType]},
175
- }
176
- for _, dim := range chart.Dims {
177
- dim.ID = fmt.Sprintf(dim.ID, iface.ifName)
178
- }
179
- }
180
-
181
- if err := c.Charts().Add(*charts...); err != nil {
182
- c.Warning(err)
183
- }
184
-}
185
-
186
-func (c *Collector) removeNetIfaceCharts(iface *netInterface) {
187
- px := fmt.Sprintf("snmp_device_net_iface_%s_", cleanMetricName.Replace(iface.ifName))
188
- for _, chart := range *c.Charts() {
189
- if strings.HasPrefix(chart.ID, px) {
190
- chart.MarkRemove()
191
- chart.MarkNotCreated()
192
- }
193
- }
194
-}
195
-
196
-func (c *Collector) addSysUptimeChart() {
197
- chart := uptimeChart.Copy()
198
- chart.Labels = []module.Label{
199
- {Key: "vendor", Value: c.sysInfo.Organization},
200
- {Key: "sysName", Value: c.sysInfo.Name},
201
- }
202
- if err := c.Charts().Add(chart); err != nil {
203
- c.Warning(err)
204
- }
205
-}
206
-
19
func newUserInputCharts(configs []ChartConfig) (*module.Charts, error) {
20
charts := &module.Charts{}
21
for _, cfg := range configs {
src/go/plugin/go.d/collector/snmp/collect.go
+3
-19
@@ -42,13 +42,12 @@ func (c *Collector) collect() (map[string]int64, error) {
42
return nil, err
43
}
44
45
- if c.DisableLegacyCollection || c.EnableProfiles {
45
+ if c.enableProfiles {
46
c.snmpProfiles = c.setupProfiles(si.SysObjectID)
47
}
48
49
if c.ddSnmpColl == nil {
50
c.ddSnmpColl = ddsnmpcollector.New(c.snmpClient, c.snmpProfiles, c.Logger, si.SysObjectID)
51
- c.ddSnmpColl.DoTableMetrics = c.EnableProfilesTableMetrics && c.snmpBulkWalkOk
51
}
52
53
if c.CreateVnode {
@@ -60,10 +59,6 @@ func (c *Collector) collect() (map[string]int64, error) {
59
}
60
61
c.sysInfo = si
63
-
64
- if !c.DisableLegacyCollection {
65
- c.addSysUptimeChart()
66
- }
62
}
63
64
mx := make(map[string]int64)
@@ -72,21 +67,10 @@ func (c *Collector) collect() (map[string]int64, error) {
67
c.Infof("failed to collect profiles: %v", err)
68
}
69
75
- if !c.DisableLegacyCollection {
76
- if err := c.collectSysUptime(mx); err != nil {
70
+ if !c.DisableLegacyCollection && len(c.customOids) > 0 {
71
+ if err := c.collectOIDs(mx); err != nil {
72
return nil, err
73
}
79
-
80
- if c.snmpBulkWalkOk && c.collectIfMib {
81
- if err := c.collectNetworkInterfaces(mx); err != nil {
82
- return nil, err
83
- }
84
- }
85
- if len(c.customOids) > 0 {
86
- if err := c.collectOIDs(mx); err != nil {
87
- return nil, err
88
- }
89
- }
74
}
75
76
return mx, nil
src/go/plugin/go.d/collector/snmp/collect_if_mib.go
deleted
-219
@@ -1,219 +0,0 @@
1
-// SPDX-License-Identifier: GPL-3.0-or-later
2
-
3
-package snmp
4
-
5
-import (
6
- "fmt"
7
- "log/slog"
8
- "sort"
9
- "strings"
10
-
11
- "github.com/netdata/netdata/go/plugins/logger"
12
- "github.com/netdata/netdata/go/plugins/plugin/go.d/pkg/snmputils"
13
-
14
- "github.com/gosnmp/gosnmp"
15
-)
16
-
17
-const (
18
- rootOidIfMibIfTable = "1.3.6.1.2.1.2.2"
19
- rootOidIfMibIfXTable = "1.3.6.1.2.1.31.1.1"
20
-)
21
-
22
-func (c *Collector) collectNetworkInterfaces(mx map[string]int64) error {
23
- ifMibTable, err := walkAll(c.snmpClient, rootOidIfMibIfTable)
24
- if err != nil {
25
- return err
26
- }
27
-
28
- ifMibXTable, err := walkAll(c.snmpClient, rootOidIfMibIfXTable)
29
- if err != nil {
30
- return err
31
- }
32
-
33
- if len(ifMibTable) == 0 && len(ifMibXTable) == 0 {
34
- c.Warning("no IF-MIB data returned")
35
- c.collectIfMib = false
36
- return nil
37
- }
38
-
39
- for _, i := range c.netInterfaces {
40
- i.updated = false
41
- }
42
-
43
- pdus := make([]gosnmp.SnmpPDU, 0, len(ifMibTable)+len(ifMibXTable))
44
- pdus = append(pdus, ifMibTable...)
45
- pdus = append(pdus, ifMibXTable...)
46
-
47
- for _, pdu := range pdus {
48
- i := strings.LastIndexByte(pdu.Name, '.')
49
- if i == -1 {
50
- continue
51
- }
52
-
53
- idx := pdu.Name[i+1:]
54
- oid := strings.TrimPrefix(pdu.Name[:i], ".")
55
-
56
- iface, ok := c.netInterfaces[idx]
57
- if !ok {
58
- iface = &netInterface{idx: idx}
59
- }
60
-
61
- switch oid {
62
- case oidIfIndex:
63
- iface.ifIndex, err = pduToInt(pdu)
64
- case oidIfDescr:
65
- iface.ifDescr, err = snmputils.PduToString(pdu)
66
- case oidIfType:
67
- iface.ifType, err = pduToInt(pdu)
68
- case oidIfMtu:
69
- iface.ifMtu, err = pduToInt(pdu)
70
- case oidIfSpeed:
71
- iface.ifSpeed, err = pduToInt(pdu)
72
- case oidIfAdminStatus:
73
- iface.ifAdminStatus, err = pduToInt(pdu)
74
- case oidIfOperStatus:
75
- iface.ifOperStatus, err = pduToInt(pdu)
76
- case oidIfInOctets:
77
- iface.ifInOctets, err = pduToInt(pdu)
78
- case oidIfInUcastPkts:
79
- iface.ifInUcastPkts, err = pduToInt(pdu)
80
- case oidIfInNUcastPkts:
81
- iface.ifInNUcastPkts, err = pduToInt(pdu)
82
- case oidIfInDiscards:
83
- iface.ifInDiscards, err = pduToInt(pdu)
84
- case oidIfInErrors:
85
- iface.ifInErrors, err = pduToInt(pdu)
86
- case oidIfInUnknownProtos:
87
- iface.ifInUnknownProtos, err = pduToInt(pdu)
88
- case oidIfOutOctets:
89
- iface.ifOutOctets, err = pduToInt(pdu)
90
- case oidIfOutUcastPkts:
91
- iface.ifOutUcastPkts, err = pduToInt(pdu)
92
- case oidIfOutNUcastPkts:
93
- iface.ifOutNUcastPkts, err = pduToInt(pdu)
94
- case oidIfOutDiscards:
95
- iface.ifOutDiscards, err = pduToInt(pdu)
96
- case oidIfOutErrors:
97
- iface.ifOutErrors, err = pduToInt(pdu)
98
- case oidIfName:
99
- iface.ifName, err = snmputils.PduToString(pdu)
100
- case oidIfInMulticastPkts:
101
- iface.ifInMulticastPkts, err = pduToInt(pdu)
102
- case oidIfInBroadcastPkts:
103
- iface.ifInBroadcastPkts, err = pduToInt(pdu)
104
- case oidIfOutMulticastPkts:
105
- iface.ifOutMulticastPkts, err = pduToInt(pdu)
106
- case oidIfOutBroadcastPkts:
107
- iface.ifOutBroadcastPkts, err = pduToInt(pdu)
108
- case oidIfHCInOctets:
109
- iface.ifHCInOctets, err = pduToInt(pdu)
110
- case oidIfHCInUcastPkts:
111
- iface.ifHCInUcastPkts, err = pduToInt(pdu)
112
- case oidIfHCInMulticastPkts:
113
- iface.ifHCInMulticastPkts, err = pduToInt(pdu)
114
- case oidIfHCInBroadcastPkts:
115
- iface.ifHCInBroadcastPkts, err = pduToInt(pdu)
116
- case oidIfHCOutOctets:
117
- iface.ifHCOutOctets, err = pduToInt(pdu)
118
- case oidIfHCOutUcastPkts:
119
- iface.ifHCOutUcastPkts, err = pduToInt(pdu)
120
- case oidIfHCOutMulticastPkts:
121
- iface.ifHCOutMulticastPkts, err = pduToInt(pdu)
122
- case oidIfHCOutBroadcastPkts:
123
- iface.ifHCOutBroadcastPkts, err = pduToInt(pdu)
124
- case oidIfHighSpeed:
125
- iface.ifHighSpeed, err = pduToInt(pdu)
126
- case oidIfAlias:
127
- iface.ifAlias, err = snmputils.PduToString(pdu)
128
- default:
129
- continue
130
- }
131
-
132
- if err != nil {
133
- return fmt.Errorf("OID '%s': %v", pdu.Name, err)
134
- }
135
-
136
- c.netInterfaces[idx] = iface
137
- iface.updated = true
138
- }
139
-
140
- var valReplacer = strings.NewReplacer("'", "", "\n", " ", "\r", " ", "\x00", "")
141
-
142
- for _, iface := range c.netInterfaces {
143
- if iface.ifName == "" {
144
- iface.ifName = iface.ifDescr
145
- }
146
- if iface.ifName == "" {
147
- continue
148
- }
149
-
150
- typeStr := ifTypeMapping[iface.ifType]
151
- if c.netIfaceFilterByName.MatchString(iface.ifName) || c.netIfaceFilterByType.MatchString(typeStr) {
152
- continue
153
- }
154
-
155
- iface.ifName = valReplacer.Replace(iface.ifName)
156
- iface.ifDescr = valReplacer.Replace(iface.ifDescr)
157
- iface.ifAlias = valReplacer.Replace(iface.ifAlias)
158
-
159
- if !iface.updated {
160
- delete(c.netInterfaces, iface.idx)
161
- if iface.hasCharts {
162
- c.removeNetIfaceCharts(iface)
163
- }
164
- continue
165
- }
166
- if !iface.hasCharts {
167
- iface.hasCharts = true
168
- c.addNetIfaceCharts(iface)
169
- }
170
-
171
- px := fmt.Sprintf("net_iface_%s_", iface.ifName)
172
- if len(ifMibXTable) == 0 {
173
- mx[px+"traffic_in"] = iface.ifInOctets * 8 / 1000 // kilobits
174
- mx[px+"traffic_out"] = iface.ifOutOctets * 8 / 1000 // kilobits
175
- mx[px+"ucast_in"] = iface.ifInUcastPkts
176
- mx[px+"ucast_out"] = iface.ifOutUcastPkts
177
- mx[px+"mcast_in"] = iface.ifInMulticastPkts
178
- mx[px+"mcast_out"] = iface.ifOutMulticastPkts
179
- mx[px+"bcast_in"] = iface.ifInBroadcastPkts
180
- mx[px+"bcast_out"] = iface.ifOutBroadcastPkts
181
- } else {
182
- mx[px+"traffic_in"] = iface.ifHCInOctets * 8 / 1000 // kilobits
183
- mx[px+"traffic_out"] = iface.ifHCOutOctets * 8 / 1000 // kilobits
184
- mx[px+"ucast_in"] = iface.ifHCInUcastPkts
185
- mx[px+"ucast_out"] = iface.ifHCOutUcastPkts
186
- mx[px+"mcast_in"] = iface.ifHCInMulticastPkts
187
- mx[px+"mcast_out"] = iface.ifHCOutMulticastPkts
188
- mx[px+"bcast_in"] = iface.ifHCInBroadcastPkts
189
- mx[px+"bcast_out"] = iface.ifHCOutBroadcastPkts
190
- }
191
- mx[px+"errors_in"] = iface.ifInErrors
192
- mx[px+"errors_out"] = iface.ifOutErrors
193
- mx[px+"discards_in"] = iface.ifInDiscards
194
- mx[px+"discards_out"] = iface.ifOutDiscards
195
-
196
- for _, v := range ifAdminStatusMapping {
197
- mx[px+"admin_status_"+v] = 0
198
- }
199
- mx[px+"admin_status_"+ifAdminStatusMapping[iface.ifAdminStatus]] = 1
200
-
201
- for _, v := range ifOperStatusMapping {
202
- mx[px+"oper_status_"+v] = 0
203
- }
204
- mx[px+"oper_status_"+ifOperStatusMapping[iface.ifOperStatus]] = 1
205
- }
206
-
207
- if logger.Level.Enabled(slog.LevelDebug) {
208
- ifaces := make([]*netInterface, 0, len(c.netInterfaces))
209
- for _, nif := range c.netInterfaces {
210
- ifaces = append(ifaces, nif)
211
- }
212
- sort.Slice(ifaces, func(i, j int) bool { return ifaces[i].ifIndex < ifaces[j].ifIndex })
213
- for _, iface := range ifaces {
214
- c.Debugf("found %s", iface)
215
- }
216
- }
217
-
218
- return nil
219
-}
src/go/plugin/go.d/collector/snmp/collector.go
+9
-20
@@ -9,7 +9,6 @@ import (
9
10
"github.com/gosnmp/gosnmp"
11
12
- "github.com/netdata/netdata/go/plugins/pkg/matcher"
12
"github.com/netdata/netdata/go/plugins/plugin/go.d/agent/module"
13
"github.com/netdata/netdata/go/plugins/plugin/go.d/agent/vnodes"
14
"github.com/netdata/netdata/go/plugins/plugin/go.d/collector/snmp/ddsnmp"
@@ -34,11 +33,10 @@ func init() {
33
func New() *Collector {
34
return &Collector{
35
Config: Config{
37
- CreateVnode: true,
38
- EnableProfiles: true,
39
- EnableProfilesTableMetrics: true,
40
- VnodeDeviceDownThreshold: 3,
41
- Community: "public",
36
+ CreateVnode: true,
37
+ VnodeDeviceDownThreshold: 3,
38
+ Community: "public",
39
+ DisableLegacyCollection: true,
40
Options: Options{
41
Port: 161,
42
Retries: 1,
@@ -61,8 +59,7 @@ func New() *Collector {
59
newSnmpClient: gosnmp.NewHandler,
60
61
snmpBulkWalkOk: true,
64
- netInterfaces: make(map[string]*netInterface),
65
- collectIfMib: true,
62
+ enableProfiles: true,
63
}
64
}
65
@@ -87,11 +84,10 @@ type Collector struct {
84
snmpBulkWalkOk bool
85
86
// legacy data collection parameters
90
- netIfaceFilterByName matcher.Matcher
91
- netIfaceFilterByType matcher.Matcher
92
- collectIfMib bool // only for tests
93
- netInterfaces map[string]*netInterface
94
- customOids []string
87
+ customOids []string
88
+
89
+ // only for tests
90
+ enableProfiles bool
91
}
92
93
func (c *Collector) Configuration() any {
@@ -107,13 +103,6 @@ func (c *Collector) Init(context.Context) error {
103
return fmt.Errorf("failed to initialize SNMP client: %v", err)
104
}
105
110
- byName, byType, err := c.initNetIfaceFilters()
111
- if err != nil {
112
- return fmt.Errorf("failed to initialize network interface filters: %v", err)
113
- }
114
- c.netIfaceFilterByName = byName
115
- c.netIfaceFilterByType = byType
116
-
106
charts, err := newUserInputCharts(c.ChartsInput)
107
if err != nil {
108
return fmt.Errorf("failed to create user charts: %v", err)
src/go/plugin/go.d/collector/snmp/collector_test.go
+5
-306
@@ -136,27 +136,11 @@ func TestCollector_Charts(t *testing.T) {
136
wantNumCharts int
137
doCollect bool
138
}{
139
- "if-mib, no custom": {
140
- doCollect: true,
141
- wantNumCharts: len(netIfaceChartsTmpl)*4 + 1,
142
- prepareSNMP: func(t *testing.T, m *snmpmock.MockHandler) *Collector {
143
- collr := New()
144
- collr.Config = prepareV2Config()
145
- if collr.EnableProfiles {
146
- setMockClientSysObjectidExpect(m)
147
- }
148
- setMockClientSysinfoAndUptimeExpect(m)
149
- setMockClientIfMibExpect(m)
150
-
151
- return collr
152
- },
153
- },
139
"custom, no if-mib": {
140
wantNumCharts: 10,
141
prepareSNMP: func(t *testing.T, m *snmpmock.MockHandler) *Collector {
142
collr := New()
143
collr.Config = prepareConfigWithUserCharts(prepareV2Config(), 0, 9)
159
- collr.collectIfMib = false
144
145
return collr
146
},
@@ -206,7 +190,6 @@ func TestCollector_Check(t *testing.T) {
190
prepareSNMP: func(m *snmpmock.MockHandler) *Collector {
191
collr := New()
192
collr.Config = prepareConfigWithUserCharts(prepareV2Config(), 0, 3)
209
- collr.collectIfMib = false
193
m.EXPECT().WalkAll(snmputils.RootOidMibSystem).Return(nil, errors.New("mock Get() error")).Times(1)
194
195
return collr
@@ -240,119 +223,11 @@ func TestCollector_Collect(t *testing.T) {
223
prepareSNMP func(m *snmpmock.MockHandler) *Collector
224
wantCollected map[string]int64
225
}{
243
- "success only IF-MIB": {
244
- prepareSNMP: func(m *snmpmock.MockHandler) *Collector {
245
- collr := New()
246
- collr.Config = prepareV2Config()
247
-
248
- if collr.EnableProfiles {
249
- setMockClientSysObjectidExpect(m)
250
- }
251
- setMockClientIfMibExpect(m)
252
-
253
- return collr
254
- },
255
- wantCollected: map[string]int64{
256
- "net_iface_ether1_admin_status_down": 0,
257
- "net_iface_ether1_admin_status_testing": 0,
258
- "net_iface_ether1_admin_status_up": 1,
259
- "net_iface_ether1_bcast_in": 0,
260
- "net_iface_ether1_bcast_out": 0,
261
- "net_iface_ether1_discards_in": 0,
262
- "net_iface_ether1_discards_out": 0,
263
- "net_iface_ether1_errors_in": 0,
264
- "net_iface_ether1_errors_out": 0,
265
- "net_iface_ether1_mcast_in": 0,
266
- "net_iface_ether1_mcast_out": 0,
267
- "net_iface_ether1_oper_status_dormant": 0,
268
- "net_iface_ether1_oper_status_down": 1,
269
- "net_iface_ether1_oper_status_lowerLayerDown": 0,
270
- "net_iface_ether1_oper_status_notPresent": 0,
271
- "net_iface_ether1_oper_status_testing": 0,
272
- "net_iface_ether1_oper_status_unknown": 0,
273
- "net_iface_ether1_oper_status_up": 0,
274
- "net_iface_ether1_traffic_in": 0,
275
- "net_iface_ether1_traffic_out": 0,
276
- "net_iface_ether1_ucast_in": 0,
277
- "net_iface_ether1_ucast_out": 0,
278
- "net_iface_ether2_admin_status_down": 0,
279
- "net_iface_ether2_admin_status_testing": 0,
280
- "net_iface_ether2_admin_status_up": 1,
281
- "net_iface_ether2_bcast_in": 0,
282
- "net_iface_ether2_bcast_out": 7386,
283
- "net_iface_ether2_discards_in": 0,
284
- "net_iface_ether2_discards_out": 0,
285
- "net_iface_ether2_errors_in": 0,
286
- "net_iface_ether2_errors_out": 0,
287
- "net_iface_ether2_mcast_in": 1891,
288
- "net_iface_ether2_mcast_out": 28844,
289
- "net_iface_ether2_oper_status_dormant": 0,
290
- "net_iface_ether2_oper_status_down": 0,
291
- "net_iface_ether2_oper_status_lowerLayerDown": 0,
292
- "net_iface_ether2_oper_status_notPresent": 0,
293
- "net_iface_ether2_oper_status_testing": 0,
294
- "net_iface_ether2_oper_status_unknown": 0,
295
- "net_iface_ether2_oper_status_up": 1,
296
- "net_iface_ether2_traffic_in": 615057509,
297
- "net_iface_ether2_traffic_out": 159677206,
298
- "net_iface_ether2_ucast_in": 71080332,
299
- "net_iface_ether2_ucast_out": 39509661,
300
- "net_iface_sfp-sfpplus1_admin_status_down": 0,
301
- "net_iface_sfp-sfpplus1_admin_status_testing": 0,
302
- "net_iface_sfp-sfpplus1_admin_status_up": 1,
303
- "net_iface_sfp-sfpplus1_bcast_in": 0,
304
- "net_iface_sfp-sfpplus1_bcast_out": 0,
305
- "net_iface_sfp-sfpplus1_discards_in": 0,
306
- "net_iface_sfp-sfpplus1_discards_out": 0,
307
- "net_iface_sfp-sfpplus1_errors_in": 0,
308
- "net_iface_sfp-sfpplus1_errors_out": 0,
309
- "net_iface_sfp-sfpplus1_mcast_in": 0,
310
- "net_iface_sfp-sfpplus1_mcast_out": 0,
311
- "net_iface_sfp-sfpplus1_oper_status_dormant": 0,
312
- "net_iface_sfp-sfpplus1_oper_status_down": 0,
313
- "net_iface_sfp-sfpplus1_oper_status_lowerLayerDown": 0,
314
- "net_iface_sfp-sfpplus1_oper_status_notPresent": 1,
315
- "net_iface_sfp-sfpplus1_oper_status_testing": 0,
316
- "net_iface_sfp-sfpplus1_oper_status_unknown": 0,
317
- "net_iface_sfp-sfpplus1_oper_status_up": 0,
318
- "net_iface_sfp-sfpplus1_traffic_in": 0,
319
- "net_iface_sfp-sfpplus1_traffic_out": 0,
320
- "net_iface_sfp-sfpplus1_ucast_in": 0,
321
- "net_iface_sfp-sfpplus1_ucast_out": 0,
322
- "net_iface_sfp-sfpplus2_admin_status_down": 0,
323
- "net_iface_sfp-sfpplus2_admin_status_testing": 0,
324
- "net_iface_sfp-sfpplus2_admin_status_up": 1,
325
- "net_iface_sfp-sfpplus2_bcast_in": 0,
326
- "net_iface_sfp-sfpplus2_bcast_out": 0,
327
- "net_iface_sfp-sfpplus2_discards_in": 0,
328
- "net_iface_sfp-sfpplus2_discards_out": 0,
329
- "net_iface_sfp-sfpplus2_errors_in": 0,
330
- "net_iface_sfp-sfpplus2_errors_out": 0,
331
- "net_iface_sfp-sfpplus2_mcast_in": 0,
332
- "net_iface_sfp-sfpplus2_mcast_out": 0,
333
- "net_iface_sfp-sfpplus2_oper_status_dormant": 0,
334
- "net_iface_sfp-sfpplus2_oper_status_down": 0,
335
- "net_iface_sfp-sfpplus2_oper_status_lowerLayerDown": 0,
336
- "net_iface_sfp-sfpplus2_oper_status_notPresent": 1,
337
- "net_iface_sfp-sfpplus2_oper_status_testing": 0,
338
- "net_iface_sfp-sfpplus2_oper_status_unknown": 0,
339
- "net_iface_sfp-sfpplus2_oper_status_up": 0,
340
- "net_iface_sfp-sfpplus2_traffic_in": 0,
341
- "net_iface_sfp-sfpplus2_traffic_out": 0,
342
- "net_iface_sfp-sfpplus2_ucast_in": 0,
343
- "net_iface_sfp-sfpplus2_ucast_out": 0,
344
- "uptime": 60,
345
- },
346
- },
226
"success only custom OIDs supported type": {
227
prepareSNMP: func(m *snmpmock.MockHandler) *Collector {
228
collr := New()
229
collr.Config = prepareConfigWithUserCharts(prepareV2Config(), 0, 3)
351
- collr.collectIfMib = false
352
-
353
- if collr.EnableProfiles {
354
- setMockClientSysObjectidExpect(m)
355
- }
230
+ collr.enableProfiles = false
231
232
m.EXPECT().Get(gomock.Any()).Return(&gosnmp.SnmpPacket{
233
Variables: []gosnmp.SnmpPDU{
@@ -379,18 +254,13 @@ func TestCollector_Collect(t *testing.T) {
254
"1.3.6.1.2.1.2.2.1.16.2": 50,
255
"1.3.6.1.2.1.2.2.1.10.3": 60,
256
"1.3.6.1.2.1.2.2.1.16.3": 70,
382
- "uptime": 60,
257
},
258
},
259
"success only custom OIDs supported and unsupported type": {
260
prepareSNMP: func(m *snmpmock.MockHandler) *Collector {
261
collr := New()
262
collr.Config = prepareConfigWithUserCharts(prepareV2Config(), 0, 2)
389
- collr.collectIfMib = false
390
-
391
- if collr.EnableProfiles {
392
- setMockClientSysObjectidExpect(m)
393
- }
263
+ collr.enableProfiles = false
264
265
m.EXPECT().Get(gomock.Any()).Return(&gosnmp.SnmpPacket{
266
Variables: []gosnmp.SnmpPDU{
@@ -410,18 +280,13 @@ func TestCollector_Collect(t *testing.T) {
280
"1.3.6.1.2.1.2.2.1.10.0": 10,
281
"1.3.6.1.2.1.2.2.1.16.0": 20,
282
"1.3.6.1.2.1.2.2.1.10.1": 30,
413
- "uptime": 60,
283
},
284
},
416
- "success only custom OIDs unsupported type": {
285
+ "fails when only custom OIDs unsupported type": {
286
prepareSNMP: func(m *snmpmock.MockHandler) *Collector {
287
collr := New()
288
collr.Config = prepareConfigWithUserCharts(prepareV2Config(), 0, 2)
420
- collr.collectIfMib = false
421
-
422
- if collr.EnableProfiles {
423
- setMockClientSysObjectidExpect(m)
424
- }
289
+ collr.enableProfiles = false
290
291
m.EXPECT().Get(gomock.Any()).Return(&gosnmp.SnmpPacket{
292
Variables: []gosnmp.SnmpPDU{
@@ -436,10 +301,6 @@ func TestCollector_Collect(t *testing.T) {
301
302
return collr
303
},
439
- wantCollected: map[string]int64{
440
- //"TestMetric": 1,
441
- "uptime": 60,
442
- },
304
},
305
}
306
@@ -449,7 +310,7 @@ func TestCollector_Collect(t *testing.T) {
310
defer cleanup()
311
312
setMockClientInitExpect(mockSNMP)
452
- setMockClientSysinfoAndUptimeExpect(mockSNMP)
313
+ setMockClientSysInfoExpect(mockSNMP)
314
315
collr := test.prepareSNMP(mockSNMP)
316
collr.newSnmpClient = func() gosnmp.Handler { return mockSNMP }
@@ -460,10 +321,6 @@ func TestCollector_Collect(t *testing.T) {
321
322
mx := collr.Collect(context.Background())
323
463
- if collr.EnableProfiles {
464
- mx["TestMetric"] = 1
465
- }
466
-
324
assert.Equal(t, test.wantCollected, mx)
325
})
326
}
@@ -598,164 +455,6 @@ func setMockClientSysInfoExpect(m *snmpmock.MockHandler) {
455
}, nil).MinTimes(1)
456
}
457
601
-func setMockClientSysinfoAndUptimeExpect(m *snmpmock.MockHandler) {
602
- setMockClientSysInfoExpect(m)
603
-
604
- m.EXPECT().Get([]string{oidSysUptime}).Return(&gosnmp.SnmpPacket{
605
- Variables: []gosnmp.SnmpPDU{
606
- {Value: uint32(6048), Type: gosnmp.TimeTicks},
607
- },
608
- }, nil).MinTimes(1)
609
-}
610
-
611
-func setMockClientIfMibExpect(m *snmpmock.MockHandler) {
612
- m.EXPECT().WalkAll(rootOidIfMibIfTable).Return([]gosnmp.SnmpPDU{
613
- {Name: oidIfIndex + ".1", Value: 1, Type: gosnmp.Integer},
614
- {Name: oidIfIndex + ".2", Value: 2, Type: gosnmp.Integer},
615
- {Name: oidIfIndex + ".17", Value: 17, Type: gosnmp.Integer},
616
- {Name: oidIfIndex + ".18", Value: 18, Type: gosnmp.Integer},
617
- {Name: oidIfDescr + ".1", Value: []uint8("ether1"), Type: gosnmp.OctetString},
618
- {Name: oidIfDescr + ".2", Value: []uint8("ether2"), Type: gosnmp.OctetString},
619
- {Name: oidIfDescr + ".17", Value: []uint8("sfp-sfpplus2"), Type: gosnmp.OctetString},
620
- {Name: oidIfDescr + ".18", Value: []uint8("sfp-sfpplus1"), Type: gosnmp.OctetString},
621
- {Name: oidIfType + ".1", Value: 6, Type: gosnmp.Integer},
622
- {Name: oidIfType + ".2", Value: 6, Type: gosnmp.Integer},
623
- {Name: oidIfType + ".17", Value: 6, Type: gosnmp.Integer},
624
- {Name: oidIfType + ".18", Value: 6, Type: gosnmp.Integer},
625
- {Name: oidIfMtu + ".1", Value: 1500, Type: gosnmp.Integer},
626
- {Name: oidIfMtu + ".2", Value: 1500, Type: gosnmp.Integer},
627
- {Name: oidIfMtu + ".17", Value: 1500, Type: gosnmp.Integer},
628
- {Name: oidIfMtu + ".18", Value: 1500, Type: gosnmp.Integer},
629
- {Name: oidIfSpeed + ".1", Value: 0, Type: gosnmp.Gauge32},
630
- {Name: oidIfSpeed + ".2", Value: 1000000000, Type: gosnmp.Gauge32},
631
- {Name: oidIfSpeed + ".17", Value: 0, Type: gosnmp.Gauge32},
632
- {Name: oidIfSpeed + ".18", Value: 0, Type: gosnmp.Gauge32},
633
- {Name: oidIfPhysAddress + ".1", Value: decodePhysAddr("18:fd:74:7e:c5:80"), Type: gosnmp.OctetString},
634
- {Name: oidIfPhysAddress + ".2", Value: decodePhysAddr("18:fd:74:7e:c5:81"), Type: gosnmp.OctetString},
635
- {Name: oidIfPhysAddress + ".17", Value: decodePhysAddr("18:fd:74:7e:c5:90"), Type: gosnmp.OctetString},
636
- {Name: oidIfPhysAddress + ".18", Value: decodePhysAddr("18:fd:74:7e:c5:91"), Type: gosnmp.OctetString},
637
- {Name: oidIfAdminStatus + ".1", Value: 1, Type: gosnmp.Integer},
638
- {Name: oidIfAdminStatus + ".2", Value: 1, Type: gosnmp.Integer},
639
- {Name: oidIfAdminStatus + ".17", Value: 1, Type: gosnmp.Integer},
640
- {Name: oidIfAdminStatus + ".18", Value: 1, Type: gosnmp.Integer},
641
- {Name: oidIfOperStatus + ".1", Value: 2, Type: gosnmp.Integer},
642
- {Name: oidIfOperStatus + ".2", Value: 1, Type: gosnmp.Integer},
643
- {Name: oidIfOperStatus + ".17", Value: 6, Type: gosnmp.Integer},
644
- {Name: oidIfOperStatus + ".18", Value: 6, Type: gosnmp.Integer},
645
- {Name: oidIfLastChange + ".1", Value: 0, Type: gosnmp.TimeTicks},
646
- {Name: oidIfLastChange + ".2", Value: 3243, Type: gosnmp.TimeTicks},
647
- {Name: oidIfLastChange + ".17", Value: 0, Type: gosnmp.TimeTicks},
648
- {Name: oidIfLastChange + ".18", Value: 0, Type: gosnmp.TimeTicks},
649
- {Name: oidIfInOctets + ".1", Value: 0, Type: gosnmp.Counter32},
650
- {Name: oidIfInOctets + ".2", Value: 3827243723, Type: gosnmp.Counter32},
651
- {Name: oidIfInOctets + ".17", Value: 0, Type: gosnmp.Counter32},
652
- {Name: oidIfInOctets + ".18", Value: 0, Type: gosnmp.Counter32},
653
- {Name: oidIfInUcastPkts + ".1", Value: 0, Type: gosnmp.Counter32},
654
- {Name: oidIfInUcastPkts + ".2", Value: 71035992, Type: gosnmp.Counter32},
655
- {Name: oidIfInUcastPkts + ".17", Value: 0, Type: gosnmp.Counter32},
656
- {Name: oidIfInUcastPkts + ".18", Value: 0, Type: gosnmp.Counter32},
657
- {Name: oidIfInNUcastPkts + ".1", Value: 0, Type: gosnmp.Counter32},
658
- {Name: oidIfInNUcastPkts + ".2", Value: 0, Type: gosnmp.Counter32},
659
- {Name: oidIfInNUcastPkts + ".17", Value: 0, Type: gosnmp.Counter32},
660
- {Name: oidIfInNUcastPkts + ".18", Value: 0, Type: gosnmp.Counter32},
661
- {Name: oidIfInDiscards + ".1", Value: 0, Type: gosnmp.Counter32},
662
- {Name: oidIfInDiscards + ".2", Value: 0, Type: gosnmp.Counter32},
663
- {Name: oidIfInDiscards + ".17", Value: 0, Type: gosnmp.Counter32},
664
- {Name: oidIfInDiscards + ".18", Value: 0, Type: gosnmp.Counter32},
665
- {Name: oidIfInErrors + ".1", Value: 0, Type: gosnmp.Counter32},
666
- {Name: oidIfInErrors + ".2", Value: 0, Type: gosnmp.Counter32},
667
- {Name: oidIfInErrors + ".17", Value: 0, Type: gosnmp.Counter32},
668
- {Name: oidIfInErrors + ".18", Value: 0, Type: gosnmp.Counter32},
669
- {Name: oidIfInUnknownProtos + ".1", Value: 0, Type: gosnmp.Counter32},
670
- {Name: oidIfInUnknownProtos + ".2", Value: 0, Type: gosnmp.Counter32},
671
- {Name: oidIfInUnknownProtos + ".17", Value: 0, Type: gosnmp.Counter32},
672
- {Name: oidIfInUnknownProtos + ".18", Value: 0, Type: gosnmp.Counter32},
673
- {Name: oidIfOutOctets + ".1", Value: 0, Type: gosnmp.Counter32},
674
- {Name: oidIfOutOctets + ".2", Value: 2769838772, Type: gosnmp.Counter32},
675
- {Name: oidIfOutOctets + ".17", Value: 0, Type: gosnmp.Counter32},
676
- {Name: oidIfOutOctets + ".18", Value: 0, Type: gosnmp.Counter32},
677
- {Name: oidIfOutUcastPkts + ".1", Value: 0, Type: gosnmp.Counter32},
678
- {Name: oidIfOutUcastPkts + ".2", Value: 39482929, Type: gosnmp.Counter32},
679
- {Name: oidIfOutUcastPkts + ".17", Value: 0, Type: gosnmp.Counter32},
680
- {Name: oidIfOutUcastPkts + ".18", Value: 0, Type: gosnmp.Counter32},
681
- {Name: oidIfOutNUcastPkts + ".1", Value: 0, Type: gosnmp.Counter32},
682
- {Name: oidIfOutNUcastPkts + ".2", Value: 0, Type: gosnmp.Counter32},
683
- {Name: oidIfOutNUcastPkts + ".17", Value: 0, Type: gosnmp.Counter32},
684
- {Name: oidIfOutNUcastPkts + ".18", Value: 0, Type: gosnmp.Counter32},
685
- {Name: oidIfOutDiscards + ".1", Value: 0, Type: gosnmp.Counter32},
686
- {Name: oidIfOutDiscards + ".2", Value: 0, Type: gosnmp.Counter32},
687
- {Name: oidIfOutDiscards + ".17", Value: 0, Type: gosnmp.Counter32},
688
- {Name: oidIfOutDiscards + ".18", Value: 0, Type: gosnmp.Counter32},
689
- {Name: oidIfOutErrors + ".1", Value: 0, Type: gosnmp.Counter32},
690
- {Name: oidIfOutErrors + ".2", Value: 0, Type: gosnmp.Counter32},
691
- {Name: oidIfOutErrors + ".17", Value: 0, Type: gosnmp.Counter32},
692
- {Name: oidIfOutErrors + ".18", Value: 0, Type: gosnmp.Counter32},
693
- }, nil).MinTimes(1)
694
-
695
- m.EXPECT().WalkAll(rootOidIfMibIfXTable).Return([]gosnmp.SnmpPDU{
696
- {Name: oidIfName + ".1", Value: []uint8("ether1"), Type: gosnmp.OctetString},
697
- {Name: oidIfName + ".2", Value: []uint8("ether2"), Type: gosnmp.OctetString},
698
- {Name: oidIfName + ".17", Value: []uint8("sfp-sfpplus2"), Type: gosnmp.OctetString},
699
- {Name: oidIfName + ".18", Value: []uint8("sfp-sfpplus1"), Type: gosnmp.OctetString},
700
- {Name: oidIfInMulticastPkts + ".1", Value: 0, Type: gosnmp.Counter32},
701
- {Name: oidIfInMulticastPkts + ".2", Value: 0, Type: gosnmp.Counter32},
702
- {Name: oidIfInMulticastPkts + ".17", Value: 0, Type: gosnmp.Counter32},
703
- {Name: oidIfInMulticastPkts + ".18", Value: 0, Type: gosnmp.Counter32},
704
- {Name: oidIfInBroadcastPkts + ".1", Value: 0, Type: gosnmp.Counter32},
705
- {Name: oidIfInBroadcastPkts + ".2", Value: 0, Type: gosnmp.Counter32},
706
- {Name: oidIfInBroadcastPkts + ".17", Value: 0, Type: gosnmp.Counter32},
707
- {Name: oidIfInBroadcastPkts + ".18", Value: 0, Type: gosnmp.Counter32},
708
- {Name: oidIfOutMulticastPkts + ".1", Value: 0, Type: gosnmp.Counter32},
709
- {Name: oidIfOutMulticastPkts + ".2", Value: 0, Type: gosnmp.Counter32},
710
- {Name: oidIfOutMulticastPkts + ".17", Value: 0, Type: gosnmp.Counter32},
711
- {Name: oidIfOutMulticastPkts + ".18", Value: 0, Type: gosnmp.Counter32},
712
- {Name: oidIfOutBroadcastPkts + ".1", Value: 0, Type: gosnmp.Counter32},
713
- {Name: oidIfOutBroadcastPkts + ".2", Value: 0, Type: gosnmp.Counter32},
714
- {Name: oidIfOutBroadcastPkts + ".17", Value: 0, Type: gosnmp.Counter32},
715
- {Name: oidIfOutBroadcastPkts + ".18", Value: 0, Type: gosnmp.Counter32},
716
- {Name: oidIfHCInOctets + ".1", Value: 0, Type: gosnmp.Counter64},
717
- {Name: oidIfHCInOctets + ".2", Value: 76882188712, Type: gosnmp.Counter64},
718
- {Name: oidIfHCInOctets + ".17", Value: 0, Type: gosnmp.Counter64},
719
- {Name: oidIfHCInOctets + ".18", Value: 0, Type: gosnmp.Counter64},
720
- {Name: oidIfHCInUcastPkts + ".1", Value: 0, Type: gosnmp.Counter64},
721
- {Name: oidIfHCInUcastPkts + ".2", Value: 71080332, Type: gosnmp.Counter64},
722
- {Name: oidIfHCInUcastPkts + ".17", Value: 0, Type: gosnmp.Counter64},
723
- {Name: oidIfHCInUcastPkts + ".18", Value: 0, Type: gosnmp.Counter64},
724
- {Name: oidIfHCInMulticastPkts + ".1", Value: 0, Type: gosnmp.Counter64},
725
- {Name: oidIfHCInMulticastPkts + ".2", Value: 1891, Type: gosnmp.Counter64},
726
- {Name: oidIfHCInMulticastPkts + ".17", Value: 0, Type: gosnmp.Counter64},
727
- {Name: oidIfHCInMulticastPkts + ".18", Value: 0, Type: gosnmp.Counter64},
728
- {Name: oidIfHCInBroadcastPkts + ".1", Value: 0, Type: gosnmp.Counter64},
729
- {Name: oidIfHCInBroadcastPkts + ".2", Value: 0, Type: gosnmp.Counter64},
730
- {Name: oidIfHCInBroadcastPkts + ".17", Value: 0, Type: gosnmp.Counter64},
731
- {Name: oidIfHCInBroadcastPkts + ".18", Value: 0, Type: gosnmp.Counter64},
732
- {Name: oidIfHCOutOctets + ".1", Value: 0, Type: gosnmp.Counter64},
733
- {Name: oidIfHCOutOctets + ".2", Value: 19959650810, Type: gosnmp.Counter64},
734
- {Name: oidIfHCOutOctets + ".17", Value: 0, Type: gosnmp.Counter64},
735
- {Name: oidIfHCOutOctets + ".18", Value: 0, Type: gosnmp.Counter64},
736
- {Name: oidIfHCOutUcastPkts + ".1", Value: 0, Type: gosnmp.Counter64},
737
- {Name: oidIfHCOutUcastPkts + ".2", Value: 39509661, Type: gosnmp.Counter64},
738
- {Name: oidIfHCOutUcastPkts + ".17", Value: 0, Type: gosnmp.Counter64},
739
- {Name: oidIfHCOutUcastPkts + ".18", Value: 0, Type: gosnmp.Counter64},
740
- {Name: oidIfHCOutMulticastPkts + ".1", Value: 0, Type: gosnmp.Counter64},
741
- {Name: oidIfHCOutMulticastPkts + ".2", Value: 28844, Type: gosnmp.Counter64},
742
- {Name: oidIfHCOutMulticastPkts + ".17", Value: 0, Type: gosnmp.Counter64},
743
- {Name: oidIfHCOutMulticastPkts + ".18", Value: 0, Type: gosnmp.Counter64},
744
- {Name: oidIfHCOutBroadcastPkts + ".1", Value: 0, Type: gosnmp.Counter64},
745
- {Name: oidIfHCOutBroadcastPkts + ".2", Value: 7386, Type: gosnmp.Counter64},
746
- {Name: oidIfHCOutBroadcastPkts + ".17", Value: 0, Type: gosnmp.Counter64},
747
- {Name: oidIfHCOutBroadcastPkts + ".18", Value: 0, Type: gosnmp.Counter64},
748
- {Name: oidIfHighSpeed + ".1", Value: 0, Type: gosnmp.Gauge32},
749
- {Name: oidIfHighSpeed + ".2", Value: 1000, Type: gosnmp.Gauge32},
750
- {Name: oidIfHighSpeed + ".17", Value: 0, Type: gosnmp.Gauge32},
751
- {Name: oidIfHighSpeed + ".18", Value: 0, Type: gosnmp.Gauge32},
752
- {Name: oidIfAlias + ".1", Value: []uint8(""), Type: gosnmp.OctetString},
753
- {Name: oidIfAlias + ".2", Value: []uint8("UPLINK2 (2.1)"), Type: gosnmp.OctetString},
754
- {Name: oidIfAlias + ".17", Value: []uint8(""), Type: gosnmp.OctetString},
755
- {Name: oidIfAlias + ".18", Value: []uint8(""), Type: gosnmp.OctetString},
756
- }, nil).MinTimes(1)
757
-}
758
-
458
func decodePhysAddr(s string) []uint8 {
459
s = strings.ReplaceAll(s, ":", "")
460
v, _ := hex.DecodeString(s)
src/go/plugin/go.d/collector/snmp/config.go
+14
-12
@@ -6,21 +6,23 @@ import "github.com/netdata/netdata/go/plugins/plugin/go.d/agent/vnodes"
6
7
type (
8
Config struct {
9
- UpdateEvery int `yaml:"update_every,omitempty" json:"update_every"`
10
- Hostname string `yaml:"hostname" json:"hostname"`
9
+ UpdateEvery int `yaml:"update_every,omitempty" json:"update_every"`
10
+ Hostname string `yaml:"hostname" json:"hostname"`
11
+
12
CreateVnode bool `yaml:"create_vnode,omitempty" json:"create_vnode"`
13
VnodeDeviceDownThreshold int `yaml:"vnode_device_down_threshold,omitempty" json:"vnode_device_down_threshold"`
14
Vnode vnodes.VirtualNode `yaml:"vnode,omitempty" json:"vnode"`
14
- Community string `yaml:"community,omitempty" json:"community"`
15
- User User `yaml:"user,omitempty" json:"user"`
16
- Options Options `yaml:"options,omitempty" json:"options"`
17
-
18
- ChartsInput []ChartConfig `yaml:"charts,omitempty" json:"charts"`
19
- NetworkInterfaceFilter NetworkInterfaceFilter `yaml:"network_interface_filter,omitempty" json:"network_interface_filter"`
20
- EnableProfiles bool `yaml:"enable_profiles,omitempty" json:"enable_profiles"`
21
- EnableProfilesTableMetrics bool `yaml:"enable_profiles_table_metrics,omitempty" json:"enable_profiles_table_metrics"`
22
- DisableLegacyCollection bool `yaml:"disable_legacy_collection,omitempty" json:"disable_legacy_collection"`
23
- ManualProfiles []string `yaml:"manual_profiles,omitempty" json:"manual_profiles"`
15
+
16
+ Community string `yaml:"community,omitempty" json:"community"`
17
+ User User `yaml:"user,omitempty" json:"user"`
18
+
19
+ Options Options `yaml:"options,omitempty" json:"options"`
20
+
21
+ ManualProfiles []string `yaml:"manual_profiles,omitempty" json:"manual_profiles"`
22
+
23
+ // legacy
24
+ ChartsInput []ChartConfig `yaml:"charts,omitempty" json:"charts"`
25
+ DisableLegacyCollection bool `yaml:"disable_legacy_collection,omitempty" json:"disable_legacy_collection"`
26
}
27
NetworkInterfaceFilter struct {
28
ByName string `yaml:"by_name,omitempty" json:"by_name"`
src/go/plugin/go.d/collector/snmp/config_schema.json
+3
-47
@@ -65,26 +65,6 @@
65
}
66
}
67
},
68
- "network_interface_filter": {
69
- "title": "Network interface filter",
70
- "description": "Configuration for filtering specific network interfaces. If left empty, no interfaces will be filtered. You can filter interfaces by name or type using [simple patterns](/src/libnetdata/simple_pattern/README.md#simple-patterns).",
71
- "type": [
72
- "object",
73
- "null"
74
- ],
75
- "properties": {
76
- "by_name": {
77
- "title": "By Name",
78
- "description": "Specify the interface name or a pattern to match against the [ifName](https://cric.grenoble.cnrs.fr/Administrateurs/Outils/MIBS/?oid=1.3.6.1.2.1.31.1.1.1.1) label.",
79
- "type": "string"
80
- },
81
- "by_type": {
82
- "title": "By Type",
83
- "description": "Specify the interface type or a pattern to match against the [ifType](https://cric.grenoble.cnrs.fr/Administrateurs/Outils/MIBS/?oid=1.3.6.1.2.1.2.2.1.3) label.",
84
- "type": "string"
85
- }
86
- }
87
- },
68
"options": {
69
"title": "Options",
70
"description": "Configuration options for SNMP monitoring.",
@@ -350,23 +330,11 @@
330
]
331
}
332
},
353
- "enable_profiles": {
354
- "title": "Enable SNMP Profile Collection",
355
- "description": "Enable collection of metrics using SNMP profiles.",
356
- "type": "boolean",
357
- "default": true
358
- },
359
- "enable_profiles_table_metrics": {
360
- "title": "Enable SNMP Table Metrics",
361
- "description": "Enable collection of SNMP table metrics from profiles. Enabling this may **increase collection time and memory usage** for devices with many network interfaces*.",
362
- "type": "boolean",
363
- "default": true
364
- },
333
"disable_legacy_collection": {
334
"title": "Disable Legacy SNMP Collection",
335
"description": "Disable the legacy SNMP collection method, forcing the collector to use only SNMP profiles (YAML-based configuration). When enabled, the collector will ignore any non-profile based collection logic.",
336
"type": "boolean",
369
- "default": false
337
+ "default": true
338
},
339
"manual_profiles": {
340
"title": "Manual SNMP Profiles",
@@ -392,19 +360,10 @@
360
"uiOptions": {
361
"fullPage": true
362
},
395
- "enable_profiles": {
396
- "ui:help": "Profiles provide pre-configured monitoring for specific device models and MIBs, including network interfaces, system information, and device-specific metrics."
397
- },
398
- "enable_profiles_table_metrics": {
399
- "ui:help": "Table metrics include interface statistics, routing tables, and other tabular data."
400
- },
363
"manual_profiles": {
364
"ui:listFlavour": "list",
365
"ui:help": "**Profiles are always applied automatically** based on the device sysObjectID. **If no sysObjectID is provided** (rare case, e.g. some printers), the profiles listed here will be applied instead. In most cases, **leave this empty**."
366
},
405
- "network_interface_filter": {
406
- "ui:collapsible": true
407
- },
367
"community": {
368
"ui:widget": "password"
369
},
@@ -495,7 +454,6 @@
454
{
455
"title": "Options",
456
"fields": [
498
- "network_interface_filter",
457
"options"
458
]
459
},
@@ -514,10 +472,8 @@
472
{
473
"title": "Profiles",
474
"fields": [
517
- "enable_profiles",
518
- "enable_profiles_table_metrics",
519
- "disable_legacy_collection",
520
- "manual_profiles"
475
+ "manual_profiles",
476
+ "disable_legacy_collection"
477
]
478
}
479
]
src/go/plugin/go.d/collector/snmp/ddsnmp/ddsnmpcollector/collector.go
+4
-8
@@ -53,8 +53,6 @@ type (
53
scalarCollector *scalarCollector
54
tableCollector *tableCollector
55
vmetricsCollector *vmetricsCollector
56
-
57
- DoTableMetrics bool
56
}
57
profileState struct {
58
profile *ddsnmp.Profile
@@ -160,13 +158,11 @@ func (c *Collector) collectProfile(ps *profileState) (*ddsnmp.ProfileMetrics, er
158
}
159
metrics = append(metrics, scalarMetrics...)
160
163
- if c.DoTableMetrics {
164
- tableMetrics, err := c.tableCollector.Collect(ps.profile)
165
- if err != nil {
166
- return nil, err
167
- }
168
- metrics = append(metrics, tableMetrics...)
161
+ tableMetrics, err := c.tableCollector.Collect(ps.profile)
162
+ if err != nil {
163
+ return nil, err
164
}
165
+ metrics = append(metrics, tableMetrics...)
166
167
pm := &ddsnmp.ProfileMetrics{
168
Source: ps.profile.SourceFile,
src/go/plugin/go.d/collector/snmp/ddsnmp/ddsnmpcollector/collector_table_test.go
-1
@@ -4613,7 +4613,6 @@ func TestCollector_Collect_TableCaching(t *testing.T) {
4613
tc.setupMock(mockHandler)
4614
4615
collector := New(mockHandler, tc.profiles, logger.New(), "")
4616
- collector.DoTableMetrics = true
4616
4617
// Configure cache based on test requirements
4618
if tc.enableCache {
src/go/plugin/go.d/collector/snmp/init.go
-24
@@ -10,8 +10,6 @@ import (
10
11
"github.com/google/uuid"
12
"github.com/gosnmp/gosnmp"
13
-
14
- "github.com/netdata/netdata/go/plugins/pkg/matcher"
13
)
14
15
func (c *Collector) validateConfig() error {
@@ -69,28 +67,6 @@ func (c *Collector) initSNMPClient() (gosnmp.Handler, error) {
67
return client, nil
68
}
69
72
-func (c *Collector) initNetIfaceFilters() (matcher.Matcher, matcher.Matcher, error) {
73
- byName, byType := matcher.FALSE(), matcher.FALSE()
74
-
75
- if v := c.NetworkInterfaceFilter.ByName; v != "" {
76
- m, err := matcher.NewSimplePatternsMatcher(v)
77
- if err != nil {
78
- return nil, nil, err
79
- }
80
- byName = m
81
- }
82
-
83
- if v := c.NetworkInterfaceFilter.ByType; v != "" {
84
- m, err := matcher.NewSimplePatternsMatcher(v)
85
- if err != nil {
86
- return nil, nil, err
87
- }
88
- byType = m
89
- }
90
-
91
- return byName, byType, nil
92
-}
93
-
70
func (c *Collector) initOIDs() (oids []string) {
71
for _, c := range *c.charts {
72
for _, d := range c.Dims {
src/go/plugin/go.d/collector/snmp/metadata.yaml
+4
-20
@@ -199,20 +199,15 @@ modules:
199
default_value: 60
200
required: false
201
202
- - name: enable_profiles
202
+ - name: manual_profiles
203
group: Profiles
204
- description: Enable collection of metrics using SNMP profiles.
205
- default_value: "true"
206
- required: false
207
- - name: enable_profiles_table_metrics
208
- group: Profiles
209
- description: Enable collection of SNMP table metrics from profiles. Enabling this may **increase collection time and memory usage** for devices with many network interfaces.
210
- default_value: "true"
204
+ description: Profiles to apply if automatic detection cannot be used.
205
+ default_value: "[]"
206
required: false
207
- name: disable_legacy_collection
208
group: Profiles
209
description: Disable the legacy SNMP collection method, forcing the collector to use only SNMP profiles (YAML-based configuration). When enabled, the collector will ignore any non-profile based collection logic.
215
- default_value: "false"
210
+ default_value: "true"
211
required: false
212
213
- name: create_vnode
@@ -240,17 +235,6 @@ modules:
235
description: Additional key-value pairs to associate with the Virtual Node.
236
default_value: ""
237
required: false
243
-
244
- - name: network_interface_filter.by_name
245
- group: Filters
246
- description: "Filter interfaces by their names using [simple patterns](/src/libnetdata/simple_pattern/README.md#simple-patterns)."
247
- default_value: ""
248
- required: false
249
- - name: network_interface_filter.by_type
250
- group: Filters
251
- description: "Filter interfaces by their types using [simple patterns](/src/libnetdata/simple_pattern/README.md#simple-patterns)."
252
- default_value: ""
253
- required: false
238
examples:
239
folding:
240
title: Config
src/go/plugin/go.d/collector/snmp/testdata/config.json
-6
@@ -12,10 +12,6 @@
12
}
13
},
14
"community": "ok",
15
- "network_interface_filter": {
16
- "by_name": "ok",
17
- "by_type": "ok"
18
- },
15
"user": {
16
"name": "ok",
17
"level": "ok",
@@ -54,8 +50,6 @@
50
]
51
}
52
],
57
- "enable_profiles": true,
58
- "enable_profiles_table_metrics": true,
53
"disable_legacy_collection": true,
54
"manual_profiles": [
55
"ok"
src/go/plugin/go.d/collector/snmp/testdata/config.yaml
-5
@@ -2,8 +2,6 @@ update_every: 123
2
hostname: "ok"
3
create_vnode: yes
4
vnode_device_down_threshold: 123
5
-enable_profiles: yes
6
-enable_profiles_table_metrics: yes
5
disable_legacy_collection: yes
6
manual_profiles:
7
- "ok"
@@ -14,9 +12,6 @@ vnode:
12
labels:
13
ok: "ok"
14
community: "ok"
17
-network_interface_filter:
18
- by_name: "ok"
19
- by_type: "ok"
15
user:
16
name: "ok"
17
level: "ok"