<?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 Export to csv is not fetching all the results - Python /Splunk SDK in Splunk Dev</title>
    <link>https://community.splunk.com/t5/Splunk-Dev/Export-to-csv-is-not-fetching-all-the-results-Python-Splunk-SDK/m-p/432548#M7745</link>
    <description>&lt;P&gt;I do have a Python code to run an query and export the search results to .csv files. The program is working perfectly fine but when i opened the search results i could not see all the results. I just validated the same by running the query manually in splunk and exported the result and compared the results with the one which is generated through my code. I am running the query for last 2 hours. &lt;/P&gt;

&lt;P&gt;My Code - &lt;BR /&gt;
import time&lt;BR /&gt;
import splunklib.client as client&lt;BR /&gt;
import splunklib.results as results&lt;BR /&gt;
import csv&lt;/P&gt;

&lt;H1&gt;import random&lt;/H1&gt;

&lt;P&gt;HOST = "Server"&lt;BR /&gt;
PORT = 8089&lt;BR /&gt;
USERNAME = "user"&lt;BR /&gt;
PASSWORD = "password"&lt;/P&gt;

&lt;P&gt;service = client.connect(&lt;BR /&gt;
     host=HOST,&lt;BR /&gt;
     port=PORT,&lt;BR /&gt;
     username=USERNAME,&lt;BR /&gt;
     password=PASSWORD)&lt;/P&gt;

&lt;H1&gt;My splunk query file&lt;/H1&gt;

&lt;P&gt;with open('H:\Query1.txt', 'r') as myfile:&lt;BR /&gt;
    Splunk_query=myfile.read()&lt;/P&gt;

&lt;H1&gt;Executing the query for last 2 hours&lt;/H1&gt;

&lt;P&gt;results_kwargs = {&lt;BR /&gt;
  "earliest_time": "-2h",&lt;BR /&gt;
  "latest_time": "now",&lt;BR /&gt;
  "search_mode": "normal",&lt;BR /&gt;
  "output_mode": "csv"&lt;BR /&gt;
 }&lt;/P&gt;

&lt;P&gt;oneshotsearch_results = service.jobs.oneshot(Splunk_query, **results_kwargs)&lt;BR /&gt;
f=open("H:\lasttwohours.csv", 'w')&lt;BR /&gt;
f.write(oneshotsearch_results.read())&lt;BR /&gt;
f.close()&lt;/P&gt;

&lt;P&gt;Kindly help me with the export with the absolute results which i am getting it from splunk. &lt;/P&gt;

&lt;P&gt;NOTE : I dont have permission to change any .conf file since this is the restricted environment. I can run my program and get the results from splunk. &lt;/P&gt;</description>
    <pubDate>Tue, 29 Sep 2020 22:22:36 GMT</pubDate>
    <dc:creator>pchp348</dc:creator>
    <dc:date>2020-09-29T22:22:36Z</dc:date>
    <item>
      <title>Export to csv is not fetching all the results - Python /Splunk SDK</title>
      <link>https://community.splunk.com/t5/Splunk-Dev/Export-to-csv-is-not-fetching-all-the-results-Python-Splunk-SDK/m-p/432548#M7745</link>
      <description>&lt;P&gt;I do have a Python code to run an query and export the search results to .csv files. The program is working perfectly fine but when i opened the search results i could not see all the results. I just validated the same by running the query manually in splunk and exported the result and compared the results with the one which is generated through my code. I am running the query for last 2 hours. &lt;/P&gt;

&lt;P&gt;My Code - &lt;BR /&gt;
import time&lt;BR /&gt;
import splunklib.client as client&lt;BR /&gt;
import splunklib.results as results&lt;BR /&gt;
import csv&lt;/P&gt;

&lt;H1&gt;import random&lt;/H1&gt;

&lt;P&gt;HOST = "Server"&lt;BR /&gt;
PORT = 8089&lt;BR /&gt;
USERNAME = "user"&lt;BR /&gt;
PASSWORD = "password"&lt;/P&gt;

