<?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: SDK and specifying App context/namespace in Splunk Dev</title>
    <link>https://community.splunk.com/t5/Splunk-Dev/SDK-and-specifying-App-context-namespace/m-p/342113#M5288</link>
    <description>&lt;P&gt;I've considered that, but I didn't see anything about token usage like in the &lt;CODE&gt;| savedsearch&lt;/CODE&gt; command.&lt;/P&gt;</description>
    <pubDate>Mon, 18 Dec 2017 09:39:03 GMT</pubDate>
    <dc:creator>rharrisssi</dc:creator>
    <dc:date>2017-12-18T09:39:03Z</dc:date>
    <item>
      <title>SDK and specifying App context/namespace</title>
      <link>https://community.splunk.com/t5/Splunk-Dev/SDK-and-specifying-App-context-namespace/m-p/342108#M5283</link>
      <description>&lt;P&gt;I've troubleshot this for awhile, must not be comprehending this correctly. Basically I'm trying to use the | savedsearch command to execute a saved search. Straight forward, right? The hitch is that I'm trying to do it via the API using the SDK, but when I've tried it cannot find the search by name I specify; I can copy/paste direct into Splunk and it works, so I'm good there.&lt;/P&gt;

&lt;P&gt;Basically anyone who is able to use the Splunk SDK to execute an arbitrary SPL query, but within the context of a specific app, could likely help me; but it's appreciated regardless! Here is some basic code to describe what I'm doing:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;config = {"searches":["search index=firewall | ... | outputlookup mylookup","..."]}

service = client.connect(host="foo",username="user",password="pass",app="my_app_name")
jobs = service.jobs
for search in config["searches"]:
    myargs = {"exec_mode":"normal"}
    job = jobs.create(search,**myargs)
    while True:
        while not job.is_ready(): pass
        if job["isDone"] == "1": break
        sleep(2)
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;That is the most relevant piece of the code. I'm not looking to bring the results back, which is why you don't see that. I'm more interested in executing a search that is used to populate some lookups, and use lookups, which is why I need to figure out why the app context is not working for me. Perhaps I'm just doing it wrong!&lt;/P&gt;</description>
      <pubDate>Fri, 15 Dec 2017 19:07:25 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Dev/SDK-and-specifying-App-context-namespace/m-p/342108#M5283</guid>
      <dc:creator>rharrisssi</dc:creator>
      <dc:date>2017-12-15T19:07:25Z</dc:date>
    </item>
    <item>
      <title>Re: SDK and specifying App context/namespace</title>
      <link>https://community.splunk.com/t5/Splunk-Dev/SDK-and-specifying-App-context-namespace/m-p/342109#M5284</link>
      <description>&lt;P&gt;Instead of using &lt;CODE&gt;| savedsearch&lt;/CODE&gt; command, try using SavedSearch object, like specified here:&lt;/P&gt;

&lt;P&gt;&lt;A href="http://dev.splunk.com/view/java-sdk/SP-CAAAEKY#runsaved"&gt;http://dev.splunk.com/view/java-sdk/SP-CAAAEKY#runsaved&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 15 Dec 2017 20:48:51 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Dev/SDK-and-specifying-App-context-namespace/m-p/342109#M5284</guid>
      <dc:creator>somesoni2</dc:creator>
      <dc:date>2017-12-15T20:48:51Z</dc:date>
    </item>
    <item>
      <title>Re: SDK and specifying App context/namespace</title>
      <link>https://community.splunk.com/t5/Splunk-Dev/SDK-and-specifying-App-context-namespace/m-p/342110#M5285</link>
      <description>&lt;P&gt;&lt;A href="http://dev.splunk.com/view/python-sdk/SP-CAAAEK2#listsaved"&gt;Here is a link to the Python SDK Saved Search examples&lt;/A&gt;&lt;/P&gt;

&lt;P&gt;In short try iterating over the saved searches in your app context like : &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;savedsearches = service.saved_searches

