<?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: Splunk script python no results in Splunk Dev</title>
    <link>https://community.splunk.com/t5/Splunk-Dev/Splunk-script-python-no-results/m-p/105466#M1559</link>
    <description>&lt;P&gt;You can't just call an arbitrary script in a search pipeline. The script must know how to accept Splunk pipeline inputs (unless it ignores them, which yours appears to do, so that's fine), but more importantly it must output them in the right format. As it turns out, the output format is a standard CSV file, including a header that specifies the field names. So basically you need to add a print for the CSV file header that matches the fields you're outputting. In general, you'll be a lot better off using the language-specific CSV libraries as well, rather than printing directly.&lt;/P&gt;

&lt;P&gt;Also, I imagine you understand that this computation can be done in Splunk search language directly and you're merely going through an exercise of getting a simple command to work.&lt;/P&gt;</description>
    <pubDate>Fri, 18 Oct 2013 05:36:33 GMT</pubDate>
    <dc:creator>gkanapathy</dc:creator>
    <dc:date>2013-10-18T05:36:33Z</dc:date>
    <item>
      <title>Splunk script python no results</title>
      <link>https://community.splunk.com/t5/Splunk-Dev/Splunk-script-python-no-results/m-p/105465#M1558</link>
      <description>&lt;P&gt;I am trying to run a python script from Splunk which takes 3 arguments and then suppose to run calculations on those arguments and print the results into Splunk. But I am not getting any results back. There are about 100 events that I want to run the script on.&lt;/P&gt;

&lt;P&gt;Splunk command:&lt;/P&gt;

&lt;P&gt;... | script python amp2 macaddress timestamp numofaverages&lt;/P&gt;

&lt;P&gt;Values of arguments:&lt;/P&gt;

&lt;P&gt;macaddress=11:22:33:44:55:66&lt;BR /&gt;&lt;BR /&gt;
timestamp=123456789&lt;BR /&gt;&lt;BR /&gt;
numofaverages=1,2,3,4,5,6,7,8,9,10&lt;BR /&gt;&lt;/P&gt;

&lt;P&gt;Below is the python script I am trying to run.&lt;/P&gt;

&lt;P&gt;import sys&lt;/P&gt;

&lt;P&gt;mac=sys.argv[1]&lt;BR /&gt;&lt;BR /&gt;
time=sys.argv[2]&lt;BR /&gt;&lt;BR /&gt;
avg=sys.argv[3]&lt;/P&gt;

&lt;P&gt;avg=avg.split(",")&lt;BR /&gt;&lt;BR /&gt;
avgmin=min(avg)&lt;BR /&gt;&lt;BR /&gt;
avgmax=max(avg)&lt;BR /&gt;&lt;BR /&gt;
count=len(avg)&lt;BR /&gt;&lt;/P&gt;

&lt;P&gt;try:&lt;BR /&gt;&lt;BR /&gt;
    &amp;nbsp;avg=map(float, avg)&lt;BR /&gt;&lt;BR /&gt;
    &amp;nbsp;avgmean=round((sum(avg)/count),2)&lt;BR /&gt;&lt;BR /&gt;
except (NameError, ValueError):&lt;BR /&gt;&lt;BR /&gt;
    &amp;nbsp;avgmin="min"&lt;BR /&gt;&lt;BR /&gt;
    &amp;nbsp;avgmax="max"&lt;BR /&gt;&lt;BR /&gt;
    &amp;nbsp;count="bin count"&lt;BR /&gt;&lt;BR /&gt;
    &amp;nbsp;avgmean="mean"&lt;BR /&gt;&lt;/P&gt;

&lt;P&gt;print(mac+","+time+","+avgmin+","+avgmax+","+str(avgmean)+","+str(count))&lt;/P&gt;</description>
      <pubDate>Fri, 18 Oct 2013 02:31:28 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Dev/Splunk-script-python-no-results/m-p/105465#M1558</guid>
      <dc:creator>obhatti</dc:creator>
      <dc:date>2013-10-18T02:31:28Z</dc:date>
    </item>
    <item>
      <title>Re: Splunk script python no results</title>
      <link>https://community.splunk.com/t5/Splunk-Dev/Splunk-script-python-no-results/m-p/105466#M1559</link>
      <description>&lt;P&gt;You can't just call an arbitrary script in a search pipeline. The script must know how to accept Splunk pipeline inputs (unless it ignores them, which yours appears to do, so that's fine), but more importantly it must output them in the right format. As it turns out, the output format is a standard CSV file, including a header that specifies the field names. So basically you need to add a print for the CSV file header that matches the fields you're outputting. In general, you'll be a lot better off using the language-specific CSV libraries as well, rather than printing directly.&lt;/P&gt;

