From 739cd36ce76f68423b7e4ec6a7ef0ad8e03d7655 Mon Sep 17 00:00:00 2001 From: Ishan Shah Date: Fri, 9 Feb 2024 16:30:05 +0530 Subject: [PATCH] Commit with debugging codes and comments --- ciscoise.json | 2 +- ciscoise_connector.py | 40 +++++++++++++++++++++++++++++----------- ciscoise_consts.py | 2 +- 3 files changed, 31 insertions(+), 13 deletions(-) diff --git a/ciscoise.json b/ciscoise.json index 127614d..eee1fe2 100644 --- a/ciscoise.json +++ b/ciscoise.json @@ -5,7 +5,7 @@ "publisher": "Splunk", "type": "network security", "main_module": "ciscoise_connector.py", - "app_version": "3.0.2", + "app_version": "3.0.5", "utctime_updated": "2022-03-11T04:16:56.000000Z", "package_name": "phantom_ciscoise", "product_vendor": "Cisco Systems", diff --git a/ciscoise_connector.py b/ciscoise_connector.py index 67d32b8..e0ddbc5 100644 --- a/ciscoise_connector.py +++ b/ciscoise_connector.py @@ -49,7 +49,7 @@ class CiscoISEConnector(BaseConnector): ACTION_ID_DELETE_POLICY = "delete_policy" def __init__(self): - + self.my_state = {} # Call the BaseConnectors init first super(CiscoISEConnector, self).__init__() @@ -124,6 +124,8 @@ def _call_ers_api(self, endpoint, action_result, data=None, allow_unknown=True, if try_ha_device: url = "{0}{1}".format(self._ha_device_url, endpoint) + self.debug_print("url = {}".format(url)) + ret_data = None config = self.get_config() @@ -142,6 +144,7 @@ def _call_ers_api(self, endpoint, action_result, data=None, allow_unknown=True, headers=headers, auth=auth_method ) + except Exception as e: self.debug_print("Exception occurred: {}".format(e)) return action_result.set_status(phantom.APP_ERROR, CISCOISE_ERROR_REST_API, e), ret_data @@ -424,36 +427,51 @@ def _terminate_session(self, param): return action_result.set_status(phantom.APP_SUCCESS, CISCOISE_SUCC_SESSION_TERMINATED) - def _paginator(self, endpoint, action_result, payload=None, limit=None): + def _paginator(self, endpoint, action_result, param=None, limit=None): items_list = list() - if not payload: + if not param: payload = {} - page = 1 - payload["size"] = DEFAULT_MAX_RESULTS - payload["page"] = page + count = 1 + # param["size"] = DEFAULT_MAX_RESULTS + # param["page"] = page while True: ret_val, items = self._call_ers_api(endpoint, action_result, data=payload) - + self.my_state[count] = items if phantom.is_fail(ret_val): + self.debug_print("Saving state for Cisco ISE 1: {}".format(self.my_state)) + self.save_state(self.my_state) return None items_list.extend(items.get("SearchResult", {}).get("resources")) + next_page_dict = items.get("SearchResult", {}).get("nextPage") + + if next_page_dict is not None: + endpoint = next_page_dict.get("href").replace(self._base_url, "") + self.debug_print("endpoint = {}".format(endpoint)) + else: + break + if limit and len(items_list) >= limit: + self.debug_print("Saving state for Cisco ISE 2: {}".format(self.my_state)) + self.save_state(self.my_state) return items_list[:limit] - if len(items.get("SearchResult", {}).get("resources")) < DEFAULT_MAX_RESULTS: - break + # if len(items.get("SearchResult", {}).get("resources")) < DEFAULT_MAX_RESULTS: + # break if len(items_list) == items.get("SearchResult", {}).get("total"): break - page = page + 1 - payload["page"] = page + count = count + 1 + # payload["page"] = page + + self.debug_print("Saving state for Cisco ISE 3: {}".format(self.my_state)) + self.save_state(self.my_state) return items_list diff --git a/ciscoise_consts.py b/ciscoise_consts.py index dd95e0c..3afa87c 100644 --- a/ciscoise_consts.py +++ b/ciscoise_consts.py @@ -51,7 +51,7 @@ CISCOISE_ERROR_INVALID_PARAM = "Please provide a non-zero positive integer in {param}" CISCOISE_MAP_IP_ABSENT_ERROR = "Please provide either mac address or ip address" CISCOISE_ERS_CRED_MISSING = "ERS credentials in asset configuration are required for this action" -DEFAULT_MAX_RESULTS = 7 +DEFAULT_MAX_RESULTS = 20 # Json reply schema IS_MAC_QUARAN_RESP_SCHEMA = {