for savedsearch in savedsearches:
    print "  " + savedsearch.name
    print "      Query: " + savedsearch["search"]
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 15 Dec 2017 21:09:52 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Dev/SDK-and-specifying-App-context-namespace/m-p/342110#M5285</guid>
      <dc:creator>Damien_Dallimor</dc:creator>
      <dc:date>2017-12-15T21:09:52Z</dc:date>
    </item>
    <item>
      <title>Re: SDK and specifying App context/namespace</title>
      <link>https://community.splunk.com/t5/Splunk-Dev/SDK-and-specifying-App-context-namespace/m-p/342111#M5286</link>
      <description>&lt;P&gt;I can run saved searches in a specific context without any problem using the SDK.&lt;/P&gt;

&lt;P&gt;I use the following code:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;instance = client.connect(host="localhost", username="user", password="pass", app="my_app")
job = instance.jobs.create("| savedsearch Rule1")
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Where Rule1 is  saved search with my_app permissions.&lt;BR /&gt;
If your saved search has private permissions, you will have to add owner="search_owner" to the parameters!&lt;/P&gt;

&lt;P&gt;You can try add the following at the beginning of the script, that will print SDK debug logs in the console and could be helpful!&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;import logging
logging.basicConfig(level=logging.DEBUG)
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 29 Sep 2020 17:17:53 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Dev/SDK-and-specifying-App-context-namespace/m-p/342111#M5286</guid>
      <dc:creator>damien_chillet</dc:creator>
      <dc:date>2020-09-29T17:17:53Z</dc:date>
    </item>
    <item>
      <title>Re: SDK and specifying App context/namespace</title>
      <link>https://community.splunk.com/t5/Splunk-Dev/SDK-and-specifying-App-context-namespace/m-p/342112#M5287</link>
      <description>&lt;P&gt;Thank you for your idea!&lt;/P&gt;</description>
      <pubDate>Mon, 18 Dec 2017 09:38:22 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Dev/SDK-and-specifying-App-context-namespace/m-p/342112#M5287</guid>
      <dc:creator>rharrisssi</dc:creator>
      <dc:date>2017-12-18T09:38:22Z</dc:date>
    </item>
    <item>
      <title>Re: SDK and specifying App context/namespace</title>
      <link>https://community.splunk.com/t5/Splunk-Dev/SDK-and-specifying-App-context-namespace/m-p/342113#M5288</link>
      <description>&lt;P&gt;I've considered that, but I didn't see anything about token usage like in the &lt;CODE&gt;| savedsearch&lt;/CODE&gt; command.&lt;/P&gt;</description>
      <pubDate>Mon, 18 Dec 2017 09:39:03 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Dev/SDK-and-specifying-App-context-namespace/m-p/342113#M5288</guid>
      <dc:creator>rharrisssi</dc:creator>
      <dc:date>2017-12-18T09:39:03Z</dc:date>
    </item>
    <item>
      <title>Re: SDK and specifying App context/namespace</title>
      <link>https://community.splunk.com/t5/Splunk-Dev/SDK-and-specifying-App-context-namespace/m-p/342114#M5289</link>
      <description>&lt;P&gt;This has puzzled me too. Turned out, default connect parameters don't give you access to objects that are set to "private" by other users. To get that, you need to explicitly specify it with wildcard, which is "-". Put that in your ~/.splunkrc or manually set in connect() method. &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;# Splunk host (default: localhost)
host=HOSTNAMEHERE
# Splunk admin port (default: 8089)
port=8089
# Splunk username
username=USERNAMEHERE
# Splunk password
password=PASSHERE
# Access scheme (default: https)
scheme=https
# Your version of Splunk (default: 5.0)
version=6.6.4
#app context
app=-
#owner wildcard
owner=-
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;After that, you should be able to see all objects. For example this should return all searches (global, app, user) from all apps: &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;def main():
    opts = parse(sys.argv[1:], {}, ".splunkrc")
    service = client.connect(**opts.kwargs)

    savedsearches = service.saved_searches    

    for s in savedsearches: 
          print s.name, s.access["owner"], s.access["sharing"]
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;I hope it helps!&lt;/P&gt;</description>
      <pubDate>Thu, 25 Jan 2018 07:22:37 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Dev/SDK-and-specifying-App-context-namespace/m-p/342114#M5289</guid>
      <dc:creator>aliakseidzianis</dc:creator>
      <dc:date>2018-01-25T07:22:37Z</dc:date>
    </item>
  </channel>
</rss>

