<?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 search command -&amp;gt; help in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Custom-search-command-gt-help/m-p/39150#M8917</link>
    <description>&lt;P&gt;Here are the steps for taking your python script and creating a splunk search command.&lt;/P&gt;

&lt;P&gt;&lt;A href="http://docs.splunk.com/Documentation/Splunk/latest/developer/searchscripts"&gt;http://docs.splunk.com/Documentation/Splunk/latest/developer/searchscripts&lt;/A&gt;&lt;/P&gt;

&lt;P&gt;Some examples referenced here for you to look at as well:&lt;/P&gt;

&lt;P&gt;&lt;A href="http://blogs.splunk.com/2011/11/30/using-custom-search-commands-with-splunk-python-sdk/"&gt;http://blogs.splunk.com/2011/11/30/using-custom-search-commands-with-splunk-python-sdk/&lt;/A&gt;&lt;/P&gt;</description>
    <pubDate>Sat, 28 Apr 2012 11:22:18 GMT</pubDate>
    <dc:creator>sdaniels</dc:creator>
    <dc:date>2012-04-28T11:22:18Z</dc:date>
    <item>
      <title>Custom search command -&gt; help</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Custom-search-command-gt-help/m-p/39149#M8916</link>
      <description>&lt;P&gt;I have the phyton script presented in note 1. How Can I modify this script so it can be called as a splunk search command?&lt;/P&gt;

&lt;P&gt;Note 1: uat_qe_feed.py&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;import urllib2, sys,csv
from lxml import etree
from time import strftime as date

host = ['host1.com','host2.com']

for s in host:

        url = "http://" + s + ":8080/rex/administration?files_used=true"

        try:

                f = urllib2.urlopen(url)
                doc = etree.XML(f.read())
                r = doc.xpath("//str[@name]")


                print(date('%Y-%m-%d %H:%M:%S') + "   " + "qe_host=" + s +  "   " + "Stack=uat" + "   " +  "LOCATION="+ r[1].text + "   " +  "NUMBER="+ r[2].text + "   " + "MAP="+ r[3].text + "   " +  "SET="+ r[4].text)


                f.close()

         except urllib2.URLError, e:

                print(date('%Y-%m-%d %H:%M:%S') + "   " + "qe_host=" + s + "   " + "Stack=uat" + "   " + "Status=QE_Not_in_Service" )
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 28 Sep 2020 11:45:10 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Custom-search-command-gt-help/m-p/39149#M8916</guid>
      <dc:creator>lpolo</dc:creator>
      <dc:date>2020-09-28T11:45:10Z</dc:date>
    </item>
    <item>
      <title>Re: Custom search command -&gt; help</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Custom-search-command-gt-help/m-p/39150#M8917</link>
      <description>&lt;P&gt;Here are the steps for taking your python script and creating a splunk search command.&lt;/P&gt;

&lt;P&gt;&lt;A href="http://docs.splunk.com/Documentation/Splunk/latest/developer/searchscripts"&gt;http://docs.splunk.com/Documentation/Splunk/latest/developer/searchscripts&lt;/A&gt;&lt;/P&gt;

&lt;P&gt;Some examples referenced here for you to look at as well:&lt;/P&gt;

