<?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: Why does my python scripted input not work? in Splunk Dev</title>
    <link>https://community.splunk.com/t5/Splunk-Dev/Why-does-my-python-scripted-input-not-work/m-p/344375#M5370</link>
    <description>&lt;P&gt;@andrewtrobec, Refer to following documentation to write a basic python scripted input to Splunk: &lt;A href="https://sublimerobots.com/2017/01/simple-splunk-scripted-input-example/"&gt;https://sublimerobots.com/2017/01/simple-splunk-scripted-input-example/&lt;/A&gt;&lt;/P&gt;

&lt;P&gt;Add code to write to splunk's internal log using &lt;CODE&gt;sys.stderr.write()&lt;/CODE&gt;:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;sys.stderr.write("python script is starting up\n") 
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Which can be accessed using the following query,&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index="_internal" sourcetype="splunkd" source="*splunkd" test.py
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Also, you should test out your script in the Python compiler of your choice whether it runs independently of Splunk or not.&lt;/P&gt;

&lt;P&gt;FYI Python code snippet from blog mentioned above&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;# So we can run this scipt under python 2 or 3
from __future__ import print_function

import sys                      # for sys.stderr.write()
import time                     # for strftime
from datetime import datetime   # for datetime.utcnow()
import random                   # to provide random data for this example

sys.stderr.write("TA-SimpleApp python script is starting up\n")                  

# output a single event
print (str(time.time()) + ", username=\"agent smith\", status=\"mediocre\", admin=noah, money=" + str(random.randint(1, 1000)))
&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Wed, 13 Dec 2017 10:20:49 GMT</pubDate>
    <dc:creator>niketn</dc:creator>
    <dc:date>2017-12-13T10:20:49Z</dc:date>
    <item>
      <title>Why does my python scripted input not work?</title>
      <link>https://community.splunk.com/t5/Splunk-Dev/Why-does-my-python-scripted-input-not-work/m-p/344374#M5369</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;

&lt;P&gt;I am trying to get a very simple python scripted input to work, but I cannot.  I am using Splunk 6.6.3 running on Windows 10.  The code for the scripted input named &lt;CODE&gt;test.py&lt;/CODE&gt; is:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;import sys
from time import localtime,strftime
import time

def main(argv):
    indexTime = strftime("%m/%d/%Y %H:%M:%S %p %Z",localtime())
    print "%s, name=%s,location=%s" % (indexTime,"Andrew","Europe")

if __name__ == '__main__':
    main(sys.argv[1:])
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;The file is located in &lt;CODE&gt;$SPLUNK_HOME\etc\apps\search\bin&lt;/CODE&gt;&lt;/P&gt;

