Skip to content

Commit ce390c6

Browse files
authored
Merge pull request splunk#447 from splunk/DVPL-10137
Create job support for "output_mode:json"
2 parents 875a58d + f7f15b2 commit ce390c6

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

splunklib/client.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,10 @@ def _load_atom_entries(response):
226226

227227

228228
# Load the sid from the body of the given response
229-
def _load_sid(response):
229+
def _load_sid(response, output_mode):
230+
if output_mode == "json":
231+
json_obj = json.loads(response.body.read())
232+
return json_obj.get('sid')
230233
return _load_atom(response).response.sid
231234

232235

@@ -2957,7 +2960,7 @@ def create(self, query, **kwargs):
29572960
if kwargs.get("exec_mode", None) == "oneshot":
29582961
raise TypeError("Cannot specify exec_mode=oneshot; use the oneshot method instead.")
29592962
response = self.post(search=query, **kwargs)
2960-
sid = _load_sid(response)
2963+
sid = _load_sid(response, kwargs.get("output_mode", None))
29612964
return Job(self.service, sid)
29622965

29632966
def export(self, query, **params):
@@ -3173,7 +3176,7 @@ def dispatch(self, **kwargs):
31733176
:return: The :class:`Job`.
31743177
"""
31753178
response = self.post("dispatch", **kwargs)
3176-
sid = _load_sid(response)
3179+
sid = _load_sid(response, kwargs.get("output_mode", None))
31773180
return Job(self.service, sid)
31783181

31793182
@property

tests/test_job.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,11 @@ def test_service_search(self):
4848
self.assertTrue(job.sid in self.service.jobs)
4949
job.cancel()
5050

51+
def test_create_job_with_output_mode_json(self):
52+
job = self.service.jobs.create(query='search index=_internal earliest=-1m | head 3', output_mode='json')
53+
self.assertTrue(job.sid in self.service.jobs)
54+
job.cancel()
55+
5156
def test_oneshot_with_garbage_fails(self):
5257
jobs = self.service.jobs
5358
self.assertRaises(TypeError, jobs.create, "abcd", exec_mode="oneshot")

0 commit comments

Comments
 (0)