From 14e0802a0659d760d80f5b3779ada15acfd25577 Mon Sep 17 00:00:00 2001 From: Gabriel Pop Date: Wed, 22 Jan 2025 16:58:12 +0200 Subject: [PATCH 1/4] dont error in getDeviceLicenses --- .../meraki/device_health/device_health.go | 5 +---- .../module/meraki/device_health/devices.go | 21 ++++++++----------- 2 files changed, 10 insertions(+), 16 deletions(-) diff --git a/x-pack/metricbeat/module/meraki/device_health/device_health.go b/x-pack/metricbeat/module/meraki/device_health/device_health.go index bbe301b3b43..d13d9de5051 100644 --- a/x-pack/metricbeat/module/meraki/device_health/device_health.go +++ b/x-pack/metricbeat/module/meraki/device_health/device_health.go @@ -105,10 +105,7 @@ func (m *MetricSet) Fetch(reporter mb.ReporterV2) error { return fmt.Errorf("getDeviceChannelUtilization failed; %w", err) } - err = getDeviceLicenses(m.client, org, devices) - if err != nil { - return fmt.Errorf("getDeviceLicenses failed; %w", err) - } + getDeviceLicenses(m.client, org, devices) err = getDeviceUplinks(m.client, org, devices, collectionPeriod) if err != nil { diff --git a/x-pack/metricbeat/module/meraki/device_health/devices.go b/x-pack/metricbeat/module/meraki/device_health/devices.go index c76b76def78..61fbf60fa9b 100644 --- a/x-pack/metricbeat/module/meraki/device_health/devices.go +++ b/x-pack/metricbeat/module/meraki/device_health/devices.go @@ -147,20 +147,17 @@ func getDeviceChannelUtilization(client *meraki.Client, devices map[Serial]*Devi return nil } -func getDeviceLicenses(client *meraki.Client, organizationID string, devices map[Serial]*Device) error { - val, res, err := client.Organizations.GetOrganizationLicenses(organizationID, &meraki.GetOrganizationLicensesQueryParams{}) - if err != nil { - return fmt.Errorf("GetOrganizationLicenses failed; [%d] %s. %w", res.StatusCode(), res.Body(), err) - } - - for i := range *val { - license := (*val)[i] - if device, ok := devices[Serial(license.DeviceSerial)]; ok { - device.license = &license +func getDeviceLicenses(client *meraki.Client, organizationID string, devices map[Serial]*Device) { + val, _, _ := client.Organizations.GetOrganizationLicenses(organizationID, &meraki.GetOrganizationLicensesQueryParams{}) + + if val != nil { + for i := range *val { + license := (*val)[i] + if device, ok := devices[Serial(license.DeviceSerial)]; ok { + device.license = &license + } } } - - return nil } func deviceDetailsToMapstr(details *meraki.ResponseItemOrganizationsGetOrganizationDevices) mapstr.M { From 41ddd0875353d46a014e76f0cbf1931061e6becf Mon Sep 17 00:00:00 2001 From: Gabriel Pop Date: Wed, 22 Jan 2025 17:02:42 +0200 Subject: [PATCH 2/4] add changelog entry --- CHANGELOG.next.asciidoc | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.next.asciidoc b/CHANGELOG.next.asciidoc index 6541ac59e12..20412ca2aba 100644 --- a/CHANGELOG.next.asciidoc +++ b/CHANGELOG.next.asciidoc @@ -242,6 +242,7 @@ https://github.com/elastic/beats/compare/v8.8.1\...main[Check the HEAD diff] - [K8s Integration] Enhance HTTP authentication in case of token updates for Apiserver, Controllermanager and Scheduler metricsets {issue}41910[41910] {pull}42016[42016] - Fixed `creation_date` scientific notation output in the `elasticsearch.index` metricset. {pull}42053[42053] - Fix bug where metricbeat unintentionally triggers Windows ASR. {pull}42177[42177] +- Continue collecting metrics even if the Cisco Meraki `getDeviceLicenses` operation fails. {pull}0[0] *Osquerybeat* From 0832462fd2d839b3868df09ce25e105254f05512 Mon Sep 17 00:00:00 2001 From: Gabriel Pop Date: Wed, 22 Jan 2025 17:12:58 +0200 Subject: [PATCH 3/4] fix pr id --- CHANGELOG.next.asciidoc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.next.asciidoc b/CHANGELOG.next.asciidoc index 20412ca2aba..9deff4c9096 100644 --- a/CHANGELOG.next.asciidoc +++ b/CHANGELOG.next.asciidoc @@ -242,7 +242,7 @@ https://github.com/elastic/beats/compare/v8.8.1\...main[Check the HEAD diff] - [K8s Integration] Enhance HTTP authentication in case of token updates for Apiserver, Controllermanager and Scheduler metricsets {issue}41910[41910] {pull}42016[42016] - Fixed `creation_date` scientific notation output in the `elasticsearch.index` metricset. {pull}42053[42053] - Fix bug where metricbeat unintentionally triggers Windows ASR. {pull}42177[42177] -- Continue collecting metrics even if the Cisco Meraki `getDeviceLicenses` operation fails. {pull}0[0] +- Continue collecting metrics even if the Cisco Meraki `getDeviceLicenses` operation fails. {pull}42397[42397] *Osquerybeat* From 052ee700e382b9e5642a99293632a43296c1427f Mon Sep 17 00:00:00 2001 From: Gabriel Pop Date: Wed, 22 Jan 2025 17:15:43 +0200 Subject: [PATCH 4/4] keep error and check for bad request --- .../meraki/device_health/device_health.go | 5 +++- .../module/meraki/device_health/devices.go | 25 ++++++++++++------- 2 files changed, 20 insertions(+), 10 deletions(-) diff --git a/x-pack/metricbeat/module/meraki/device_health/device_health.go b/x-pack/metricbeat/module/meraki/device_health/device_health.go index d13d9de5051..bbe301b3b43 100644 --- a/x-pack/metricbeat/module/meraki/device_health/device_health.go +++ b/x-pack/metricbeat/module/meraki/device_health/device_health.go @@ -105,7 +105,10 @@ func (m *MetricSet) Fetch(reporter mb.ReporterV2) error { return fmt.Errorf("getDeviceChannelUtilization failed; %w", err) } - getDeviceLicenses(m.client, org, devices) + err = getDeviceLicenses(m.client, org, devices) + if err != nil { + return fmt.Errorf("getDeviceLicenses failed; %w", err) + } err = getDeviceUplinks(m.client, org, devices, collectionPeriod) if err != nil { diff --git a/x-pack/metricbeat/module/meraki/device_health/devices.go b/x-pack/metricbeat/module/meraki/device_health/devices.go index 61fbf60fa9b..fc612744512 100644 --- a/x-pack/metricbeat/module/meraki/device_health/devices.go +++ b/x-pack/metricbeat/module/meraki/device_health/devices.go @@ -147,17 +147,24 @@ func getDeviceChannelUtilization(client *meraki.Client, devices map[Serial]*Devi return nil } -func getDeviceLicenses(client *meraki.Client, organizationID string, devices map[Serial]*Device) { - val, _, _ := client.Organizations.GetOrganizationLicenses(organizationID, &meraki.GetOrganizationLicensesQueryParams{}) - - if val != nil { - for i := range *val { - license := (*val)[i] - if device, ok := devices[Serial(license.DeviceSerial)]; ok { - device.license = &license - } +func getDeviceLicenses(client *meraki.Client, organizationID string, devices map[Serial]*Device) error { + val, res, err := client.Organizations.GetOrganizationLicenses(organizationID, &meraki.GetOrganizationLicensesQueryParams{}) + if err != nil { + // Ignore 400 error for per-device licensing not supported + if res.StatusCode() == 400 { + return nil + } + return fmt.Errorf("GetOrganizationLicenses failed; [%d] %s. %w", res.StatusCode(), res.Body(), err) + } + + for i := range *val { + license := (*val)[i] + if device, ok := devices[Serial(license.DeviceSerial)]; ok { + device.license = &license } } + + return nil } func deviceDetailsToMapstr(details *meraki.ResponseItemOrganizationsGetOrganizationDevices) mapstr.M {