<?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: Custom command arguments in Getting Data In</title>
    <link>https://community.splunk.com/t5/Getting-Data-In/Custom-command-arguments/m-p/353252#M93602</link>
    <description>&lt;P&gt;I have created below sample script in python which finds hostname from output and ingest data into splunk using HTTP Event Collector &lt;/P&gt;

&lt;P&gt;test.py&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;import requests,sys,splunk.Intersplunk,json
keywords, argvals = splunk.Intersplunk.getKeywordsAndOptions()

try:
     head={"Authorization":"Splunk 34b7bbe4-f239-44b5-ba65-61d5bec103af", "Content-Type": "application/json"}
     url="http://localhost:8088/services/collector/event"
     results = splunk.Intersplunk.getOrganizedResults()
     item = results[0]
     for a in item:
          b = a['host']
     data={"sourcetype": "test", "event": b}
     r = requests.post(url, data=json.dumps(data), headers=head)
except Exception, e:
    splunk.Intersplunk.parseError(e)
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;commands.conf&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;[testcommand]
filename = test.py
local = true
supports_rawargs = false
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Splunk query which I am running&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=_internal | stats count by host | testcommand
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;I hope this helps to create your own script based on your requirement.&lt;/P&gt;</description>
    <pubDate>Wed, 20 Dec 2017 16:06:20 GMT</pubDate>
    <dc:creator>harsmarvania57</dc:creator>
    <dc:date>2017-12-20T16:06:20Z</dc:date>
    <item>
      <title>Custom command arguments</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/Custom-command-arguments/m-p/353249#M93599</link>
      <description>&lt;P&gt;Hello Splunkers!&lt;BR /&gt;
I have a custom command, that execute a perl script with argument.&lt;BR /&gt;
Script.pl&lt;BR /&gt;
//////////////&lt;/P&gt;

&lt;H1&gt;!/usr/bin/perl&lt;/H1&gt;

&lt;P&gt;use strict;&lt;BR /&gt;
use warnings;&lt;BR /&gt;
my $curlResponseCode = &lt;CODE&gt;curl -v -H "Content-Type: application/xml" -X POST -H "X-X-API-Key: f2c3a693ef31HHHH7b2a294f0f9e5b84413" -d "&amp;lt;AAA&amp;gt;&amp;lt;BBBB&amp;gt;AAA&amp;lt;/BBBB&amp;gt;&amp;lt;CCCC&amp;gt;50&amp;lt;/CCCC&amp;gt;&amp;lt;VVVV&amp;gt;$ARGV[0]&amp;lt;/VVVV&amp;gt;&amp;lt;/AAAA&amp;gt;" "http://www.URL.com/test.xml"&lt;/CODE&gt;;&lt;BR /&gt;
///////////////////////&lt;BR /&gt;
Commands.conf&lt;BR /&gt;
[myscript]&lt;BR /&gt;
type=perl&lt;BR /&gt;
filename = script.pl&lt;/P&gt;

