Skip to content

Commit

Permalink
Commit with debugging codes and comments
Browse files Browse the repository at this point in the history
  • Loading branch information
ishans-crest committed Feb 9, 2024
1 parent 6a6af2d commit 739cd36
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 13 deletions.
2 changes: 1 addition & 1 deletion ciscoise.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
40 changes: 29 additions & 11 deletions ciscoise_connector.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__()

Expand Down Expand Up @@ -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()
Expand All @@ -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
Expand Down Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion ciscoise_consts.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down

0 comments on commit 739cd36

Please sign in to comment.