&lt;P&gt;service = client.connect(&lt;BR /&gt;
     host=HOST,&lt;BR /&gt;
     port=PORT,&lt;BR /&gt;
     username=USERNAME,&lt;BR /&gt;
     password=PASSWORD)&lt;/P&gt;

&lt;H1&gt;My splunk query file&lt;/H1&gt;

&lt;P&gt;with open('H:\Query1.txt', 'r') as myfile:&lt;BR /&gt;
    Splunk_query=myfile.read()&lt;/P&gt;

&lt;H1&gt;Executing the query for last 2 hours&lt;/H1&gt;

&lt;P&gt;results_kwargs = {&lt;BR /&gt;
  "earliest_time": "-2h",&lt;BR /&gt;
  "latest_time": "now",&lt;BR /&gt;
  "search_mode": "normal",&lt;BR /&gt;
  "output_mode": "csv"&lt;BR /&gt;
 }&lt;/P&gt;

&lt;P&gt;oneshotsearch_results = service.jobs.oneshot(Splunk_query, **results_kwargs)&lt;BR /&gt;
f=open("H:\lasttwohours.csv", 'w')&lt;BR /&gt;
f.write(oneshotsearch_results.read())&lt;BR /&gt;
f.close()&lt;/P&gt;

&lt;P&gt;Kindly help me with the export with the absolute results which i am getting it from splunk. &lt;/P&gt;

&lt;P&gt;NOTE : I dont have permission to change any .conf file since this is the restricted environment. I can run my program and get the results from splunk. &lt;/P&gt;</description>
      <pubDate>Tue, 29 Sep 2020 22:22:36 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Dev/Export-to-csv-is-not-fetching-all-the-results-Python-Splunk-SDK/m-p/432548#M7745</guid>
      <dc:creator>pchp348</dc:creator>
      <dc:date>2020-09-29T22:22:36Z</dc:date>
    </item>
    <item>
      <title>Re: Export to csv is not fetching all the results - Python /Splunk SDK</title>
      <link>https://community.splunk.com/t5/Splunk-Dev/Export-to-csv-is-not-fetching-all-the-results-Python-Splunk-SDK/m-p/432549#M7746</link>
      <description>&lt;P&gt;&lt;A href="http://dev.splunk.com/view/python-sdk/SP-CAAAEE5"&gt;http://dev.splunk.com/view/python-sdk/SP-CAAAEE5&lt;/A&gt;&lt;BR /&gt;
The document says:&lt;/P&gt;

&lt;P&gt;&lt;STRONG&gt;By default, one-shot searches will return a maximum of 100 events&lt;/STRONG&gt;, even if there are more than 100 events in the search results. To return more than 100 events, add the following parameter to your one-shot search's arguments:&lt;BR /&gt;
    &lt;STRONG&gt;"count": 0&lt;/STRONG&gt;&lt;BR /&gt;
The count parameter, when set to zero, indicates that there is no limit to the number of events to be returned.&lt;/P&gt;

&lt;P&gt;Maybe you could try to modify your search query.&lt;/P&gt;</description>
      <pubDate>Thu, 17 Oct 2019 03:42:33 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Dev/Export-to-csv-is-not-fetching-all-the-results-Python-Splunk-SDK/m-p/432549#M7746</guid>
      <dc:creator>lesley_lin</dc:creator>
      <dc:date>2019-10-17T03:42:33Z</dc:date>
    </item>
    <item>
      <title>Re: Export to csv is not fetching all the results - Python /Splunk SDK</title>
      <link>https://community.splunk.com/t5/Splunk-Dev/Export-to-csv-is-not-fetching-all-the-results-Python-Splunk-SDK/m-p/432550#M7747</link>
      <description>&lt;P&gt;Like this:&lt;BR /&gt;
job = service.jobs.oneshot(searchquery, **results_kwargs, count=0)&lt;/P&gt;</description>
      <pubDate>Thu, 17 Oct 2019 06:11:06 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Dev/Export-to-csv-is-not-fetching-all-the-results-Python-Splunk-SDK/m-p/432550#M7747</guid>
      <dc:creator>lesley_lin</dc:creator>
      <dc:date>2019-10-17T06:11:06Z</dc:date>
    </item>
  </channel>
</rss>

