<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Export/stream massive results from splunk REST API in Splunk Dev</title>
    <link>https://community.splunk.com/t5/Splunk-Dev/Export-stream-massive-results-from-splunk-REST-API/m-p/191445#M2580</link>
    <description>&lt;P&gt;I don't have access to the box running splunk so cannot use the CLI. I need to do it remotely. I fixed the above problem by using the requests API and writing chunks of results to a file. But i see that for large searches, the job status sometimes auto finalizes when i have huge number of results. &lt;/P&gt;</description>
    <pubDate>Sun, 05 Jul 2015 23:08:59 GMT</pubDate>
    <dc:creator>karan1337</dc:creator>
    <dc:date>2015-07-05T23:08:59Z</dc:date>
    <item>
      <title>Export/stream massive results from splunk REST API</title>
      <link>https://community.splunk.com/t5/Splunk-Dev/Export-stream-massive-results-from-splunk-REST-API/m-p/191443#M2578</link>
      <description>&lt;P&gt;I need to export a massive number of events from splunk. Hence for performance reasons i resorted to directly using the REST API in my python code rather than using the Splunk SDK itself.&lt;/P&gt;

&lt;P&gt;I found the following curl command to export results:-&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;curl -ku username:password
&lt;A href="https://splunk_host:port/servicesNS/admin/search/search/jobs/export" target="test_blank"&gt;https://splunk_host:port/servicesNS/admin/search/search/jobs/export&lt;/A&gt; -d
search=“search index%3D_internal | head 3” -d output_mode=json
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;My attempt at simulating this using python's http functions is as follows:-&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;//assume i have authenticated to splunk and have a session key
base_url = "http://splunkhost:port"

search_job_urn = '/services/search/jobs/export'

myhttp = httplib2.Http(disable_ssl_certificate_validation=True)

searchjob = myhttp.request(base_url + search_job_urn, 'POST', headers=
{'Authorization': 'Splunk %s' % sessionKey},
body=urllib.urlencode({'search':'search index=indexname sourcetype=sourcename'}))[1]

print searchjob
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;The last print keeps printing all results until done. For large queries i get "Memory Errors". I need to be able to read results in chunks (say 50,000) and write them to a file and reset the buffer for searchjob. How can i accomplish that?&lt;/P&gt;</description>
      <pubDate>Sat, 04 Jul 2015 23:20:27 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Dev/Export-stream-massive-results-from-splunk-REST-API/m-p/191443#M2578</guid>
      <dc:creator>karan1337</dc:creator>
      <dc:date>2015-07-04T23:20:27Z</dc:date>
    </item>
    <item>
      <title>Re: Export/stream massive results from splunk REST API</title>
      <link>https://community.splunk.com/t5/Splunk-Dev/Export-stream-massive-results-from-splunk-REST-API/m-p/191444#M2579</link>
      <description>&lt;P&gt;Have you considered mass-exporting from the CLI?&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;$SPLUNK_HOME/bin/splunk export eventdata -index indexname -sourcetype sourcetypename -dir /path/to/write/to
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;More info by running &lt;CODE&gt;splunk help export&lt;/CODE&gt;.&lt;/P&gt;</description>
      <pubDate>Sun, 05 Jul 2015 11:21:28 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Dev/Export-stream-massive-results-from-splunk-REST-API/m-p/191444#M2579</guid>
      <dc:creator>martin_mueller</dc:creator>
      <dc:date>2015-07-05T11:21:28Z</dc:date>
    </item>
    <item>
      <title>Re: Export/stream massive results from splunk REST API</title>
      <link>https://community.splunk.com/t5/Splunk-Dev/Export-stream-massive-results-from-splunk-REST-API/m-p/191445#M2580</link>
      <description>&lt;P&gt;I don't have access to the box running splunk so cannot use the CLI. I need to do it remotely. I fixed the above problem by using the requests API and writing chunks of results to a file. But i see that for large searches, the job status sometimes auto finalizes when i have huge number of results. &lt;/P&gt;</description>
      <pubDate>Sun, 05 Jul 2015 23:08:59 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Dev/Export-stream-massive-results-from-splunk-REST-API/m-p/191445#M2580</guid>
      <dc:creator>karan1337</dc:creator>
      <dc:date>2015-07-05T23:08:59Z</dc:date>
    </item>
    <item>
      <title>Re: Export/stream massive results from splunk REST API</title>
      <link>https://community.splunk.com/t5/Splunk-Dev/Export-stream-massive-results-from-splunk-REST-API/m-p/191446#M2581</link>
      <description>&lt;P&gt;I solved the above using the python's requests API. Refer: &lt;A href="http://docs.python-requests.org/en/latest/api/"&gt;http://docs.python-requests.org/en/latest/api/&lt;/A&gt;&lt;/P&gt;

&lt;P&gt;Just need to set stream=true in iter_content call (the call is looped until a valid chunk is received) and write the chunk to a file.&lt;BR /&gt;
Also refer here for more info: &lt;A href="http://stackoverflow.com/questions/16694907/how-to-download-large-file-in-python-with-requests-py"&gt;http://stackoverflow.com/questions/16694907/how-to-download-large-file-in-python-with-requests-py&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Sun, 05 Jul 2015 23:20:12 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Dev/Export-stream-massive-results-from-splunk-REST-API/m-p/191446#M2581</guid>
      <dc:creator>karan1337</dc:creator>
      <dc:date>2015-07-05T23:20:12Z</dc:date>
    </item>
    <item>
      <title>Re: Export/stream massive results from splunk REST API</title>
      <link>https://community.splunk.com/t5/Splunk-Dev/Export-stream-massive-results-from-splunk-REST-API/m-p/191447#M2582</link>
      <description>&lt;P&gt;Hello karan1337,&lt;/P&gt;

&lt;P&gt;Would yu mind sharing a copy of your python script call rest api and using chunk ?&lt;/P&gt;

&lt;P&gt;I'm trying to get the same behavior, and that would be very cool &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;

&lt;P&gt;Thank you anyway !&lt;/P&gt;

&lt;P&gt;Guilhem&lt;/P&gt;</description>
      <pubDate>Thu, 03 Mar 2016 09:38:55 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Dev/Export-stream-massive-results-from-splunk-REST-API/m-p/191447#M2582</guid>
      <dc:creator>guilmxm</dc:creator>
      <dc:date>2016-03-03T09:38:55Z</dc:date>
    </item>
  </channel>
</rss>

