From 520f00f1724a22d0b32287cb618e0481d49d9a42 Mon Sep 17 00:00:00 2001 From: imranalisyed506 <105209301+imranalisyed506@users.noreply.github.com> Date: Wed, 15 Jan 2025 13:38:20 +0530 Subject: [PATCH] [Cisco Meraki] Improve Error handling in cisco meraki collector (#384) --- collectors/ciscomeraki/collector.js | 12 +++--------- collectors/ciscomeraki/meraki_client.js | 7 ++++++- collectors/ciscomeraki/package.json | 2 +- ps_spec.yml | 2 +- 4 files changed, 11 insertions(+), 12 deletions(-) diff --git a/collectors/ciscomeraki/collector.js b/collectors/ciscomeraki/collector.js index 866d8601..2f744e15 100644 --- a/collectors/ciscomeraki/collector.js +++ b/collectors/ciscomeraki/collector.js @@ -20,7 +20,6 @@ const MAX_POLL_INTERVAL = 900; const API_THROTTLING_ERROR = 429; const API_NOT_FOUND_ERROR = 404; const NOT_FOUND_ERROR_MAX_RETRIES = 3; -const PRODUCT_TYPE_NOTAPPLICABLE_MESSAGE = "productType is not applicable to this network"; const typeIdPaths = [{ path: ["type"] }]; const tsPaths = [{ path: ["occurredAt"] }]; @@ -187,14 +186,9 @@ class CiscomerakiCollector extends PawsCollector { return callback(error); } } else if (error && error.response && error.response.data) { - if (error.response.data.errors == PRODUCT_TYPE_NOTAPPLICABLE_MESSAGE) { - AlLogger.warn(`CMRI0000023 ${error.response.data.errors} : ${state.networkId}`); - return callback(null, [], state, state.poll_interval_sec); - } else { - AlLogger.debug(`CMRI0000022 error ${error.response.data.errors} - status: ${error.response.status}`); - error.response.data.errorCode = error.response.status; - return callback(error.response.data); - } + AlLogger.debug(`CMRI0000022 error ${error.response.data.errors} - status: ${error.response.status}`); + error.response.data.errorCode = error.response.status; + return callback(error.response.data); } else { return callback(error); } diff --git a/collectors/ciscomeraki/meraki_client.js b/collectors/ciscomeraki/meraki_client.js index 9885ba14..758534ed 100644 --- a/collectors/ciscomeraki/meraki_client.js +++ b/collectors/ciscomeraki/meraki_client.js @@ -8,6 +8,7 @@ const NETWORKS_PER_PAGE = 1000; const EVENTS_PER_PAGE = 500; const API_THROTTLING_ERROR = 429; const DEFAULT_RETRY_DELAY_MILLIS = 1000; +const PRODUCT_TYPE_NOTAPPLICABLE_MESSAGE = "productType is not applicable to this network"; async function getAPILogs(apiDetails, accumulator, apiEndpoint, state, clientSecret, maxPagesPerInvocation) { let nextPage; @@ -55,7 +56,11 @@ async function getAPILogs(apiDetails, accumulator, apiEndpoint, state, clientSec throw new Error(`CMRI000007 Error:NetworkId required in ${url}`); } } catch (error) { - throw error; + if (error && error.response && error.response.data && (error.response.data.errors == PRODUCT_TYPE_NOTAPPLICABLE_MESSAGE)) { + AlLogger.warn(`CMRI0000027 ${productType} ${error.response.data.errors} : ${state.networkId}`); + } else { + throw error; + } } } else { nextPage = since; diff --git a/collectors/ciscomeraki/package.json b/collectors/ciscomeraki/package.json index e7b194bb..507d0a9a 100644 --- a/collectors/ciscomeraki/package.json +++ b/collectors/ciscomeraki/package.json @@ -1,6 +1,6 @@ { "name": "ciscomeraki-collector", - "version": "1.0.6", + "version": "1.0.7", "description": "Alert Logic AWS based Cisco Meraki Log Collector", "repository": {}, "private": true, diff --git a/ps_spec.yml b/ps_spec.yml index c65636f3..f715c9f0 100644 --- a/ps_spec.yml +++ b/ps_spec.yml @@ -139,7 +139,7 @@ stages: - ./build_collector.sh ciscomeraki env: ALPS_SERVICE_NAME: "paws-ciscomeraki-collector" - ALPS_SERVICE_VERSION: "1.0.6" #set the value from collector package json + ALPS_SERVICE_VERSION: "1.0.7" #set the value from collector package json outputs: file: ./ciscomeraki-collector* packagers: