<?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 get session key in a search script (| script ) similar to the way a scripted input can? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-to-get-session-key-in-a-search-script-script-similar-to-the/m-p/282503#M85311</link>
    <description>&lt;P&gt;Make sure if you copy and paste from the commands.conf file example above, you remove the comment:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt; passauth = true  #&amp;lt;- the keys to the castle
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;It should just be:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt; passauth = true
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Splunk conf files don't always like comments at the end of a line&lt;/P&gt;</description>
    <pubDate>Fri, 07 Apr 2017 11:33:56 GMT</pubDate>
    <dc:creator>TonyLeeVT</dc:creator>
    <dc:date>2017-04-07T11:33:56Z</dc:date>
    <item>
      <title>How to get session key in a search script (| script ) similar to the way a scripted input can?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-get-session-key-in-a-search-script-script-similar-to-the/m-p/282496#M85304</link>
      <description>&lt;P&gt;I'm storing a few credentials in Splunk keystore using setup.xml  endpoint="storage/passwords".  I have no problem extracting the credential in my scripted input since the session-key is sent to its stdin.  However, that is not the case to search script (I think also referred custom script).  My script doesn't actually perform a Splunk search like other activities related to my Splunk App, but I need the extract the password using the session key.  I tested it to see what I get in stdin to experiment and I do in fact get few lines as follows, but I don't see how to get the session_key from these:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;splunkVersion:6.4.1
allowStream:1
keywords:%22%22
search:%7C%20script%20search_script%20%22PARAM-1%22%20PARAM-2
sid:admin__admin_VEVTVF9BVVRI__search1_1469631525.79
realtime:0
preview:0
truncated:0 
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 27 Jul 2016 15:08:34 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-get-session-key-in-a-search-script-script-similar-to-the/m-p/282496#M85304</guid>
      <dc:creator>avilandau</dc:creator>
      <dc:date>2016-07-27T15:08:34Z</dc:date>
    </item>
    <item>
      <title>Re: How to get session key in a search script (| script ) similar to the way a scripted input can?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-get-session-key-in-a-search-script-script-similar-to-the/m-p/282497#M85305</link>
      <description>&lt;P&gt;Instead of using | script... is writing a custom SPL command in python an option?&lt;/P&gt;

&lt;P&gt;If so, it's a bit easier you can use something akin to "sessionKey=self.getSessionKey()"&lt;/P&gt;</description>
      <pubDate>Wed, 27 Jul 2016 15:40:41 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-get-session-key-in-a-search-script-script-similar-to-the/m-p/282497#M85305</guid>
      <dc:creator>jkat54</dc:creator>
      <dc:date>2016-07-27T15:40:41Z</dc:date>
    </item>
    <item>
      <title>Re: How to get session key in a search script (| script ) similar to the way a scripted input can?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-get-session-key-in-a-search-script-script-similar-to-the/m-p/282498#M85306</link>
      <description>&lt;P&gt;Yes,  custom SPL command in python is surely an option. Will I need the Python SDK for that?  Can you refer me to some exmaple or link for that?&lt;/P&gt;</description>
      <pubDate>Wed, 27 Jul 2016 15:50:13 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-get-session-key-in-a-search-script-script-similar-to-the/m-p/282498#M85306</guid>
      <dc:creator>avilandau</dc:creator>
      <dc:date>2016-07-27T15:50:13Z</dc:date>
    </item>
    <item>
      <title>Re: How to get session key in a search script (| script ) similar to the way a scripted input can?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-get-session-key-in-a-search-script-script-similar-to-the/m-p/282499#M85307</link>
      <description>&lt;P&gt;I write my own python SPL without use of the SDK.  Hold on for a moment and I'll share an example.&lt;/P&gt;</description>
      <pubDate>Wed, 27 Jul 2016 16:18:59 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-get-session-key-in-a-search-script-script-similar-to-the/m-p/282499#M85307</guid>
      <dc:creator>jkat54</dc:creator>
      <dc:date>2016-07-27T16:18:59Z</dc:date>
    </item>
    <item>
      <title>Re: How to get session key in a search script (| script ) similar to the way a scripted input can?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-get-session-key-in-a-search-script-script-similar-to-the/m-p/282500#M85308</link>
      <description>&lt;P&gt;first you create /apps/appName/default/commands.conf:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;[myCommandName]
