diff --git a/pkg/collector/corechecks/network-devices/cisco-sdwan/sdwan.go b/pkg/collector/corechecks/network-devices/cisco-sdwan/sdwan.go index ef83846480266..49cd35622b15f 100644 --- a/pkg/collector/corechecks/network-devices/cisco-sdwan/sdwan.go +++ b/pkg/collector/corechecks/network-devices/cisco-sdwan/sdwan.go @@ -44,6 +44,7 @@ type checkCfg struct { CAFile string `yaml:"ca_file"` SendNDMMetadata *bool `yaml:"send_ndm_metadata"` MinCollectionInterval int `yaml:"min_collection_interval"` + CollectBFDSessionStatus bool `yaml:"collect_bfd_session_status"` } // CiscoSdwanCheck contains the field for the CiscoSdwanCheck @@ -99,10 +100,6 @@ func (c *CiscoSdwanCheck) Run() error { if err != nil { log.Warnf("Error getting OMP peer states from Cisco SD-WAN API: %s", err) } - bfdSessionsState, err := client.GetBFDSessionsState() - if err != nil { - log.Warnf("Error getting BFD session states from Cisco SD-WAN API: %s", err) - } deviceCounters, err := client.GetDevicesCounters() if err != nil { log.Warnf("Error getting device counters from Cisco SD-WAN API: %s", err) @@ -128,10 +125,18 @@ func (c *CiscoSdwanCheck) Run() error { c.metricsSender.SendAppRouteMetrics(appRouteStats) c.metricsSender.SendControlConnectionMetrics(controlConnectionsState) c.metricsSender.SendOMPPeerMetrics(ompPeersState) - c.metricsSender.SendBFDSessionMetrics(bfdSessionsState) c.metricsSender.SendDeviceCountersMetrics(deviceCounters) c.metricsSender.SendDeviceStatusMetrics(deviceStatus) + // Configurable metrics + if c.config.CollectBFDSessionStatus { + bfdSessionsState, err := client.GetBFDSessionsState() + if err != nil { + log.Warnf("Error getting BFD session states from Cisco SD-WAN API: %s", err) + } + c.metricsSender.SendBFDSessionMetrics(bfdSessionsState) + } + // Commit c.metricsSender.Commit() diff --git a/pkg/collector/corechecks/network-devices/cisco-sdwan/sdwan_test.go b/pkg/collector/corechecks/network-devices/cisco-sdwan/sdwan_test.go index 5bb150b5fd80f..4a2ee3b622951 100644 --- a/pkg/collector/corechecks/network-devices/cisco-sdwan/sdwan_test.go +++ b/pkg/collector/corechecks/network-devices/cisco-sdwan/sdwan_test.go @@ -68,6 +68,7 @@ password: 'test-password' use_http: true namespace: test min_collection_interval: 180 +collect_bfd_session_status: true `) // Use ID to ensure the mock sender gets registered @@ -217,5 +218,46 @@ min_collection_interval: 180 assert.NoError(t, err) sender.AssertEventPlatformEvent(t, compactEvent.Bytes(), "network-devices-metadata") +} + +func TestBFDMetricConfig(t *testing.T) { + payload.TimeNow = mockTimeNow + report.TimeNow = mockTimeNow + + apiMockServer := client.SetupMockAPIServer() + defer apiMockServer.Close() + + deps := createDeps(t) + chk := newCheck() + senderManager := deps.Demultiplexer + + url := strings.TrimPrefix(apiMockServer.URL, "http://") + + // language=yaml + rawInstanceConfig := []byte(` +vmanage_endpoint: ` + url + ` +username: admin +password: 'test-password' +use_http: true +namespace: test +`) + + // Use ID to ensure the mock sender gets registered + id := checkid.BuildID(CheckName, integration.FakeConfigHash, rawInstanceConfig, []byte(``)) + sender := mocksender.NewMockSenderWithSenderManager(id, senderManager) + sender.On("Gauge", mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return() + sender.On("MonotonicCount", mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return() + sender.On("GaugeWithTimestamp", mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return() + sender.On("CountWithTimestamp", mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return() + sender.On("EventPlatformEvent", mock.Anything, mock.Anything).Return() + + sender.On("Commit").Return() + + err := chk.Configure(senderManager, integration.FakeConfigHash, rawInstanceConfig, []byte(``), "test") + require.NoError(t, err) + + err = chk.Run() + require.NoError(t, err) + sender.AssertNotCalled(t, "Gauge", "cisco_sdwan.bfd_session.status", mock.Anything, mock.Anything, mock.Anything) }