&lt;P&gt;Also, I imagine you understand that this computation can be done in Splunk search language directly and you're merely going through an exercise of getting a simple command to work.&lt;/P&gt;</description>
      <pubDate>Fri, 18 Oct 2013 05:36:33 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Dev/Splunk-script-python-no-results/m-p/105466#M1559</guid>
      <dc:creator>gkanapathy</dc:creator>
      <dc:date>2013-10-18T05:36:33Z</dc:date>
    </item>
    <item>
      <title>Re: Splunk script python no results</title>
      <link>https://community.splunk.com/t5/Splunk-Dev/Splunk-script-python-no-results/m-p/105467#M1560</link>
      <description>&lt;P&gt;For example, you can pretty much replace your command with:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;... | eval n=split(numofaverages,",") | stats min(n) as avgmin max(n) mean(n) count(n) by macaddress,timestamp
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Maybe you want to rename more fields and maybe you want to use the round function to round off the mean, but that's basically it.&lt;/P&gt;</description>
      <pubDate>Fri, 18 Oct 2013 05:43:27 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Dev/Splunk-script-python-no-results/m-p/105467#M1560</guid>
      <dc:creator>gkanapathy</dc:creator>
      <dc:date>2013-10-18T05:43:27Z</dc:date>
    </item>
    <item>
      <title>Re: Splunk script python no results</title>
      <link>https://community.splunk.com/t5/Splunk-Dev/Splunk-script-python-no-results/m-p/105468#M1561</link>
      <description>&lt;P&gt;Hi gkanapathy, thanks for the reply. Yes I can do these calculations in Splunk but this exercise was for me to understand how Splunk interacts with external scripts. Can you give me more information on python CSV header and how to include them in the code?&lt;/P&gt;</description>
      <pubDate>Fri, 18 Oct 2013 14:01:00 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Dev/Splunk-script-python-no-results/m-p/105468#M1561</guid>
      <dc:creator>obhatti</dc:creator>
      <dc:date>2013-10-18T14:01:00Z</dc:date>
    </item>
    <item>
      <title>Re: Splunk script python no results</title>
      <link>https://community.splunk.com/t5/Splunk-Dev/Splunk-script-python-no-results/m-p/105469#M1562</link>
      <description>&lt;P&gt;In the Splunk command for the python script, how do I send values from column as arguments? Right now it is only sending "macaddress", "timestamp" and "numofaverages" as arguments.&lt;/P&gt;</description>
      <pubDate>Sat, 19 Oct 2013 21:33:36 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Dev/Splunk-script-python-no-results/m-p/105469#M1562</guid>
      <dc:creator>obhatti</dc:creator>
      <dc:date>2013-10-19T21:33:36Z</dc:date>
    </item>
    <item>
      <title>Re: Splunk script python no results</title>
      <link>https://community.splunk.com/t5/Splunk-Dev/Splunk-script-python-no-results/m-p/105470#M1563</link>
      <description>&lt;P&gt;Obhatti, what you wamt to do is a Splunk custom search command. Have a look here for details: &lt;/P&gt;

&lt;P&gt;&lt;A href="http://docs.splunk.com/Documentation/Splunk/6.0/AdvancedDev/SearchScripts"&gt;http://docs.splunk.com/Documentation/Splunk/6.0/AdvancedDev/SearchScripts&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Sun, 20 Oct 2013 13:13:24 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Dev/Splunk-script-python-no-results/m-p/105470#M1563</guid>
      <dc:creator>mdessus_splunk</dc:creator>
      <dc:date>2013-10-20T13:13:24Z</dc:date>
    </item>
  </channel>
</rss>