filename = myCommandName.py
passauth = true  
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;"passauth = true" is what sends the auth details through from SPL to your python command.&lt;/P&gt;

&lt;P&gt;Then you create python script in /apps/appName/bin/myCommandName.py:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;import splunk.Intersplunk 
import splunk.mining.dcutils as dcu

logger = dcu.getLogger()

#results = previous data in the search pipe
#settings = splunk 'header'
results,dummy,settings = splunk.Intersplunk.getOrganizedResults()
sessionKey = settings.get("sessionKey")

#Below would log sessionKey to python.log, not the best idea, here for example
logger.info(sessionKey) 

# Below logs 1st result's _raw field to python.log, just an example of how to parse results from intersplunk.getOrganizedResutls
logger.info(results()[0]["_raw"]) 

#Below sample function iterates over each row of results and adds your user's sessionKey as field onto each row of the results
def addSessionKey(results,settings):
 for result in results:
  result["sessionKey"] = settings.get("sessionKey")
 return results

#Below is how you return your potentially modified search results &amp;amp; settingsback to splunk search pipeline
splunk.Intersplunk.outputResults(addSessionKey(results,settings))

#example REST post using sessionKey
 headers = {'Authorization':''}
 headers['Authorization'] = 'Splunk ' + settings.get("sessionKey")  
 data = {'name':'restart_link','value':'Splunk must be restarted for changes to take effect.  [[/manager/search/control| Click here to restart from the Manager.]]','severity':'warn'}
 r = requests.post("https://localhost:8089/services/messages/new", headers=headers, data=data, verify=False)
 logger.info(r.status_code) 
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Then you restart and execute the command. &lt;CODE&gt;... | myCommandName | table sessionKey&lt;/CODE&gt;&lt;/P&gt;

&lt;P&gt;If it exits non-zero, look in the job log&lt;BR /&gt;
If it completes but doesnt give you proper results check &lt;CODE&gt;index=_internal source=*python*&lt;/CODE&gt;&lt;/P&gt;

&lt;P&gt;There are other things in "settings" you may wish to explore.  authString is used for manipulated splunk via CLI for example&lt;BR /&gt;
user can be found in "results", etc... good to send both settings and results to log and see what you have there.&lt;/P&gt;</description>
      <pubDate>Wed, 27 Jul 2016 17:20:24 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-get-session-key-in-a-search-script-script-similar-to-the/m-p/282500#M85308</guid>
      <dc:creator>jkat54</dc:creator>
      <dc:date>2016-07-27T17:20:24Z</dc:date>
    </item>
    <item>
      <title>Re: How to get session key in a search script (| script ) similar to the way a scripted input can?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-get-session-key-in-a-search-script-script-similar-to-the/m-p/282501#M85309</link>
      <description>&lt;P&gt;Hi,&lt;BR /&gt;
