<?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 Custom Search Command: Why is it showing up in configurations list, but not found from CLI? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Splunk-Custom-Search-Command-Why-is-it-showing-up-in/m-p/365590#M162939</link>
    <description>&lt;P&gt;I checked this, but it looks like no matter what case I use in the command line, the error message changes it to all lowercase. Did you notice any other mistakes in my method that might have caused this error?&lt;/P&gt;</description>
    <pubDate>Tue, 13 Feb 2018 14:15:31 GMT</pubDate>
    <dc:creator>tschn00</dc:creator>
    <dc:date>2018-02-13T14:15:31Z</dc:date>
    <item>
      <title>Splunk Custom Search Command: Why is it showing up in configurations list, but not found from CLI?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Splunk-Custom-Search-Command-Why-is-it-showing-up-in/m-p/365588#M162937</link>
      <description>&lt;P&gt;I have written a python script whose purpose is to add a line to a file every time the specified command is called in Splunk. I created the script and added the command to the local commands.conf file. &lt;/P&gt;

&lt;P&gt;When I go into my Splunk environment, I can see that this command is listed under the "Settings --&amp;gt; All Configurations"; However, when I try to run this command from the app, I get the following message: &lt;STRONG&gt;&lt;EM&gt;"Search Factory: Unknown search command 'printlog'."&lt;/EM&gt;&lt;/STRONG&gt;&lt;/P&gt;

&lt;P&gt;&lt;STRONG&gt;Python Script&lt;/STRONG&gt; (saved in \Splunk\etc\apps\search\bin)&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;import sys,splunk.Intersplunk
import datetime
results = []

try:
    results,dummyresults,settings = splunk.Intersplunk.getOrganizedResults()
    now = datetime.datetime.now()
    with open('C:/testfile.txt','a') as openfile:
        openfile.write(str(now)+'\n')
    openfile.close()

except:
    import traceback
    stack =  traceback.format_exc()
    results = splunk.Intersplunk.generateErrorResults("Error : Traceback: " + str(stack))

splunk.Intersplunk.outputResults( results )
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;&lt;STRONG&gt;Commands.conf edit&lt;/STRONG&gt; (saved in C:\Splunk\etc\apps\search\local) &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;[printLog]
filename = printLog.py
type = python
local = True
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 12 Feb 2018 21:26:54 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Splunk-Custom-Search-Command-Why-is-it-showing-up-in/m-p/365588#M162937</guid>
      <dc:creator>tschn00</dc:creator>
      <dc:date>2018-02-12T21:26:54Z</dc:date>
    </item>
    <item>
      <title>Re: Splunk Custom Search Command: Why is it showing up in configurations list, but not found from CLI?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Splunk-Custom-Search-Command-Why-is-it-showing-up-in/m-p/365589#M162938</link>
      <description>&lt;P&gt;You have &lt;CODE&gt;printLog&lt;/CODE&gt; in your commands.conf and &lt;CODE&gt;printlog&lt;/CODE&gt; in your error message (capital &lt;CODE&gt;L&lt;/CODE&gt; vs lowercase &lt;CODE&gt;l&lt;/CODE&gt;).  Is this perhaps a case of, well, case?  &lt;/P&gt;

&lt;P&gt;Adding to this answer after doing some testing.&lt;/P&gt;

&lt;P&gt;I ran into the same issue when trying to define your search command as &lt;CODE&gt;printLog&lt;/CODE&gt;, but it works when I make it &lt;CODE&gt;printlog&lt;/CODE&gt;, including in commands.conf:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;[printlog]
filename = printLog.py
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;I think search commands are actually case insensitive in the search bar, but they are all converted to lowercase to find the actual search command.  So if you &lt;CODE&gt;| WHERE&lt;/CODE&gt;, splunk looks for the search command &lt;CODE&gt;where&lt;/CODE&gt;.&lt;/P&gt;

&lt;P&gt;In addition to solving that issue, I strongly suggest you look at using the SDK for custom search commands instead of Intersplunk.  This is advised by Splunk for new search commands.  As a starting point, this snippet may accomplish what your script aims to do, but using the SDK:&lt;/P&gt;

&lt;P&gt;printLog.py:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;from splunklib.searchcommands import dispatch, EventingCommand, Configuration, Option
from splunklib.searchcommands.validators import Code

import sys 

@Configuration()
class PrintLogCommand(EventingCommand):
    def transform(self, records):
        now = datetime.datetime.now()
        with open('C:/testfile.txt','a') as openfile:
            openfile.write(str(now)+'\n')
        openfile.close()

        for record in records:
            yield record

dispatch(PrintLogCommand, sys.argv, sys.stdin, sys.stdout, __name__)
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;commands.conf:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;[printlog]
filename = printLog.py
chunked = true
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;You would also need to copy &lt;CODE&gt;splunklib&lt;/CODE&gt; from the python SDK into the &lt;CODE&gt;bin&lt;/CODE&gt; directory for this to work.&lt;/P&gt;</description>
      <pubDate>Tue, 13 Feb 2018 04:19:33 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Splunk-Custom-Search-Command-Why-is-it-showing-up-in/m-p/365589#M162938</guid>
      <dc:creator>micahkemp</dc:creator>
      <dc:date>2018-02-13T04:19:33Z</dc:date>
    </item>
    <item>
      <title>Re: Splunk Custom Search Command: Why is it showing up in configurations list, but not found from CLI?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Splunk-Custom-Search-Command-Why-is-it-showing-up-in/m-p/365590#M162939</link>
      <description>&lt;P&gt;I checked this, but it looks like no matter what case I use in the command line, the error message changes it to all lowercase. Did you notice any other mistakes in my method that might have caused this error?&lt;/P&gt;</description>
      <pubDate>Tue, 13 Feb 2018 14:15:31 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Splunk-Custom-Search-Command-Why-is-it-showing-up-in/m-p/365590#M162939</guid>
      <dc:creator>tschn00</dc:creator>
      <dc:date>2018-02-13T14:15:31Z</dc:date>
    </item>
    <item>
      <title>Re: Splunk Custom Search Command: Why is it showing up in configurations list, but not found from CLI?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Splunk-Custom-Search-Command-Why-is-it-showing-up-in/m-p/365591#M162940</link>
      <description>&lt;P&gt;Updated answer after testing.&lt;/P&gt;</description>
      <pubDate>Tue, 13 Feb 2018 15:16:00 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Splunk-Custom-Search-Command-Why-is-it-showing-up-in/m-p/365591#M162940</guid>
      <dc:creator>micahkemp</dc:creator>
      <dc:date>2018-02-13T15:16:00Z</dc:date>
    </item>
    <item>
      <title>Re: Splunk Custom Search Command: Why is it showing up in configurations list, but not found from CLI?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Splunk-Custom-Search-Command-Why-is-it-showing-up-in/m-p/365592#M162941</link>
      <description>&lt;P&gt;Thank you so much. I experienced a different error once I fixed the first, but by using the python SDK method you suggested, it worked perfectly!&lt;/P&gt;</description>
      <pubDate>Tue, 13 Feb 2018 18:59:58 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Splunk-Custom-Search-Command-Why-is-it-showing-up-in/m-p/365592#M162941</guid>
      <dc:creator>tschn00</dc:creator>
      <dc:date>2018-02-13T18:59:58Z</dc:date>
    </item>
  </channel>
</rss>

