<?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 Splunk results automatically for every 3 hours using Python in Splunk Dev</title>
    <link>https://community.splunk.com/t5/Splunk-Dev/Export-Splunk-results-automatically-for-every-3-hours-using/m-p/439701#M7965</link>
    <description>&lt;P&gt;Now i am able to get the results from splunk - Its working fine.&lt;/P&gt;

&lt;BLOCKQUOTE&gt;
&lt;P&gt;from time import sleep import&lt;BR /&gt;
splunklib.client as client import&lt;BR /&gt;
splunklib.results as results   count=0&lt;BR /&gt;
HOST = "cicloga-enterprise.net" PORT =&lt;BR /&gt;
8089 USERNAME = "SID" PASSWORD =&lt;BR /&gt;
"Password"   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;search_query = "search index=cfs_classic_81712 | head 10"&lt;/H1&gt;

&lt;H1&gt;kwargs_normalsearch = {"exec_mode": "normal"}&lt;/H1&gt;

&lt;H1&gt;job = service.jobs.create(search_query,&lt;/H1&gt;

&lt;P&gt;**kwargs_normalsearch)   rr = results.ResultsReader(service.jobs.export("search&lt;BR /&gt;
index=cgh_new_876544 | stats count by&lt;BR /&gt;
host")) for result in rr:&lt;BR /&gt;
    if isinstance(result, results.Message):&lt;BR /&gt;
        # Diagnostic messages may be returned in the results&lt;BR /&gt;
        print '%s: %s' % (result.type, result.message)&lt;BR /&gt;
    elif isinstance(result, dict):&lt;BR /&gt;
        # Normal events are returned as dicts&lt;BR /&gt;
        print result assert rr.is_preview == False&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;</description>
    <pubDate>Tue, 29 Sep 2020 19:52:42 GMT</pubDate>
    <dc:creator>pchp348</dc:creator>
    <dc:date>2020-09-29T19:52:42Z</dc:date>
    <item>
      <title>Export Splunk results automatically for every 3 hours using Python</title>
      <link>https://community.splunk.com/t5/Splunk-Dev/Export-Splunk-results-automatically-for-every-3-hours-using/m-p/439700#M7964</link>
      <description>&lt;P&gt;I am very new to Splunk and i am trying to automate the manual search and export with Python(Splunk SDK). &lt;BR /&gt;
I have searched most of the answers relevant to Splunk SDK,But none is straight forward. &lt;/P&gt;

&lt;P&gt;Here is my code which i have tried - &lt;/P&gt;

&lt;BLOCKQUOTE&gt;
&lt;P&gt;import splunklib.client as client&lt;BR /&gt;
import splunklib.results as results&lt;/P&gt;

&lt;P&gt;c =&lt;BR /&gt;
client.connect(host='cicloga-enterprise.net',&lt;BR /&gt;
port=8089,&lt;BR /&gt;
                       username='username',&lt;BR /&gt;
password='password')&lt;/P&gt;

&lt;P&gt;saved_searches = c.saved_searches&lt;BR /&gt;
saved_searches.create('my_saved_search',&lt;BR /&gt;
                      'search index=cgh_new_876544 | head 1')&lt;BR /&gt;
assert 'my_saved_search' in&lt;BR /&gt;
saved_searches&lt;BR /&gt;
saved_searches.delete('my_saved_search')&lt;BR /&gt;
assert 'my_saved_search' not in&lt;BR /&gt;
saved_searches&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;

&lt;P&gt;With the above python code i am able to connect to Splunk host and getting the job results , But i am not getting results for my search "'&lt;EM&gt;search index=cgh_new_876544 | head 1"&lt;/EM&gt;&lt;/P&gt;

&lt;P&gt;Ultimately i need a logic/help to run a splunk query to export the splunk results to CSV.&lt;BR /&gt;
I have already gone through this link - &lt;A href="https://answers.splunk.com/answers/2651/exporting-search-results-automatically.html?utm_source=typeahead&amp;amp;utm_medium=newquestion&amp;amp;utm_campaign=no_votes_sort_relev" target="_blank"&gt;https://answers.splunk.com/answers/2651/exporting-search-results-automatically.html?utm_source=typeahead&amp;amp;utm_medium=newquestion&amp;amp;utm_campaign=no_votes_sort_relev&lt;/A&gt; &lt;/P&gt;

&lt;P&gt;But that is not something which interacting directly with Python. &lt;/P&gt;

&lt;P&gt;Kindly help me with the above requirement.&lt;/P&gt;</description>
      <pubDate>Tue, 29 Sep 2020 19:51:14 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Dev/Export-Splunk-results-automatically-for-every-3-hours-using/m-p/439700#M7964</guid>
      <dc:creator>pchp348</dc:creator>
      <dc:date>2020-09-29T19:51:14Z</dc:date>
    </item>
    <item>
      <title>Re: Export Splunk results automatically for every 3 hours using Python</title>
      <link>https://community.splunk.com/t5/Splunk-Dev/Export-Splunk-results-automatically-for-every-3-hours-using/m-p/439701#M7965</link>
      <description>&lt;P&gt;Now i am able to get the results from splunk - Its working fine.&lt;/P&gt;

&lt;BLOCKQUOTE&gt;
&lt;P&gt;from time import sleep import&lt;BR /&gt;
splunklib.client as client import&lt;BR /&gt;
splunklib.results as results   count=0&lt;BR /&gt;
HOST = "cicloga-enterprise.net" PORT =&lt;BR /&gt;
8089 USERNAME = "SID" PASSWORD =&lt;BR /&gt;
"Password"   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;search_query = "search index=cfs_classic_81712 | head 10"&lt;/H1&gt;

&lt;H1&gt;kwargs_normalsearch = {"exec_mode": "normal"}&lt;/H1&gt;

&lt;H1&gt;job = service.jobs.create(search_query,&lt;/H1&gt;

&lt;P&gt;**kwargs_normalsearch)   rr = results.ResultsReader(service.jobs.export("search&lt;BR /&gt;
index=cgh_new_876544 | stats count by&lt;BR /&gt;
host")) for result in rr:&lt;BR /&gt;
    if isinstance(result, results.Message):&lt;BR /&gt;
        # Diagnostic messages may be returned in the results&lt;BR /&gt;
        print '%s: %s' % (result.type, result.message)&lt;BR /&gt;
    elif isinstance(result, dict):&lt;BR /&gt;
        # Normal events are returned as dicts&lt;BR /&gt;
        print result assert rr.is_preview == False&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;</description>
      <pubDate>Tue, 29 Sep 2020 19:52:42 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Dev/Export-Splunk-results-automatically-for-every-3-hours-using/m-p/439701#M7965</guid>
      <dc:creator>pchp348</dc:creator>
      <dc:date>2020-09-29T19:52:42Z</dc:date>
    </item>
  </channel>
</rss>