I used the same approach but I received this error&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;command="remedyincidentcreate", Failed to get conf=remedy, stanza=remedy_account, status=401, reason=Unauthorized, detail=   call not properly authenticated  
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;I have set the passauth = true and insert the following in my script &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;import sys
import splunk.Intersplunk as si
def main():
 results,dummyresults,settings = si.getOrganizedResults()
 handler = RemedyIncidentCreateManual()
 handler.handle()
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Any help is appreciated.&lt;/P&gt;</description>
      <pubDate>Tue, 25 Oct 2016 06:46:03 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-get-session-key-in-a-search-script-script-similar-to-the/m-p/282501#M85309</guid>
      <dc:creator>dellytaniasetia</dc:creator>
      <dc:date>2016-10-25T06:46:03Z</dc:date>
    </item>
    <item>
      <title>Re: How to get session key in a search script (| script ) similar to the way a scripted input can?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-get-session-key-in-a-search-script-script-similar-to-the/m-p/282502#M85310</link>
      <description>&lt;P&gt;Then you're trying to pass the Splunk authentication token to remedy?  That's not going to work at all.  You'll have a different auth token / user &amp;amp; pass for remedy.  The auth token here is for Splunk only.&lt;/P&gt;</description>
      <pubDate>Tue, 25 Oct 2016 08:02:48 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-get-session-key-in-a-search-script-script-similar-to-the/m-p/282502#M85310</guid>
      <dc:creator>jkat54</dc:creator>
      <dc:date>2016-10-25T08:02:48Z</dc:date>
    </item>
    <item>
      <title>Re: How to get session key in a search script (| script ) similar to the way a scripted input can?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-get-session-key-in-a-search-script-script-similar-to-the/m-p/282503#M85311</link>
      <description>&lt;P&gt;Make sure if you copy and paste from the commands.conf file example above, you remove the comment:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt; passauth = true  #&amp;lt;- the keys to the castle
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;It should just be:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt; passauth = true
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Splunk conf files don't always like comments at the end of a line&lt;/P&gt;</description>
      <pubDate>Fri, 07 Apr 2017 11:33:56 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-get-session-key-in-a-search-script-script-similar-to-the/m-p/282503#M85311</guid>
      <dc:creator>TonyLeeVT</dc:creator>
      <dc:date>2017-04-07T11:33:56Z</dc:date>
    </item>
    <item>
      <title>Re: How to get session key in a search script (| script ) similar to the way a scripted input can?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-get-session-key-in-a-search-script-script-similar-to-the/m-p/282504#M85312</link>
      <description>&lt;P&gt;thanks god! it's two days that i'm struggling about this. thanks jkat54! I owe you one (or a thousand)&lt;/P&gt;</description>
      <pubDate>Fri, 14 Sep 2018 16:11:26 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-get-session-key-in-a-search-script-script-similar-to-the/m-p/282504#M85312</guid>
      <dc:creator>fabiofox</dc:creator>
      <dc:date>2018-09-14T16:11:26Z</dc:date>
    </item>
    <item>
      <title>Re: How to get session key in a search script (| script ) similar to the way a scripted input can?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-get-session-key-in-a-search-script-script-similar-to-the/m-p/282505#M85313</link>
      <description>&lt;P&gt;I've updated the answer to address this.  Thank you for the feedback.&lt;/P&gt;</description>
      <pubDate>Fri, 14 Sep 2018 16:49:09 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-get-session-key-in-a-search-script-script-similar-to-the/m-p/282505#M85313</guid>
      <dc:creator>jkat54</dc:creator>
      <dc:date>2018-09-14T16:49:09Z</dc:date>
    </item>
    <item>
      <title>Re: How to get session key in a search script (| script ) similar to the way a scripted input can?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-get-session-key-in-a-search-script-script-similar-to-the/m-p/282506#M85314</link>
      <description>&lt;P&gt;The accepted answer is now out-of-date. With the new version 2 of the protocol, use of Intersplunk is deprecated: &lt;/P&gt;

&lt;P&gt;(as of Splunk 6.4.0):&lt;A href="https://docs.splunk.com/Documentation/Splunk/6.4.0/Search/Aboutcustomsearchcommands"&gt;https://docs.splunk.com/Documentation/Splunk/6.4.0/Search/Aboutcustomsearchcommands&lt;/A&gt;&lt;/P&gt;

&lt;P&gt;(as of today) &lt;A href="https://docs.splunk.com/Documentation/Splunk/7.2.5/Search/Aboutcustomsearchcommands"&gt;https://docs.splunk.com/Documentation/Splunk/7.2.5/Search/Aboutcustomsearchcommands&lt;/A&gt;&lt;/P&gt;

&lt;P&gt;here is an example that works for me to use the session key to perform a search within a custom command without actually retreiving it myself and adding it as a header:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;class CustomCommand(StreamingCommand):
    def stream(self, records):
                mysearch="search index=_internal"
                kwargs_create = {'earliest_time':'2019-04-01T12:00:00','latest_time':'2019-04-01:01:00'}
                job = self.service.jobs.create(mysearch,**kwargs_create)

dispatch(IpToUserCommand, sys.argv, sys.stdin, sys.stdout, __name__)
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Of course, add in all the appropriate error handling.&lt;/P&gt;