&lt;P&gt;The &lt;CODE&gt;inputs.conf&lt;/CODE&gt; located in &lt;CODE&gt;$SPLUNK_HOME\etc\apps\search\local&lt;/CODE&gt;  looks like this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;[script://$SPLUNK_HOME\etc\apps\search\bin\test.py]
disabled = false
index = main
interval = 60.0
sourcetype = csv
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Now that it has been configured, nothing seems to happen.  I don't even know whether the script is being run.  When I run &lt;CODE&gt;index=main&lt;/CODE&gt; as a search, it returns no results.  &lt;CODE&gt;index=_internal test.py&lt;/CODE&gt; doesn't show any signs of life either.&lt;/P&gt;

&lt;P&gt;Could somebody help me troubleshoot?  Is it a permissions issue?  Is it the script?  Is it the configuration?&lt;/P&gt;

&lt;P&gt;Any point in the right direction would be greatly appreciated.&lt;/P&gt;

&lt;P&gt;Best regards,&lt;/P&gt;

&lt;P&gt;Andrew&lt;/P&gt;</description>
      <pubDate>Wed, 13 Dec 2017 09:56:50 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Dev/Why-does-my-python-scripted-input-not-work/m-p/344374#M5369</guid>
      <dc:creator>andrewtrobec</dc:creator>
      <dc:date>2017-12-13T09:56:50Z</dc:date>
    </item>
    <item>
      <title>Re: Why does my python scripted input not work?</title>
      <link>https://community.splunk.com/t5/Splunk-Dev/Why-does-my-python-scripted-input-not-work/m-p/344375#M5370</link>
      <description>&lt;P&gt;@andrewtrobec, Refer to following documentation to write a basic python scripted input to Splunk: &lt;A href="https://sublimerobots.com/2017/01/simple-splunk-scripted-input-example/"&gt;https://sublimerobots.com/2017/01/simple-splunk-scripted-input-example/&lt;/A&gt;&lt;/P&gt;

&lt;P&gt;Add code to write to splunk's internal log using &lt;CODE&gt;sys.stderr.write()&lt;/CODE&gt;:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;sys.stderr.write("python script is starting up\n") 
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Which can be accessed using the following query,&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index="_internal" sourcetype="splunkd" source="*splunkd" test.py
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Also, you should test out your script in the Python compiler of your choice whether it runs independently of Splunk or not.&lt;/P&gt;

&lt;P&gt;FYI Python code snippet from blog mentioned above&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;# So we can run this scipt under python 2 or 3
from __future__ import print_function

import sys                      # for sys.stderr.write()
import time                     # for strftime
from datetime import datetime   # for datetime.utcnow()
import random                   # to provide random data for this example

sys.stderr.write("TA-SimpleApp python script is starting up\n")                  

# output a single event
print (str(time.time()) + ", username=\"agent smith\", status=\"mediocre\", admin=noah, money=" + str(random.randint(1, 1000)))
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 13 Dec 2017 10:20:49 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Dev/Why-does-my-python-scripted-input-not-work/m-p/344375#M5370</guid>
      <dc:creator>niketn</dc:creator>
      <dc:date>2017-12-13T10:20:49Z</dc:date>
    </item>
    <item>
      <title>Re: Why does my python scripted input not work?</title>
      <link>https://community.splunk.com/t5/Splunk-Dev/Why-does-my-python-scripted-input-not-work/m-p/344376#M5371</link>
      <description>&lt;P&gt;First run the script from the folder and check whether it is giving you output or not. &lt;/P&gt;

&lt;P&gt;Probably you have given wrong "\" ...replace this with "/"&lt;/P&gt;

&lt;P&gt;[script://$SPLUNK_HOME/etc/apps/search/bin/test.py]&lt;BR /&gt;
 disabled = false&lt;BR /&gt;
 index = main&lt;BR /&gt;
 interval = 60.0&lt;BR /&gt;
 sourcetype = csv&lt;/P&gt;

&lt;P&gt;Also check the user with which you have installed Splunk have permission to run the script. &lt;/P&gt;</description>
      <pubDate>Wed, 13 Dec 2017 10:26:16 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Dev/Why-does-my-python-scripted-input-not-work/m-p/344376#M5371</guid>
      <dc:creator>sandyIscream</dc:creator>
      <dc:date>2017-12-13T10:26:16Z</dc:date>
    </item>
    <item>
      <title>Re: Why does my python scripted input not work?</title>
      <link>https://community.splunk.com/t5/Splunk-Dev/Why-does-my-python-scripted-input-not-work/m-p/344377#M5372</link>
      <description>&lt;P&gt;Hi Andrew,&lt;/P&gt;

&lt;P&gt;To start with,&lt;BR /&gt;
Have you restarted Splunk after adding your scripted input?&lt;/P&gt;</description>
      <pubDate>Wed, 13 Dec 2017 10:32:30 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Dev/Why-does-my-python-scripted-input-not-work/m-p/344377#M5372</guid>
      <dc:creator>damien_chillet</dc:creator>
      <dc:date>2017-12-13T10:32:30Z</dc:date>
    </item>
    <item>
      <title>Re: Why does my python scripted input not work?</title>
      <link>https://community.splunk.com/t5/Splunk-Dev/Why-does-my-python-scripted-input-not-work/m-p/344378#M5373</link>
      <description>&lt;P&gt;I suspect that the "csv" sourcetype is to blame. Your output does not have a header line.&lt;/P&gt;

&lt;P&gt;Try:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;[script://$SPLUNK_HOME\etc\apps\search\bin\test.py]
...
sourcetype = test
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;If you want to use the "csv" sourcetype, change the output of your script to print something like this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;print "date,name,location"
print "%s,%s,%s" % (indexTime,"Andrew","Europe")
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 13 Dec 2017 10:38:39 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Dev/Why-does-my-python-scripted-input-not-work/m-p/344378#M5373</guid>
      <dc:creator>Yunagi</dc:creator>
      <dc:date>2017-12-13T10:38:39Z</dc:date>
    </item>
    <item>
      <title>Re: Why does my python scripted input not work?</title>
      <link>https://community.splunk.com/t5/Splunk-Dev/Why-does-my-python-scripted-input-not-work/m-p/344379#M5374</link>
      <description>&lt;P&gt;This was it!  Thank you so much!&lt;/P&gt;</description>
      <pubDate>Wed, 13 Dec 2017 12:46:40 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Dev/Why-does-my-python-scripted-input-not-work/m-p/344379#M5374</guid>
      <dc:creator>andrewtrobec</dc:creator>
      <dc:date>2017-12-13T12:46:40Z</dc:date>
    </item>
    <item>
      <title>Re: Why does my python scripted input not work?</title>
      <link>https://community.splunk.com/t5/Splunk-Dev/Why-does-my-python-scripted-input-not-work/m-p/344380#M5375</link>
      <description>&lt;P&gt;I made sure to restart after every change.  From another response it turns out that I was using the wrong sourcetype.  Thanks for your input!&lt;/P&gt;</description>
      <pubDate>Wed, 13 Dec 2017 12:47:18 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Dev/Why-does-my-python-scripted-input-not-work/m-p/344380#M5375</guid>
      <dc:creator>andrewtrobec</dc:creator>
      <dc:date>2017-12-13T12:47:18Z</dc:date>
    </item>
    <item>
      <title>Re: Why does my python scripted input not work?</title>
      <link>https://community.splunk.com/t5/Splunk-Dev/Why-does-my-python-scripted-input-not-work/m-p/344381#M5376</link>
      <description>&lt;P&gt;Thanks for the link, very useful.  Also, the &lt;CODE&gt;sys.stderr.write&lt;/CODE&gt; call to debug and perform logging is great!&lt;/P&gt;</description>
      <pubDate>Wed, 13 Dec 2017 12:48:23 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Dev/Why-does-my-python-scripted-input-not-work/m-p/344381#M5376</guid>
      <dc:creator>andrewtrobec</dc:creator>
      <dc:date>2017-12-13T12:48:23Z</dc:date>
    </item>
    <item>
      <title>Re: Why does my python scripted input not work?</title>
      <link>https://community.splunk.com/t5/Splunk-Dev/Why-does-my-python-scripted-input-not-work/m-p/344382#M5377</link>
      <description>&lt;P&gt;I ran the script from another folder and ensured that all was working perfectly before moving it to the bin directory.  When I deploy the app to a linux box then I'll be sure to remember the slashes.  Thanks for your input!&lt;/P&gt;</description>
      <pubDate>Wed, 13 Dec 2017 12:49:43 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Dev/Why-does-my-python-scripted-input-not-work/m-p/344382#M5377</guid>
      <dc:creator>andrewtrobec</dc:creator>
      <dc:date>2017-12-13T12:49:43Z</dc:date>
    </item>
    <item>
      <title>Re: Why does my python scripted input not work?</title>
      <link>https://community.splunk.com/t5/Splunk-Dev/Why-does-my-python-scripted-input-not-work/m-p/344383#M5378</link>
      <description>&lt;P&gt;You're welcome. &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 13 Dec 2017 12:55:43 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Dev/Why-does-my-python-scripted-input-not-work/m-p/344383#M5378</guid>
      <dc:creator>Yunagi</dc:creator>
      <dc:date>2017-12-13T12:55:43Z</dc:date>
    </item>
  </channel>
</rss>

