splunk-sdk-python icon indicating copy to clipboard operation
splunk-sdk-python copied to clipboard

JSONResultsReader does not work for Community Edition

Open marian-craciunescu opened this issue 4 years ago • 3 comments

Describe the bug I'm trying to get some result from a splunk server in python using JsonResultsReader, but the answer is not readable by json. However using the old ResultsReader I'm able to retrieve it. `Below is my code.

To Reproduce Steps to reproduce the behavior:

 search_job = self.do_splunk_search(query_string, search_args)
        res = search_job.results(**{"count": total_size, "output_mode": "json"})
        final_res = []
        last_ts = None
        for result in results.JSONResultsReader(res):
            final_res.append(result)
        

Expected behavior Call should return values . However if i'm using it returns values.

 for result in results.ResultsReader(search_job.results()):
                final_res.append(json.loads(json.dumps(result)))

Logs or Screenshots If applicable, add logs or screenshots to help explain your problem.

Splunk (please complete the following information):

  • Version: Splunk Enterprise Server 8.2.2
  • OS: Amazon AMI
  • Deployment: single-instance

SDK (please complete the following information):

  • Version: [e.g. 1.6.19]
  • Language Runtime Version: [e.g. Python 3.9]
  • OS: [Linux]

marian-craciunescu avatar May 23 '22 16:05 marian-craciunescu

Hi @marian-craciunescu , the issue is not related with the Community Edition of Splunk Enterprise. It seems that job creation is not completed when results are fetched in the next line i.e it requires an interval for the job creation to be completed before fetching the results.

Solution:- Try adding a while counter to check if the job creation has finished or not before fetching the results

job = self.service.jobs.create("search index=_internal_does_not_exist | head 2")
while not job.is_done():
    sleep(0.5)

Here are some references for the same, --> Example --> Test Case

Would request you to try the suggested solution and let us know in case if you still face the issue. Thanks!

ashah-splunk avatar Jun 01 '22 08:06 ashah-splunk

I do have such a mechanism implemented and it's the same behavior(I've just did not put it the snippet)

However I was able to get the results using .events(output_mode=json).

marian-craciunescu avatar Jun 01 '22 08:06 marian-craciunescu

Closing this Issue as the Events API is returning the required results.

ashah-splunk avatar Jul 13 '22 08:07 ashah-splunk