Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

updated version checks for v2 search APIs #482

Merged
merged 4 commits into from Sep 2, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 6 additions & 6 deletions splunklib/client.py
Expand Up @@ -572,7 +572,7 @@ def parse(self, query, **kwargs):
:type kwargs: ``dict``
:return: A semantic map of the parsed search query.
"""
if self.splunk_version >= (9,):
if self.splunk_version >= (9,0,2):
return self.post("search/v2/parser", q=query, **kwargs)
return self.get("search/parser", q=query, **kwargs)

Expand Down Expand Up @@ -2722,7 +2722,7 @@ def __init__(self, service, sid, **kwargs):
# Default to v2 in Splunk Version 9+
path = "{path}{sid}"
# Formatting path based on the Splunk Version
if service.splunk_version < (9,):
if service.splunk_version < (9,0,2):
path = path.format(path=PATH_JOBS, sid=sid)
else:
path = path.format(path=PATH_JOBS_V2, sid=sid)
Expand Down Expand Up @@ -2782,7 +2782,7 @@ def events(self, **kwargs):
kwargs['segmentation'] = kwargs.get('segmentation', 'none')

# Search API v1(GET) and v2(POST)
if self.service.splunk_version < (9,):
if self.service.splunk_version < (9,0,2):
return self.get("events", **kwargs).body
return self.post("events", **kwargs).body

Expand Down Expand Up @@ -2874,7 +2874,7 @@ def results(self, **query_params):
query_params['segmentation'] = query_params.get('segmentation', 'none')

# Search API v1(GET) and v2(POST)
if self.service.splunk_version < (9,):
if self.service.splunk_version < (9,0,2):
return self.get("results", **query_params).body
return self.post("results", **query_params).body

Expand Down Expand Up @@ -2919,7 +2919,7 @@ def preview(self, **query_params):
query_params['segmentation'] = query_params.get('segmentation', 'none')

# Search API v1(GET) and v2(POST)
if self.service.splunk_version < (9,):
if self.service.splunk_version < (9,0,2):
return self.get("results_preview", **query_params).body
return self.post("results_preview", **query_params).body

Expand Down Expand Up @@ -3011,7 +3011,7 @@ class Jobs(Collection):
collection using :meth:`Service.jobs`."""
def __init__(self, service):
# Splunk 9 introduces the v2 endpoint
if service.splunk_version >= (9,):
if service.splunk_version >= (9,0,2):
path = PATH_JOBS_V2
else:
path = PATH_JOBS
Expand Down
4 changes: 2 additions & 2 deletions tests/test_job.py
Expand Up @@ -401,8 +401,8 @@ def test_v1_job_fallback(self):
n_results = len([x for x in results_r if isinstance(x, dict)])

# Fallback test for Splunk Version 9+
if self.service.splunk_version[0] >= 9:
self.assertGreaterEqual(9, self.service.splunk_version[0])
if self.service.splunk_version >= (9,0,2):
self.assertGreaterEqual((9,0,2), self.service.splunk_version)
self.assertEqual(n_events, n_preview, n_results)


Expand Down
4 changes: 2 additions & 2 deletions tests/test_service.py
Expand Up @@ -104,8 +104,8 @@ def test_parse(self):
response = self.service.parse('search * abc="def" | dedup abc')

# Splunk Version 9+ using API v2: search/v2/parser
if self.service.splunk_version[0] >= 9:
self.assertGreaterEqual(9, self.service.splunk_version[0])
if self.service.splunk_version >= (9,0,2):
self.assertGreaterEqual((9,0,2), self.service.splunk_version)

self.assertEqual(response.status, 200)

Expand Down