Skip to content

Commit 258f921

Browse files
authored
Merge pull request #7 from splunk/bug-fix-pagination
- Bug fix for pagination - Updated the pagination logic by using the next page link directly.
2 parents 2faa1c4 + 8891587 commit 258f921

File tree

4 files changed

+37
-28
lines changed

4 files changed

+37
-28
lines changed

globalConfig.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"meta": {
33
"name": "ta_cisco_webex_add_on_for_splunk",
44
"displayName": "Cisco Webex Add-on for Splunk",
5-
"version": "1.0.10",
5+
"version": "1.0.11",
66
"restRoot": "ta_cisco_webex_add_on_for_splunk",
77
"schemaVersion": "0.0.9",
88
"supportedThemes": [

package/app.manifest

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"id": {
66
"group": null,
77
"name": "ta_cisco_webex_add_on_for_splunk",
8-
"version": "1.0.10"
8+
"version": "1.0.11"
99
},
1010
"author": [
1111
{

package/bin/webex_api_client.py

Lines changed: 33 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,16 @@
55
from oauth_helper import update_access_token
66
import re
77

8+
def extract_link_regex(link_header_string):
9+
"""
10+
Extracts the URL from a Link header-like string using regex.
11+
"""
12+
match = re.search(r'<([^>]+)>;', link_header_string)
13+
if match:
14+
return match.group(1)
15+
else:
16+
raise ValueError(f"Next page link string does not match expected link header format: '{link_header_string}'")
17+
818
def paging_get_request_to_webex(
919
helper,
1020
base_endpoint,
@@ -22,8 +32,10 @@ def paging_get_request_to_webex(
2232
params["max"] = _MAX_PAGE_SIZE if not params.get("max") else params["max"]
2333

2434
paging = True
35+
next_page_link = None
2536
try:
2637
while paging:
38+
helper.log_debug("[-] next_page_link {}".format(next_page_link))
2739
data,response_header = make_get_request_to_webex(
2840
helper,
2941
base_endpoint,
@@ -34,6 +46,7 @@ def paging_get_request_to_webex(
3446
client_id,
3547
client_secret,
3648
params,
49+
next_page_link
3750
)
3851

3952
if data is None or len(data)==0:
@@ -42,24 +55,15 @@ def paging_get_request_to_webex(
4255
# append paging data
4356
results.extend(data.get(response_tag))
4457

45-
next_page_link = response_header.get("link", None)
46-
helper.log_debug("[--] next_page_link {}".format(next_page_link))
47-
48-
if next_page_link:
49-
# update offset to get the next page
50-
if "offset" in next_page_link:
51-
offset = int(params.get("offset", 0)) + len(data.get(response_tag))
52-
params["offset"] = offset
53-
else:
54-
# Regular expression to find the cursor value
55-
# This will capture characters following 'cursor=' until it hits either '&' or the end of the string
56-
match = re.search(r'cursor=([^&>]+)', next_page_link)
57-
# Extract the cursor value if it is found
58-
if match:
59-
cursor_value = match.group(1)
60-
params["cursor"] = cursor_value
61-
else:
62-
raise Exception("Cursor value not found for next page")
58+
next_page_link_header = response_header.get("link", None)
59+
helper.log_debug("[--] next_page_link_header {}".format(next_page_link_header))
60+
61+
if next_page_link_header:
62+
try:
63+
next_page_link=extract_link_regex(next_page_link_header)
64+
helper.log_debug("[--] next_page_link {}".format(next_page_link))
65+
except ValueError as e:
66+
helper.log_error(f"Next page link extraction failed (regex): {e}")
6367
else:
6468
helper.log_debug("[--] This is the last page for {}".format(endpoint))
6569
paging = False
@@ -83,14 +87,19 @@ def make_get_request_to_webex(
8387
client_id,
8488
client_secret,
8589
params,
86-
retry=True,
90+
next_page_link,
91+
retry=True
8792
):
88-
url = _BASE_URL.format(base_endpoint=base_endpoint) + endpoint
93+
if next_page_link:
94+
url = next_page_link
95+
params = None
96+
else:
97+
url = _BASE_URL.format(base_endpoint=base_endpoint) + endpoint
8998

90-
# reconstruct the url for meeting/qualities and cdr_feed endpoints
91-
if endpoint == "meeting/qualities" or endpoint == "cdr_feed":
92-
protocol, rest = url.split("//")
93-
url = f"{protocol}//analytics.{rest}"
99+
# reconstruct the url for meeting/qualities and cdr_feed endpoints
100+
if endpoint == "meeting/qualities" or endpoint == "cdr_feed":
101+
protocol, rest = url.split("//")
102+
url = f"{protocol}//analytics.{rest}"
94103

95104
helper.log_debug("[-] url: {} -- params: {}".format(url, params))
96105
headers = {

package/default/app.conf

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ build = 1
55

66
[launcher]
77
author = FDSE
8-
version = 1.0.10
8+
version = 1.0.11
99
description =
1010

1111
[ui]
@@ -17,7 +17,7 @@ docs_section_override = AddOns:released
1717
id = ta_cisco_webex_add_on_for_splunk
1818

1919
[id]
20-
version = 1.0.10
20+
version = 1.0.11
2121

2222
[triggers]
2323
reload.ta_cisco_webex_add_on_for_splunk_account = simple

0 commit comments

Comments
 (0)