&lt;P&gt;This script writes in corporate web site information.&lt;BR /&gt;
I execute perl script.pl test, the script work fine.&lt;BR /&gt;
I use the following search:&lt;BR /&gt;
index=XXX &lt;BR /&gt;
|  stats count by field1&lt;BR /&gt;
| script myscript field1&lt;BR /&gt;
I need the value of field1, no the string field1.&lt;BR /&gt;
I tried with ‘field1’, ‘$field1’ …. And any combination that I imagine&lt;BR /&gt;
Any idea?&lt;BR /&gt;
Thnks!&lt;/P&gt;</description>
      <pubDate>Tue, 19 Dec 2017 20:16:02 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/Custom-command-arguments/m-p/353249#M93599</guid>
      <dc:creator>alvaro_garcia</dc:creator>
      <dc:date>2017-12-19T20:16:02Z</dc:date>
    </item>
    <item>
      <title>Re: Custom command arguments</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/Custom-command-arguments/m-p/353250#M93600</link>
      <description>&lt;P&gt;Answer given on this question might help you &lt;A href="https://answers.splunk.com/answers/385936/unable-to-execute-python-script-could-be-splunk-li.html"&gt;https://answers.splunk.com/answers/385936/unable-to-execute-python-script-could-be-splunk-li.html&lt;/A&gt; but they are for python, you need to modify your perl script accordingly and give it a try.&lt;/P&gt;</description>
      <pubDate>Wed, 20 Dec 2017 07:59:22 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/Custom-command-arguments/m-p/353250#M93600</guid>
      <dc:creator>harsmarvania57</dc:creator>
      <dc:date>2017-12-20T07:59:22Z</dc:date>
    </item>
    <item>
      <title>Re: Custom command arguments</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/Custom-command-arguments/m-p/353251#M93601</link>
      <description>&lt;P&gt;I adapted my perl script to python:&lt;/P&gt;

&lt;P&gt;import requests,sys,splunk.Intersplunk&lt;BR /&gt;
keywords, argvals = splunk.Intersplunk.getKeywordsAndOptions()&lt;BR /&gt;
argument1 = argvals.get("field1")&lt;BR /&gt;
print argument1&lt;BR /&gt;
url= "&lt;A href="http://www.XXXXXcom/AAA.xml"&gt;http://www.XXXXXcom/AAA.xml&lt;/A&gt;"&lt;BR /&gt;
headers = {'API-Key': 'f2c3a693esb2ad02f0f9e5b84413',&lt;BR /&gt;
                    'Content-Type': 'application/xml'}&lt;BR /&gt;
data = "% (argument1)"&lt;BR /&gt;
r = requests.post(url, data=data, headers=headers)&lt;/P&gt;

&lt;P&gt;But my problem now is how to pass the value of search field to argument1, i tried:&lt;BR /&gt;
&lt;A href="https://answers.splunk.com/answers/409554/how-to-pass-hostname-to-a-custom-alert-script.html"&gt;https://answers.splunk.com/answers/409554/how-to-pass-hostname-to-a-custom-alert-script.html&lt;/A&gt; and others. But I not an expert in python&lt;/P&gt;

&lt;P&gt;Thanks&lt;/P&gt;</description>
      <pubDate>Wed, 20 Dec 2017 10:54:53 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/Custom-command-arguments/m-p/353251#M93601</guid>
      <dc:creator>alvaro_garcia</dc:creator>
      <dc:date>2017-12-20T10:54:53Z</dc:date>
    </item>
    <item>
      <title>Re: Custom command arguments</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/Custom-command-arguments/m-p/353252#M93602</link>
      <description>&lt;P&gt;I have created below sample script in python which finds hostname from output and ingest data into splunk using HTTP Event Collector &lt;/P&gt;

&lt;P&gt;test.py&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;import requests,sys,splunk.Intersplunk,json
keywords, argvals = splunk.Intersplunk.getKeywordsAndOptions()

try:
     head={"Authorization":"Splunk 34b7bbe4-f239-44b5-ba65-61d5bec103af", "Content-Type": "application/json"}
     url="http://localhost:8088/services/collector/event"
     results = splunk.Intersplunk.getOrganizedResults()
     item = results[0]
     for a in item:
          b = a['host']
     data={"sourcetype": "test", "event": b}
     r = requests.post(url, data=json.dumps(data), headers=head)
except Exception, e:
    splunk.Intersplunk.parseError(e)
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;commands.conf&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;[testcommand]
filename = test.py
local = true
supports_rawargs = false
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Splunk query which I am running&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=_internal | stats count by host | testcommand
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;I hope this helps to create your own script based on your requirement.&lt;/P&gt;</description>
      <pubDate>Wed, 20 Dec 2017 16:06:20 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/Custom-command-arguments/m-p/353252#M93602</guid>
      <dc:creator>harsmarvania57</dc:creator>
      <dc:date>2017-12-20T16:06:20Z</dc:date>
    </item>
    <item>
      <title>Re: Custom command arguments</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/Custom-command-arguments/m-p/353253#M93603</link>
      <description>&lt;P&gt;Hello, thanks work fine!!&lt;BR /&gt;
