Skip to content

Commit

Permalink
[8.x](backport #41622) [meraki] Log getDevicePerformanceScores erro…
Browse files Browse the repository at this point in the history
…rs (#41659)

* [meraki] Log `getDevicePerformanceScores` errors (#41622)

* log getDevicePerformanceScores errors

* add changelog entry

* fix PR id

* Update x-pack/metricbeat/module/meraki/device_health/devices.go

Co-authored-by: Tom Myers <[email protected]>

* Update x-pack/metricbeat/module/meraki/device_health/devices.go

Co-authored-by: Vihas Makwana <[email protected]>

* fix imports

---------

Co-authored-by: Tom Myers <[email protected]>
Co-authored-by: Vihas Makwana <[email protected]>
(cherry picked from commit f35602f)

* Update CHANGELOG.next.asciidoc

---------

Co-authored-by: Gabriel Pop <[email protected]>
  • Loading branch information
mergify[bot] and gpop63 authored Nov 18, 2024
1 parent aed4f01 commit d1e9e8e
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 8 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.next.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,8 @@ https://github.com/elastic/beats/compare/v8.8.1\...main[Check the HEAD diff]
- Use namespace for GetListMetrics when exists in AWS {pull}41022[41022]
- Fix http server helper SSL config. {pull}39405[39405]
- Fix Kubernetes metadata sometimes not being present after startup {pull}41216[41216]
- Log Cisco Meraki `getDevicePerformanceScores` errors without stopping metrics collection. {pull}41622[41622]


*Osquerybeat*

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,10 +98,7 @@ func (m *MetricSet) Fetch(reporter mb.ReporterV2) error {
return fmt.Errorf("getDeviceStatuses failed; %w", err)
}

err = getDevicePerformanceScores(m.client, devices)
if err != nil {
return fmt.Errorf("getDevicePerformanceScores failed; %w", err)
}
getDevicePerformanceScores(m.logger, m.client, devices)

err = getDeviceChannelUtilization(m.client, devices, collectionPeriod)
if err != nil {
Expand Down
12 changes: 8 additions & 4 deletions x-pack/metricbeat/module/meraki/device_health/devices.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@ package device_health

import (
"fmt"
"net/http"
"strings"
"time"

"github.com/elastic/beats/v7/metricbeat/mb"
"github.com/elastic/elastic-agent-libs/logp"
"github.com/elastic/elastic-agent-libs/mapstr"

meraki "github.com/meraki/dashboard-api-go/v3/sdk"
Expand Down Expand Up @@ -67,7 +69,7 @@ func getDeviceStatuses(client *meraki.Client, organizationID string, devices map
return nil
}

func getDevicePerformanceScores(client *meraki.Client, devices map[Serial]*Device) error {
func getDevicePerformanceScores(logger *logp.Logger, client *meraki.Client, devices map[Serial]*Device) {
for _, device := range devices {
// attempting to get a performance score for a non-MX device returns a 400
if strings.Index(device.details.Model, "MX") != 0 {
Expand All @@ -76,16 +78,18 @@ func getDevicePerformanceScores(client *meraki.Client, devices map[Serial]*Devic

val, res, err := client.Appliance.GetDeviceAppliancePerformance(device.details.Serial)
if err != nil {
return fmt.Errorf("GetDeviceAppliancePerformance failed; [%d] %s. %w", res.StatusCode(), res.Body(), err)
if !(res.StatusCode() != http.StatusBadRequest && strings.Contains(string(res.Body()), "Feature not supported")) {
logger.Errorf("GetDeviceAppliancePerformance failed; [%d] %s. %v", res.StatusCode(), res.Body(), err)
}

continue
}

// 204 indicates there is no data for the device, it's likely 'offline' or 'dormant'
if res.StatusCode() != 204 {
device.performanceScore = val
}
}

return nil
}

func getDeviceChannelUtilization(client *meraki.Client, devices map[Serial]*Device, period time.Duration) error {
Expand Down

0 comments on commit d1e9e8e

Please sign in to comment.