&lt;P&gt;self.service returns a splunklib.client.Service object (&lt;A href="https://docs.splunk.com/DocumentationStatic/PythonSDK/1.6.5/searchcommands.html#splunklib.searchcommands.StreamingCommand.service"&gt;https://docs.splunk.com/DocumentationStatic/PythonSDK/1.6.5/searchcommands.html#splunklib.searchcommands.StreamingCommand.service&lt;/A&gt;), which already has an authentication token attached. The guidance in @jkat54 post about needing passauth = true in commands.conf still applies&lt;/P&gt;</description>
      <pubDate>Tue, 16 Apr 2019 00:35:41 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-get-session-key-in-a-search-script-script-similar-to-the/m-p/282506#M85314</guid>
      <dc:creator>supersleepwalke</dc:creator>
      <dc:date>2019-04-16T00:35:41Z</dc:date>
    </item>
    <item>
      <title>Re: How to get session key in a search script (| script ) similar to the way a scripted input can?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-get-session-key-in-a-search-script-script-similar-to-the/m-p/282507#M85315</link>
      <description>&lt;P&gt;I downvoted this post because answer is out of date. it appears that this guidance applies for version 1 of the custom search command protocol, which was deprecated just a couple months before this answer was published.&lt;/P&gt;</description>
      <pubDate>Tue, 16 Apr 2019 00:42:25 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-get-session-key-in-a-search-script-script-similar-to-the/m-p/282507#M85315</guid>
      <dc:creator>supersleepwalke</dc:creator>
      <dc:date>2019-04-16T00:42:25Z</dc:date>
    </item>
    <item>
      <title>Re: How to get session key in a search script (| script ) similar to the way a scripted input can?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-get-session-key-in-a-search-script-script-similar-to-the/m-p/282508#M85316</link>
      <description>&lt;P&gt;Deprecated and EOL are two different things.  There’s nothing wrong with this method.  It still works.&lt;/P&gt;

&lt;P&gt;Downvotes should be reserved for answers that would cause harm or answers that are vulgar/rude, etc.&lt;/P&gt;</description>
      <pubDate>Tue, 16 Apr 2019 10:53:33 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-get-session-key-in-a-search-script-script-similar-to-the/m-p/282508#M85316</guid>
      <dc:creator>jkat54</dc:creator>
      <dc:date>2019-04-16T10:53:33Z</dc:date>
    </item>
    <item>
      <title>Re: How to get session key in a search script (| script ) similar to the way a scripted input can?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-get-session-key-in-a-search-script-script-similar-to-the/m-p/282509#M85317</link>
      <description>&lt;P&gt;@supersleepwalker &lt;/P&gt;</description>
      <pubDate>Tue, 16 Apr 2019 10:54:39 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-get-session-key-in-a-search-script-script-similar-to-the/m-p/282509#M85317</guid>
      <dc:creator>jkat54</dc:creator>
      <dc:date>2019-04-16T10:54:39Z</dc:date>
    </item>
    <item>
      <title>Re: How to get session key in a search script (| script ) similar to the way a scripted input can?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-get-session-key-in-a-search-script-script-similar-to-the/m-p/282510#M85318</link>
      <description>&lt;P&gt;yeah, I was unsure on downvoting. I guess I interpreted an out-of-date answer to be "harmful" because I was trying to use the latest recommended technology, and this answer led me down the wrong path and caused me to waste time. I considered that harmful. I can see how other people would disagree.&lt;/P&gt;</description>
      <pubDate>Tue, 16 Apr 2019 15:12:52 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-get-session-key-in-a-search-script-script-similar-to-the/m-p/282510#M85318</guid>
      <dc:creator>supersleepwalke</dc:creator>
      <dc:date>2019-04-16T15:12:52Z</dc:date>
    </item>
    <item>
      <title>Re: How to get session key in a search script (| script ) similar to the way a scripted input can?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-get-session-key-in-a-search-script-script-similar-to-the/m-p/282511#M85319</link>
      <description>&lt;P&gt;I still use intersplunk in 7.2... so I don’t believe it causes harm, but in general we don’t go downvoting accepted answers from 2016 due to newness conflicts.&lt;/P&gt;</description>
      <pubDate>Tue, 16 Apr 2019 21:54:59 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-get-session-key-in-a-search-script-script-similar-to-the/m-p/282511#M85319</guid>
      <dc:creator>jkat54</dc:creator>
      <dc:date>2019-04-16T21:54:59Z</dc:date>
    </item>
    <item>
      <title>Re: How to get session key in a search script (| script ) similar to the way a scripted input can?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-get-session-key-in-a-search-script-script-similar-to-the/m-p/282512#M85320</link>
      <description>&lt;P&gt;incredibly helpful, thank you!&lt;/P&gt;</description>
      <pubDate>Thu, 19 Mar 2020 19:11:09 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-get-session-key-in-a-search-script-script-similar-to-the/m-p/282512#M85320</guid>
      <dc:creator>andrewtrobec</dc:creator>
      <dc:date>2020-03-19T19:11:09Z</dc:date>
    </item>
  </channel>
</rss>

