<?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: Scripted Input - Python SDK - passAuth Not Working in Splunk Dev</title>
    <link>https://community.splunk.com/t5/Splunk-Dev/Scripted-Input-Python-SDK-passAuth-Not-Working/m-p/147798#M2040</link>
    <description>&lt;P&gt;Hmm. I'm not able to even parse the sessionKey out. I'm glad to hear you've got it working! What does your code look like? &lt;/P&gt;

&lt;P&gt;Mine is:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;import splunklib.results as results
import splunklib.client as client
import splunk.entity, splunk.Intersplunk
settings = dict()
records = splunk.Intersplunk.readResults(settings = settings, has_header = True)
sessionKey = settings['sessionKey']
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;And then I get an error saying that it can't find sessionKey. &lt;/P&gt;

&lt;P&gt;My inputs configuration is:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;[script://$SPLUNK_HOME/etc/apps/app/bin/script.py]
disabled = false
interval = 60
sourcetype = xyz
passAuth = true
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;I've also tried it with &lt;CODE&gt;passAuth = admin&lt;/CODE&gt; to no avail, based on the inputs.conf doc. &lt;/P&gt;</description>
    <pubDate>Sun, 18 Jan 2015 18:13:48 GMT</pubDate>
    <dc:creator>David</dc:creator>
    <dc:date>2015-01-18T18:13:48Z</dc:date>
    <item>
      <title>Scripted Input - Python SDK - passAuth Not Working</title>
      <link>https://community.splunk.com/t5/Splunk-Dev/Scripted-Input-Python-SDK-passAuth-Not-Working/m-p/147796#M2038</link>
      <description>&lt;P&gt;I've got a great script that runs just fine with hardcoded credentials, but I'm having trouble making it work as a scripted input. The script uses the Python SDK to make several calls to Splunk.&lt;/P&gt;

&lt;P&gt;I'm initializing the session key via:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;import splunklib.results as results
import splunklib.client as client
import time
import sys

sessionKey = sys.stdin.readline().strip()

if len(sessionKey) == 0:
   sys.stderr.write("Did not receive a session key from splunkd. " +
                    "Please enable passAuth in inputs.conf for this " +
                    "script\n")
   exit(2)

sys.stdout.write("Got Session Key: " + sessionKey + "\n");
sys.stdout.flush()
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Which does successfully print the sessionKey. I'm then initializing the Splunk service via:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;# Create a Service instance and log in
service = client.connect(
    host="ec2-54-148-178-247.us-west-2.compute.amazonaws.com",
    port=8089,
    token=sessionKey)
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Which does not die, but as soon as I try to use that object:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;job = service.jobs.create(searchquery_normal, **kwargs_normalsearch)
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;I get a crash:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;12-09-2014 22:56:57.162 +0000 ERROR ExecProcessor - message from "/opt/splunk/etc/apps/splunk_search_usage/bin/CheckDataStats.sh" Traceback (most recent call last):
12-09-2014 22:56:57.162 +0000 ERROR ExecProcessor - message from "/opt/splunk/etc/apps/splunk_search_usage/bin/CheckDataStats.sh"   File "/opt/splunk/etc/apps/splunk_search_usage/bin/CheckDataStats.py", line 46, in &amp;lt;module&amp;gt;
12-09-2014 22:56:57.162 +0000 ERROR ExecProcessor - message from "/opt/splunk/etc/apps/splunk_search_usage/bin/CheckDataStats.sh"     job = service.jobs.create(searchquery_normal, **kwargs_normalsearch)
12-09-2014 22:56:57.162 +0000 ERROR ExecProcessor - message from "/opt/splunk/etc/apps/splunk_search_usage/bin/CheckDataStats.sh" AttributeError: 'NoneType' object has no attribute 'jobs'
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Has anyone done this successfully?&lt;/P&gt;</description>
      <pubDate>Tue, 09 Dec 2014 22:59:36 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Dev/Scripted-Input-Python-SDK-passAuth-Not-Working/m-p/147796#M2038</guid>
      <dc:creator>David</dc:creator>
      <dc:date>2014-12-09T22:59:36Z</dc:date>
    </item>
    <item>
      <title>Re: Scripted Input - Python SDK - passAuth Not Working</title>
      <link>https://community.splunk.com/t5/Splunk-Dev/Scripted-Input-Python-SDK-passAuth-Not-Working/m-p/147797#M2039</link>
      <description>&lt;P&gt;This may be a bit late, but I was having the same problem, then I re-read the api doc. To use token, you have to use client.Service:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;service = client.Service(token=sessionKey, host=host, port=port)
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 23 Dec 2014 00:26:53 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Dev/Scripted-Input-Python-SDK-passAuth-Not-Working/m-p/147797#M2039</guid>
      <dc:creator>mschon314</dc:creator>
      <dc:date>2014-12-23T00:26:53Z</dc:date>
    </item>
    <item>
      <title>Re: Scripted Input - Python SDK - passAuth Not Working</title>
      <link>https://community.splunk.com/t5/Splunk-Dev/Scripted-Input-Python-SDK-passAuth-Not-Working/m-p/147798#M2040</link>
      <description>&lt;P&gt;Hmm. I'm not able to even parse the sessionKey out. I'm glad to hear you've got it working! What does your code look like? &lt;/P&gt;

&lt;P&gt;Mine is:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;import splunklib.results as results
import splunklib.client as client
import splunk.entity, splunk.Intersplunk
settings = dict()
records = splunk.Intersplunk.readResults(settings = settings, has_header = True)
sessionKey = settings['sessionKey']
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;And then I get an error saying that it can't find sessionKey. &lt;/P&gt;

&lt;P&gt;My inputs configuration is:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;[script://$SPLUNK_HOME/etc/apps/app/bin/script.py]
disabled = false
interval = 60
sourcetype = xyz
passAuth = true
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;I've also tried it with &lt;CODE&gt;passAuth = admin&lt;/CODE&gt; to no avail, based on the inputs.conf doc. &lt;/P&gt;</description>
      <pubDate>Sun, 18 Jan 2015 18:13:48 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Dev/Scripted-Input-Python-SDK-passAuth-Not-Working/m-p/147798#M2040</guid>
      <dc:creator>David</dc:creator>
      <dc:date>2015-01-18T18:13:48Z</dc:date>
    </item>
    <item>
      <title>Re: Scripted Input - Python SDK - passAuth Not Working</title>
      <link>https://community.splunk.com/t5/Splunk-Dev/Scripted-Input-Python-SDK-passAuth-Not-Working/m-p/147799#M2041</link>
      <description>&lt;P&gt;Found the problem -- I assumed that Intersplunk would parse out the sessionKey for me, when in reality it was the only thing passed. For anyone else stumbling across, here's the right config:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;import splunklib.results as results
import splunklib.client as client
import sys

sessionKey = ""

for line in sys.stdin:
  sessionKey = line

service = client.Service(token=sessionKey, host="127.0.0.1", port=8089, user="admin")
kwargs_normalsearch = {"exec_mode": "normal", "app": "splunk_search_usage"}

searchquery_normal = ' [... mysearch ...] '
job = service.jobs.create(searchquery_normal, **kwargs_normalsearch)
[.....]
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;You also do need to use &lt;CODE&gt;passAuth = admin&lt;/CODE&gt; in inputs.conf&lt;/P&gt;

&lt;P&gt;Thanks for your help!&lt;/P&gt;</description>
      <pubDate>Sun, 18 Jan 2015 21:04:44 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Dev/Scripted-Input-Python-SDK-passAuth-Not-Working/m-p/147799#M2041</guid>
      <dc:creator>David</dc:creator>
      <dc:date>2015-01-18T21:04:44Z</dc:date>
    </item>
  </channel>
</rss>

