<?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: How to run a saved search with SDK? in Splunk Dev</title>
    <link>https://community.splunk.com/t5/Splunk-Dev/How-to-run-a-saved-search-with-SDK/m-p/68985#M956</link>
    <description>&lt;P&gt;Yes it certainly can. To run a saved search, use splunklib.client.SavedSearch.dispatch() (see the reference docs here: &lt;A href="http://docs.splunk.com/DocumentationStatic/PythonSDK/0.8Beta/client.html#splunklib.client.SavedSearch" target="_blank"&gt;http://docs.splunk.com/DocumentationStatic/PythonSDK/0.8Beta/client.html#splunklib.client.SavedSearch&lt;/A&gt; ). &lt;/P&gt;

&lt;P&gt;The saved search example shows how to list your saved searches, but not how to run one. BUT, you can see an example of how to run a saved search in the unit tests for saved_search (/test/test_saved_search.py). Look for "def test_dispatch(self)", which tests various things such as enumerating saved searches, deleting one, creating one, but also running one. This part of the test case runs a search, gets back a job ID, waits for the job to finish, gets the results: &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;    ...
    job = saved_search.dispatch()
    testlib.wait(job, lambda job: bool(int(job['isDone'])))
    job.results().close()
    job.cancel()
    ...
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;In general, the unit tests are a good place to look for examples of how to use the API.&lt;/P&gt;</description>
    <pubDate>Mon, 28 Sep 2020 11:54:46 GMT</pubDate>
    <dc:creator>apruneda_splunk</dc:creator>
    <dc:date>2020-09-28T11:54:46Z</dc:date>
    <item>
      <title>How to run a saved search with SDK?</title>
      <link>https://community.splunk.com/t5/Splunk-Dev/How-to-run-a-saved-search-with-SDK/m-p/68984#M955</link>
      <description>&lt;P&gt;I'm new to Splunk, and am trying to run a saved search with the Python SDK, with the client module (not binding), only I don't understand the SDK model well enough (probably don't know Splunk itself well enough either). I can list all saved searches with &lt;CODE&gt;saved_searches.py&lt;/CODE&gt; or a particular search with &lt;CODE&gt;saved_search/saved_search.py&lt;/CODE&gt;, and I can run a one-off search:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;job  = splunk.jobs.create('search sourcetype=foo earliest=-60m')
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;but I don't see an interface for running a saved search.&lt;/P&gt;

&lt;P&gt;Can the client module run a saved search?&lt;/P&gt;

&lt;P&gt;Thank you,&lt;/P&gt;</description>
      <pubDate>Wed, 06 Jun 2012 19:42:47 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Dev/How-to-run-a-saved-search-with-SDK/m-p/68984#M955</guid>
      <dc:creator>zacharysyoung</dc:creator>
      <dc:date>2012-06-06T19:42:47Z</dc:date>
    </item>
    <item>
      <title>Re: How to run a saved search with SDK?</title>
      <link>https://community.splunk.com/t5/Splunk-Dev/How-to-run-a-saved-search-with-SDK/m-p/68985#M956</link>
      <description>&lt;P&gt;Yes it certainly can. To run a saved search, use splunklib.client.SavedSearch.dispatch() (see the reference docs here: &lt;A href="http://docs.splunk.com/DocumentationStatic/PythonSDK/0.8Beta/client.html#splunklib.client.SavedSearch" target="_blank"&gt;http://docs.splunk.com/DocumentationStatic/PythonSDK/0.8Beta/client.html#splunklib.client.SavedSearch&lt;/A&gt; ). &lt;/P&gt;

&lt;P&gt;The saved search example shows how to list your saved searches, but not how to run one. BUT, you can see an example of how to run a saved search in the unit tests for saved_search (/test/test_saved_search.py). Look for "def test_dispatch(self)", which tests various things such as enumerating saved searches, deleting one, creating one, but also running one. This part of the test case runs a search, gets back a job ID, waits for the job to finish, gets the results: &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;    ...
    job = saved_search.dispatch()
    testlib.wait(job, lambda job: bool(int(job['isDone'])))
    job.results().close()
    job.cancel()
    ...
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;In general, the unit tests are a good place to look for examples of how to use the API.&lt;/P&gt;</description>
      <pubDate>Mon, 28 Sep 2020 11:54:46 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Dev/How-to-run-a-saved-search-with-SDK/m-p/68985#M956</guid>
      <dc:creator>apruneda_splunk</dc:creator>
      <dc:date>2020-09-28T11:54:46Z</dc:date>
    </item>
    <item>
      <title>Re: How to run a saved search with SDK?</title>
      <link>https://community.splunk.com/t5/Splunk-Dev/How-to-run-a-saved-search-with-SDK/m-p/68986#M957</link>
      <description>&lt;P&gt;Thank you, Apruneda. This is exactly the answer.&lt;/P&gt;</description>
      <pubDate>Wed, 06 Jun 2012 20:59:23 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Dev/How-to-run-a-saved-search-with-SDK/m-p/68986#M957</guid>
      <dc:creator>zacharysyoung</dc:creator>
      <dc:date>2012-06-06T20:59:23Z</dc:date>
    </item>
  </channel>
</rss>

