Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions splunklib/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,10 @@ def _load_atom_entries(response):


# Load the sid from the body of the given response
def _load_sid(response):
def _load_sid(response, output_mode):
if output_mode == "json":
json_obj = json.loads(response.body.read())
return json_obj.get('sid')
return _load_atom(response).response.sid


Expand Down Expand Up @@ -2968,7 +2971,7 @@ def create(self, query, **kwargs):
if kwargs.get("exec_mode", None) == "oneshot":
raise TypeError("Cannot specify exec_mode=oneshot; use the oneshot method instead.")
response = self.post(search=query, **kwargs)
sid = _load_sid(response)
sid = _load_sid(response, kwargs.get("output_mode", None))
return Job(self.service, sid)

def export(self, query, **params):
Expand Down Expand Up @@ -3184,7 +3187,7 @@ def dispatch(self, **kwargs):
:return: The :class:`Job`.
"""
response = self.post("dispatch", **kwargs)
sid = _load_sid(response)
sid = _load_sid(response, kwargs.get("output_mode", None))
return Job(self.service, sid)

@property
Expand Down
5 changes: 5 additions & 0 deletions tests/test_job.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,11 @@ def test_service_search(self):
self.assertTrue(job.sid in self.service.jobs)
job.cancel()

def test_create_job_with_output_mode_json(self):
job = self.service.jobs.create(query='search index=_internal earliest=-1m | head 3', output_mode='json')
self.assertTrue(job.sid in self.service.jobs)
job.cancel()

def test_oneshot_with_garbage_fails(self):
jobs = self.service.jobs
self.assertRaises(TypeError, jobs.create, "abcd", exec_mode="oneshot")
Expand Down