Thnks a lot.&lt;BR /&gt;
Only a appreciation I need to change &lt;STRONG&gt;except Exception, e:&lt;/STRONG&gt; to &lt;STRONG&gt;except Exception as e:&lt;/STRONG&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 21 Dec 2017 08:10:15 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/Custom-command-arguments/m-p/353253#M93603</guid>
      <dc:creator>alvaro_garcia</dc:creator>
      <dc:date>2017-12-21T08:10:15Z</dc:date>
    </item>
    <item>
      <title>Re: Custom command arguments</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/Custom-command-arguments/m-p/353254#M93604</link>
      <description>&lt;P&gt;harsmarvania57 post as answer, and I set as correct&lt;/P&gt;</description>
      <pubDate>Thu, 21 Dec 2017 08:14:02 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/Custom-command-arguments/m-p/353254#M93604</guid>
      <dc:creator>alvaro_garcia</dc:creator>
      <dc:date>2017-12-21T08:14:02Z</dc:date>
    </item>
    <item>
      <title>Re: Custom command arguments</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/Custom-command-arguments/m-p/353255#M93605</link>
      <description>&lt;P&gt;Glad to hear that it worked, I have converted my comment as answer please accept and upvote it.&lt;/P&gt;</description>
      <pubDate>Thu, 21 Dec 2017 08:16:33 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/Custom-command-arguments/m-p/353255#M93605</guid>
      <dc:creator>harsmarvania57</dc:creator>
      <dc:date>2017-12-21T08:16:33Z</dc:date>
    </item>
    <item>
      <title>Re: Custom command arguments</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/Custom-command-arguments/m-p/353256#M93606</link>
      <description>&lt;P&gt;Hi, the last question, ^_^&lt;BR /&gt;
My query returns many result, I need to made a request for result.&lt;/P&gt;

&lt;P&gt;Thanks!&lt;/P&gt;</description>
      <pubDate>Fri, 22 Dec 2017 07:29:58 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/Custom-command-arguments/m-p/353256#M93606</guid>
      <dc:creator>alvaro_garcia</dc:creator>
      <dc:date>2017-12-22T07:29:58Z</dc:date>
    </item>
    <item>
      <title>Re: Custom command arguments</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/Custom-command-arguments/m-p/353257#M93607</link>
      <description>&lt;P&gt;Here is updated python script&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;import requests,sys,splunk.Intersplunk,json
keywords, argvals = splunk.Intersplunk.getKeywordsAndOptions()

try:
     head={"Authorization":"Splunk 34b7bbe4-f239-44b5-ba65-61d5bec103af", "Content-Type": "application/json"}
     url="http://localhost:8088/services/collector/event"
     results = splunk.Intersplunk.getOrganizedResults()
     item = results[0]
     for a in item:
       b = a['host']
       data={"sourcetype": "test", "event": b}
       r = requests.post(url, data=json.dumps(data), headers=head)