&lt;P&gt;&lt;A href="http://blogs.splunk.com/2011/11/30/using-custom-search-commands-with-splunk-python-sdk/"&gt;http://blogs.splunk.com/2011/11/30/using-custom-search-commands-with-splunk-python-sdk/&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Sat, 28 Apr 2012 11:22:18 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Custom-search-command-gt-help/m-p/39150#M8917</guid>
      <dc:creator>sdaniels</dc:creator>
      <dc:date>2012-04-28T11:22:18Z</dc:date>
    </item>
    <item>
      <title>Re: Custom search command -&gt; help</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Custom-search-command-gt-help/m-p/39151#M8918</link>
      <description>&lt;P&gt;i knew about the links and I was not able to make it work. I just need a single example from the code I presented to have a start up..&lt;/P&gt;</description>
      <pubDate>Sat, 28 Apr 2012 12:24:12 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Custom-search-command-gt-help/m-p/39151#M8918</guid>
      <dc:creator>lpolo</dc:creator>
      <dc:date>2012-04-28T12:24:12Z</dc:date>
    </item>
    <item>
      <title>Re: Custom search command -&gt; help</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Custom-search-command-gt-help/m-p/39152#M8919</link>
      <description>&lt;P&gt;What are you trying to accomplish with your custom search command?  That may help us get you what you need.&lt;/P&gt;</description>
      <pubDate>Sat, 28 Apr 2012 12:35:48 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Custom-search-command-gt-help/m-p/39152#M8919</guid>
      <dc:creator>sdaniels</dc:creator>
      <dc:date>2012-04-28T12:35:48Z</dc:date>
    </item>
    <item>
      <title>Re: Custom search command -&gt; help</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Custom-search-command-gt-help/m-p/39153#M8920</link>
      <description>&lt;P&gt;Get the result set of an xml file. I have the script I presented in the initial post. I am able to print the results. I need to get these results from splunk by executing the script as a custom search. For example:&lt;/P&gt;

&lt;P&gt;|uat_qe_feed&lt;/P&gt;

&lt;P&gt;The result of this search command is the result of the last line of my phyton script:&lt;/P&gt;

&lt;P&gt;print(date('%Y-%m-%d %H:%M:%S') + "   " + "qe_host=" + s +  "   " + "Stack=uat" + "   " +  "LOCATION="+ r[1].text + "   " +  "NUMBER="+ r[2].text + "   " + "MAP="+ r[3].text + "   " +  "SET="+ r[4].text)&lt;/P&gt;

&lt;P&gt;What should I add in my code so this script can be called as a search command&lt;/P&gt;</description>
      <pubDate>Mon, 28 Sep 2020 11:45:12 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Custom-search-command-gt-help/m-p/39153#M8920</guid>
      <dc:creator>lpolo</dc:creator>
      <dc:date>2020-09-28T11:45:12Z</dc:date>
    </item>
    <item>
      <title>Re: Custom search command -&gt; help</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Custom-search-command-gt-help/m-p/39154#M8921</link>
      <description>&lt;P&gt;I am getting the result set from a REST API call as shown in the script I presented. I am not indexing the result set. &lt;BR /&gt;
I just need to know from this script example, how to converted to a custom search command.&lt;/P&gt;</description>
      <pubDate>Sat, 28 Apr 2012 17:19:55 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Custom-search-command-gt-help/m-p/39154#M8921</guid>
      <dc:creator>lpolo</dc:creator>
      <dc:date>2012-04-28T17:19:55Z</dc:date>
    </item>
    <item>
      <title>Re: Custom search command -&gt; help</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Custom-search-command-gt-help/m-p/39155#M8922</link>
      <description>&lt;P&gt;if you're looking for examples, several of the shipped Splunk search commands are in fact Python scripts. Look in &lt;CODE&gt;$SPLUNK_HOME/etc/apps/search/bin&lt;/CODE&gt; and &lt;CODE&gt;$SPLUNK_HOME/etc/apps/search/default/commands.conf&lt;/CODE&gt;.&lt;/P&gt;</description>
      <pubDate>Sun, 29 Apr 2012 18:32:40 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Custom-search-command-gt-help/m-p/39155#M8922</guid>
      <dc:creator>gkanapathy</dc:creator>
      <dc:date>2012-04-29T18:32:40Z</dc:date>
    </item>
    <item>
      <title>Re: Custom search command -&gt; help</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Custom-search-command-gt-help/m-p/39156#M8923</link>
      <description>&lt;P&gt;I suspect you are fundamentally misunderstanding what a search command is good for. You appear to be trying to feed raw data into Splunk. Normally you would do this via a scripted input or simply a file, and index the data. But since a custom search command can run arbitrary code, it's expected that it outputs CSV field data. You can certainly just pass in raw text by putting it into a &lt;CODE&gt;_raw&lt;/CODE&gt; CSV field, but it would make more sense if you also, at minimum, included &lt;CODE&gt;_time&lt;/CODE&gt; in epoch time, as well as the other fields you already have available in Python. By putting it back into raw text line, it's wasteful, as you're simply forcing Splunk to re-parse fields that you've already parsed out.&lt;/P&gt;</description>
      <pubDate>Sun, 29 Apr 2012 18:41:23 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Custom-search-command-gt-help/m-p/39156#M8923</guid>
      <dc:creator>gkanapathy</dc:creator>
      <dc:date>2012-04-29T18:41:23Z</dc:date>
    </item>
    <item>
      <title>Re: Custom search command -&gt; help</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Custom-search-command-gt-help/m-p/39157#M8924</link>
      <description>&lt;P&gt;Thanks.&lt;/P&gt;

