<?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 Help on custom command (Examples needed) in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Help-on-custom-command-Examples-needed/m-p/86822#M22165</link>
    <description>&lt;P&gt;Hi, &lt;/P&gt;

&lt;P&gt;May I ask if there is any steps on how can you have your custom command take in the search results of "x|custom command"? So that when you "x|custom command", the search results of "x" will be able to be printed out on the results panel. &lt;BR /&gt;
For example, your custom command is to print out "Testing123" on the results panel. However, when you typed "source_type|custom command", it will print out "Testing123" and at the same time also the results of "source_type". Is there any examples or steps that I can follow so that I know what can I change in my python file? &lt;BR /&gt;
Thanks in advance! &lt;/P&gt;</description>
    <pubDate>Mon, 28 Sep 2020 13:41:24 GMT</pubDate>
    <dc:creator>sarahh</dc:creator>
    <dc:date>2020-09-28T13:41:24Z</dc:date>
    <item>
      <title>Help on custom command (Examples needed)</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Help-on-custom-command-Examples-needed/m-p/86822#M22165</link>
      <description>&lt;P&gt;Hi, &lt;/P&gt;

&lt;P&gt;May I ask if there is any steps on how can you have your custom command take in the search results of "x|custom command"? So that when you "x|custom command", the search results of "x" will be able to be printed out on the results panel. &lt;BR /&gt;
For example, your custom command is to print out "Testing123" on the results panel. However, when you typed "source_type|custom command", it will print out "Testing123" and at the same time also the results of "source_type". Is there any examples or steps that I can follow so that I know what can I change in my python file? &lt;BR /&gt;
Thanks in advance! &lt;/P&gt;</description>
      <pubDate>Mon, 28 Sep 2020 13:41:24 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Help-on-custom-command-Examples-needed/m-p/86822#M22165</guid>
      <dc:creator>sarahh</dc:creator>
      <dc:date>2020-09-28T13:41:24Z</dc:date>
    </item>
    <item>
      <title>Re: Help on custom command (Examples needed)</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Help-on-custom-command-Examples-needed/m-p/86823#M22166</link>
      <description>&lt;P&gt;Care to post your custom command's python code ?&lt;/P&gt;</description>
      <pubDate>Mon, 08 Apr 2013 15:33:09 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Help-on-custom-command-Examples-needed/m-p/86823#M22166</guid>
      <dc:creator>Damien_Dallimor</dc:creator>
      <dc:date>2013-04-08T15:33:09Z</dc:date>
    </item>
    <item>
      <title>Re: Help on custom command (Examples needed)</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Help-on-custom-command-Examples-needed/m-p/86824#M22167</link>
      <description>&lt;P&gt;Custom command : 'addcustomfield.py'&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;import re,sys,time, splunk.Intersplunk

def doaddfield(results, settings):

  try:
    # get list of fields, and hash of arguments
    fields, argvals = splunk.Intersplunk.getKeywordsAndOptions()
    # set test message if "message" is not defined
    message         = argvals.get("message","Testing 123")

    # for each result, add fields set to message
    for r in results:
      for f in fields:
        r[f] = message

    # return the results
    splunk.Intersplunk.outputResults(results)

  except:
    import traceback
    stack =  traceback.format_exc()
    results = splunk.Intersplunk.generateErrorResults("Error : Traceback: " + str(stack))

results, dummyresults, settings = splunk.Intersplunk.getOrganizedResults()
results = doaddfield(results, settings)
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;commands.conf&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;[addcustomfield]
retainsevents = true
streaming = true
filename = addcustomfield.py
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;usage :&lt;/P&gt;

&lt;P&gt;... | addcustomfield myfield message="blah blah blah"&lt;/P&gt;</description>
      <pubDate>Mon, 08 Apr 2013 17:05:19 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Help-on-custom-command-Examples-needed/m-p/86824#M22167</guid>
      <dc:creator>jonuwz</dc:creator>
      <dc:date>2013-04-08T17:05:19Z</dc:date>
    </item>
    <item>
      <title>Re: Help on custom command (Examples needed)</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Help-on-custom-command-Examples-needed/m-p/86825#M22168</link>
      <description>&lt;P&gt;Hi,&lt;BR /&gt;
But what i wanted was " myfield message="blah" | addcustomfield " instead of "... | addcustomfield myfield message="blah" "&lt;/P&gt;</description>
      <pubDate>Tue, 09 Apr 2013 00:54:07 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Help-on-custom-command-Examples-needed/m-p/86825#M22168</guid>
      <dc:creator>sarahh</dc:creator>
      <dc:date>2013-04-09T00:54:07Z</dc:date>
    </item>
    <item>
      <title>Re: Help on custom command (Examples needed)</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Help-on-custom-command-Examples-needed/m-p/86826#M22169</link>
      <description>&lt;P&gt;You asked for an example where new fields are added to the existing result set. Thats exactly what the above does.&lt;/P&gt;

&lt;P&gt;The "..." Is a search I.e &lt;CODE&gt;sourcetype=syslog&lt;/CODE&gt; . then you can do &lt;CODE&gt;| addcustomfield myfield&lt;/CODE&gt; to add &lt;CODE&gt;myfiled&lt;/CODE&gt; to the list of fields.&lt;/P&gt;

&lt;P&gt;If you want to hard code these in the example above, change the default message, and hard code "f"&lt;/P&gt;</description>
      <pubDate>Tue, 09 Apr 2013 06:27:36 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Help-on-custom-command-Examples-needed/m-p/86826#M22169</guid>
      <dc:creator>jonuwz</dc:creator>
      <dc:date>2013-04-09T06:27:36Z</dc:date>
    </item>
  </channel>
</rss>