except Exception as e:
    splunk.Intersplunk.parseError(e)
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;If it works then you can upvote my comment.&lt;/P&gt;</description>
      <pubDate>Fri, 22 Dec 2017 08:48:11 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/Custom-command-arguments/m-p/353257#M93607</guid>
      <dc:creator>harsmarvania57</dc:creator>
      <dc:date>2017-12-22T08:48:11Z</dc:date>
    </item>
    <item>
      <title>Re: Custom command arguments</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/Custom-command-arguments/m-p/353258#M93608</link>
      <description>&lt;P&gt;I am using  &lt;STRONG&gt;r = requests.post(url, data=data2, headers=head)&lt;/STRONG&gt;, my data is in xml format&lt;/P&gt;</description>
      <pubDate>Fri, 22 Dec 2017 09:24:00 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/Custom-command-arguments/m-p/353258#M93608</guid>
      <dc:creator>alvaro_garcia</dc:creator>
      <dc:date>2017-12-22T09:24:00Z</dc:date>
    </item>
    <item>
      <title>Re: Custom command arguments</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/Custom-command-arguments/m-p/353259#M93609</link>
      <description>&lt;P&gt;Which value are you fetching from Splunk output url or data2 ? If you can paste your script here then it will be helpful.&lt;/P&gt;</description>
      <pubDate>Fri, 22 Dec 2017 09:35:04 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/Custom-command-arguments/m-p/353259#M93609</guid>
      <dc:creator>harsmarvania57</dc:creator>
      <dc:date>2017-12-22T09:35:04Z</dc:date>
    </item>
    <item>
      <title>Re: Custom command arguments</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/Custom-command-arguments/m-p/353260#M93610</link>
      <description>&lt;H1&gt;!/usr/bin/env python&lt;/H1&gt;

&lt;P&gt;import requests,sys,splunk.Intersplunk&lt;BR /&gt;
keywords, argvals = splunk.Intersplunk.getKeywordsAndOptions()&lt;/P&gt;

&lt;P&gt;try:&lt;BR /&gt;
      head={"X-API-Key": "bca3cd217870968ddd4a6a2", "Content-Type": "application/xml"}&lt;BR /&gt;
      url="&lt;A href="https://mydomain/host"&gt;https://mydomain/host&lt;/A&gt;"&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;  results = splunk.Intersplunk.getOrganizedResults()
  item = results[0]
  for a in item:
                  AA = a['AA']
                 BB = a['tBB']
                  data2="&amp;lt;field1&amp;gt;&amp;lt;field2&amp;gt;2&amp;lt;/field2&amp;gt;&amp;lt;field3&amp;gt;"+ AA +"&amp;lt;/field3&amp;gt;&amp;lt;field4&amp;gt;"+ BB +"&amp;lt;/field4&amp;gt;&amp;lt;/field1&amp;gt;"
                  r = requests.post(url, data=data2, headers=head)
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;except Exception as e:&lt;BR /&gt;
     splunk.Intersplunk.parseError(e)&lt;/P&gt;</description>
      <pubDate>Fri, 22 Dec 2017 09:41:16 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/Custom-command-arguments/m-p/353260#M93610</guid>
      <dc:creator>alvaro_garcia</dc:creator>
      <dc:date>2017-12-22T09:41:16Z</dc:date>
    </item>
    <item>
      <title>Re: Custom command arguments</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/Custom-command-arguments/m-p/353261#M93611</link>
      <description>&lt;P&gt;When you run above script what problem are you facing? and can you please remove &lt;CODE&gt;!/usr/bin/env python&lt;/CODE&gt; from your script because splunk will use inbuilt python.&lt;/P&gt;</description>
      <pubDate>Fri, 22 Dec 2017 10:09:52 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/Custom-command-arguments/m-p/353261#M93611</guid>
      <dc:creator>harsmarvania57</dc:creator>
      <dc:date>2017-12-22T10:09:52Z</dc:date>
    </item>
    <item>
      <title>Re: Custom command arguments</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/Custom-command-arguments/m-p/353262#M93612</link>
      <description>&lt;P&gt;ok, thanks right, I remove the !/usr/bin/env python&lt;/P&gt;</description>
      <pubDate>Tue, 26 Dec 2017 06:21:53 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/Custom-command-arguments/m-p/353262#M93612</guid>
      <dc:creator>alvaro_garcia</dc:creator>
      <dc:date>2017-12-26T06:21:53Z</dc:date>
    </item>
  </channel>
</rss>