&lt;P&gt;Solved by using as example:&lt;/P&gt;

&lt;P&gt;/opt/splunk/etc/apps/search/bin/google.py&lt;/P&gt;</description>
      <pubDate>Mon, 30 Apr 2012 11:49:37 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Custom-search-command-gt-help/m-p/39157#M8924</guid>
      <dc:creator>lpolo</dc:creator>
      <dc:date>2012-04-30T11:49:37Z</dc:date>
    </item>
    <item>
      <title>Re: Custom search command -&gt; help</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Custom-search-command-gt-help/m-p/39158#M8925</link>
      <description>&lt;P&gt;&lt;A href="http://splunk-base.splunk.com/answers/7909/where-is-the-python-api-for-splunkintersplunk"&gt;http://splunk-base.splunk.com/answers/7909/where-is-the-python-api-for-splunkintersplunk&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 30 Apr 2012 14:29:44 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Custom-search-command-gt-help/m-p/39158#M8925</guid>
      <dc:creator>lpolo</dc:creator>
      <dc:date>2012-04-30T14:29:44Z</dc:date>
    </item>
    <item>
      <title>Re: Custom search command -&gt; help</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Custom-search-command-gt-help/m-p/39159#M8926</link>
      <description>&lt;P&gt;Script example customsearch.py:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;import urllib2, sys,csv,time
from lxml import etree
import splunk.Intersplunk as si

host = ['host1.net','host2.net']
for s in host:

        url = "http://" + s + ":8080/rex/administration?files_used=true"
        #print(url)
        results = []
        now = str(int(time.mktime(time.gmtime())))

        try:
                f = urllib2.urlopen(url)
                doc = etree.XML(f.read())


                one =  doc.xpath("//str[@name='LINEUP']/text()")
                two  = doc.xpath("//str[@name='LINEAR']/text()")
                three  = doc.xpath("//str[@name='BITSET']/text()")

                results.append({'_time' : now,'qe_host' : s,'Stack' : 'cim','Status' : 'up','LINEUP' : one,'LINEAR' :  two,'BITSET' :  three})

                si.outputResults(results)



        except urllib2.URLError, e:
                results.append({'_time' : 'now','qe_host' : s,'Stack' : 'cim','Status' : 'down','LINEUP' : '','LINEAR' :  '','BITSET' :  ''})
                si.outputResults(results)

        f.close()
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;commands.conf&lt;BR /&gt;
    [customsearch]&lt;BR /&gt;
    filename = customsearch.py&lt;BR /&gt;
    generating = true&lt;BR /&gt;
    maxinputs = 1&lt;/P&gt;</description>
      <pubDate>Tue, 01 May 2012 13:41:45 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Custom-search-command-gt-help/m-p/39159#M8926</guid>
      <dc:creator>lpolo</dc:creator>
      <dc:date>2012-05-01T13:41:45Z</dc:date>
    </item>
  </channel>
</rss>

