<?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: External command calling subprocess not working in Getting Data In</title>
    <link>https://community.splunk.com/t5/Getting-Data-In/External-command-calling-subprocess-not-working/m-p/71379#M14520</link>
    <description>&lt;P&gt;Support came back with this which works for shell and other python scripts but I can't get it to work with perl. It is a nice workaround for accessing python modules that are not part of splunk.&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;
    def getemp(host):&lt;BR /&gt;
      cmd = ("./mrilookup.pl ",host)&lt;BR /&gt;
      pseudohandle = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE)&lt;BR /&gt;
      stdout, stderr = pseudohandle.communicate()&lt;BR /&gt;
      return stdout.rstrip()&lt;/P&gt;</description>
    <pubDate>Sun, 24 Mar 2013 14:45:27 GMT</pubDate>
    <dc:creator>rdownie</dc:creator>
    <dc:date>2013-03-24T14:45:27Z</dc:date>
    <item>
      <title>External command calling subprocess not working</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/External-command-calling-subprocess-not-working/m-p/71378#M14519</link>
      <description>&lt;P&gt;I am attempting to write an external command that uses a subprocess call and assigns the value returned by the subprocess call to a field and returns that in the output results. Like the many examples, if I set:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;for r in results:
    r['foo']="bar"
si.outputResults(results)
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;works fine and gives me a fieldname of foo with a value of bar. &lt;/P&gt;&lt;P&gt;&lt;BR /&gt;
But when I try to assign the fieldname to what is returned from my subprocess call, it just creates the fieldname named the value and doesn't pass anything else back &lt;/P&gt;&lt;P&gt;&lt;BR /&gt;
Here is the code I am using, the ldapquery.py script returns a value "22393".&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;#import the python module provided with Splunk
import splunk.Intersplunk as si
import subprocess
import os

#read the results into a variable
results, dummyresults, settings = si.getOrganizedResults()

def getemp(host):
    emp = subprocess.call(["./ldapquery.py", host])
    return emp

#loop over each result. results is a list of dict.
for r in results:
    #r is a dict. Access fields using the fieldname.
    myhost = r['myhost']
    r['employee'] = getemp(myhost)
#return the results back to Splunk
si.outputResults(results)
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;&lt;/P&gt;&lt;P&gt; Outputs  "22393" as the name of the field and just gives it as a header.&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;
the search I am using to test this is:&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;
     | stats count | eval myhost="bemsrv1"   | hrdquery&lt;/P&gt;

&lt;P&gt;the commands.conf file is.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;[hrdquery]
filename = hrdquery.py
streaming = true
retainsevents = true
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;&lt;/P&gt;&lt;P&gt;Any help with this would be greatly appreciated.&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;
Thanks, Bob&lt;/P&gt;</description>
      <pubDate>Fri, 22 Mar 2013 11:08:56 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/External-command-calling-subprocess-not-working/m-p/71378#M14519</guid>
      <dc:creator>rdownie</dc:creator>
      <dc:date>2013-03-22T11:08:56Z</dc:date>
    </item>
    <item>
      <title>Re: External command calling subprocess not working</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/External-command-calling-subprocess-not-working/m-p/71379#M14520</link>
      <description>&lt;P&gt;Support came back with this which works for shell and other python scripts but I can't get it to work with perl. It is a nice workaround for accessing python modules that are not part of splunk.&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;
    def getemp(host):&lt;BR /&gt;
      cmd = ("./mrilookup.pl ",host)&lt;BR /&gt;
      pseudohandle = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE)&lt;BR /&gt;
      stdout, stderr = pseudohandle.communicate()&lt;BR /&gt;
      return stdout.rstrip()&lt;/P&gt;</description>
      <pubDate>Sun, 24 Mar 2013 14:45:27 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/External-command-calling-subprocess-not-working/m-p/71379#M14520</guid>
      <dc:creator>rdownie</dc:creator>
      <dc:date>2013-03-24T14:45:27Z</dc:date>
    </item>
  </channel>
</rss>

