<?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: getinfo probe failed for external search command - a rights issue in Security</title>
    <link>https://community.splunk.com/t5/Security/getinfo-probe-failed-for-external-search-command-a-rights-issue/m-p/151197#M4608</link>
    <description>&lt;H2&gt;Short Solution&lt;/H2&gt;

&lt;P&gt;The SDK that I had previously downloaded and installed was missing &lt;CODE&gt;__init__.py&lt;/CODE&gt; and few other root python files in the &lt;EM&gt;splunklib&lt;/EM&gt; folder. Once I downloaded a NEW version of the python SDK and replaced the splunklib directory (and its recursive files/directories) I was able to restart Splunk as the splunk user and it worked. &lt;/P&gt;

&lt;H2&gt;Long Answer&lt;/H2&gt;

&lt;P&gt;I modified the &lt;CODE&gt;gmeans.py&lt;/CODE&gt; python file a bit; streamlined the code and added exception errors. This allowed the search.log to properly report that it was not finding the splunklib.searchcommands .&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;06-22-2015 10:27:46.297 ERROR ScriptRunner - stderr from '/opt/splunk/bin/python /opt/splunk/etc/apps/&amp;lt;appname&amp;gt;/bin/gmeans.py __GETINFO__ nums=scores field=score': ImportError: No module named splunklib.searchcommands
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Once I added the missing &lt;CODE&gt;__init__.py&lt;/CODE&gt; to &lt;EM&gt;../splunklib/&lt;/EM&gt; &lt;CODE&gt;search.log&lt;/CODE&gt; then started reporting on the missing *.py files like client, binding, data ..etc.&lt;/P&gt;

&lt;H2&gt;Updated gmeans.py&lt;/H2&gt;

&lt;PRE&gt;&lt;CODE&gt;import sys
from splunklib.searchcommands import \
    dispatch, StreamingCommand, Configuration, Option, validators

# Geometric Mean Calculator
def geomean(nums):
    """
        Return the geometric average of nums
        @param    list    nums    List of nums to avg
        @return   float   Geometric avg of nums
    """
    numbers = []
    for n in nums:
        if not isinstance(n, float):
            n = float(n)
            numbers.append(n)
        else:
            numbers.append(n)
    product = 1
    for n in numbers:
        if n &amp;lt; 0.25:
            n = 0.04
        product *= n
    return round(product ** (1.0 / len(numbers)), 2)

@Configuration()
class gmeansCommand(StreamingCommand):
    """ Computes the geometric mean of a list of numbers.
        | stats list(&amp;lt;field with non zero numbers&amp;gt;) | gmeans nums=&amp;lt;number list&amp;gt; field=&amp;lt;name&amp;gt;
    """

    # Options
    field = Option(name='field', require=True)
    nums = Option(name='nums', require=True)
    show_error = Option(name='show_error', require=False, default=False, validate=validators.Boolean())

    def stream(self, events):

        for event in events:
            try:
                event[self.field] = geomean(str(event[self.nums]).split())
            except Exception, e:
                if not self.show_error :
                    raise e            
            yield event

dispatch(gmeansCommand, sys.argv, sys.stdin, sys.stdout, __name__)
&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Mon, 22 Jun 2015 16:14:36 GMT</pubDate>
    <dc:creator>jhubbard74</dc:creator>
    <dc:date>2015-06-22T16:14:36Z</dc:date>
    <item>
      <title>getinfo probe failed for external search command - a rights issue</title>
      <link>https://community.splunk.com/t5/Security/getinfo-probe-failed-for-external-search-command-a-rights-issue/m-p/151196#M4607</link>
      <description>&lt;H2&gt;Issue&lt;/H2&gt;

&lt;P&gt;Splunk custom command will not work unless Splunkd is started by the root user.&lt;/P&gt;

&lt;P&gt;If 'getinfo' is the culprit; is it due to rights/perms? and if so what rights do i need to modify on which files/directories to make it work with the splunk user?&lt;/P&gt;

&lt;H2&gt;Background&lt;/H2&gt;

&lt;UL&gt;
&lt;LI&gt;Custom command is a python built command to calculate geometric means.&lt;/LI&gt;
&lt;LI&gt;It uses splunklib.searchcommands and imports &lt;EM&gt;dispatch, StreamingCommand, Configuration, Option, validators&lt;/EM&gt;.&lt;/LI&gt;
&lt;LI&gt;paths '&lt;EM&gt;/opt/splunk/etc/apps/&amp;lt;appname&amp;gt;/bin/gmeans.py&lt;/EM&gt;' and '&lt;EM&gt;/opt/splunk/etc/apps/&amp;lt;appname&amp;gt;/bin/splunklib/searchcommands/&lt;/EM&gt;.py*'&lt;/LI&gt;
&lt;LI&gt;Splunk runs as user: splunk. The splunk user:group also has (775) permissions across directories and files to the gmeans.py and splunklib.&lt;/LI&gt;
&lt;LI&gt;gmeans command in Splunk is configured as "Everyone --&amp;gt; read - write" permissions&lt;/LI&gt;
&lt;LI&gt;have run the following command: &lt;EM&gt;chown -R splunk:splunk /opt/splunk&lt;/EM&gt; &lt;/LI&gt;
&lt;LI&gt;Splunk version 6.2.0&lt;/LI&gt;
&lt;/UL&gt;

&lt;H2&gt;Problem&lt;/H2&gt;

&lt;P&gt;If Splunk is started as sudo root, then gmeans.py works perfectly. &lt;BR /&gt;
If Splunk is started as splunk, then gmeans fails with getinfo error.&lt;/P&gt;

&lt;H2&gt;commands.conf&lt;/H2&gt;

&lt;PRE&gt;&lt;CODE&gt;[gmeans]
filename = gmeans.py
supports_getinfo = true
supports_rawargs = true
outputheader = true
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;H2&gt;btool command gmeans&lt;/H2&gt;

&lt;PRE&gt;&lt;CODE&gt;splunk btool --debug commands list gmeans
/opt/splunk/etc/apps/&amp;lt;appname&amp;gt;/default/commands.conf [gmeans]
/opt/splunk/etc/system/default/commands.conf         changes_colorder = true
/opt/splunk/etc/system/default/commands.conf         enableheader = true
/opt/splunk/etc/apps/&amp;lt;appname&amp;gt;/default/commands.conf filename = gmeans.py
/opt/splunk/etc/system/default/commands.conf         generates_timeorder = false
/opt/splunk/etc/system/default/commands.conf         generating = false
/opt/splunk/etc/system/default/commands.conf         maxinputs = 50000
/opt/splunk/etc/system/default/commands.conf         outputheader = false
/opt/splunk/etc/system/default/commands.conf         passauth = false
/opt/splunk/etc/system/default/commands.conf         perf_warn_limit = 0
/opt/splunk/etc/system/default/commands.conf         required_fields = *
/opt/splunk/etc/system/default/commands.conf         requires_preop = false
/opt/splunk/etc/system/default/commands.conf         retainsevents = false
/opt/splunk/etc/system/default/commands.conf         streaming = false
/opt/splunk/etc/apps/&amp;lt;appname&amp;gt;/default/commands.conf supports_getinfo = true
/opt/splunk/etc/apps/&amp;lt;appname&amp;gt;/default/commands.conf supports_rawargs = true
/opt/splunk/etc/system/default/commands.conf         type = python
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;HR /&gt;

&lt;H2&gt;Update 6-17-2015&lt;/H2&gt;

&lt;P&gt;I installed a Brand New Splunk instance (6.2.3) installed as splunk user. I followed every piece of online documentation for creating custom streaming commands. The custom command is now in its own app. The splunklib library is located in &lt;EM&gt;$SPLUNK_HOME/etc/apps/(app_name)/bin/&lt;/EM&gt;. The bin directory also holds the python script. &lt;/P&gt;

&lt;P&gt;The attribute getinfo will not work. If I set &lt;EM&gt;supports_getinfo=0&lt;/EM&gt; the command acts like it runs, but will not return results. If I enable &lt;EM&gt;supports_getinfo&lt;/EM&gt;, it returns the error. Debugging the script tells me nothing more than the error on screen.&lt;/P&gt;

&lt;H2&gt;gmeans.py&lt;/H2&gt;

&lt;PRE&gt;&lt;CODE&gt;#!/usr/bin/env python

import sys
from splunklib.searchcommands import dispatch, StreamingCommand, Configuration, Option, validators


# Geometric Mean Calculator
def geomean(nums):
    numbers = []
    for n in nums:
        if not isinstance(n, float):
            n = float(n)
            numbers.append(n)
        else:
            numbers.append(n)
    product = 1
    for n in numbers:
        # Prevent 0; numbers[n] should never be a 0. 
        if n &amp;lt; 0.25:
            n = 0.04
        product *= n
    return round(product ** (1.0 / len(numbers)), 2)


@Configuration()
class gmeansCommand(StreamingCommand):
    # Options
    fieldname = Option(
        doc=''' **Syntax:** **fieldname=***&amp;lt;fieldname&amp;gt;*
        **Description:** REQUIRED: Name of the field to hold the calcluted mean for the geometric average''',
        require=True, validate=validators.Fieldname())
    nums = Option(
        doc=''' **Syntax:** **nums=***&amp;lt;fieldname&amp;gt;*
        **Description:** REQUIRED: Name of the field that contains the list if numbers to be calculated''',
        require=True, validate=validators.Fieldname())

    def stream(self, events):
        for event in events:
            nums = []
            for n in event[self.nums].split():
                nums.append(float(n))
            event[self.fieldname] = geomean(nums)
            yield record


dispatch(gmeansCommand, sys.argv, sys.stdin, sys.stdout, __name__)
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 28 Sep 2020 20:14:27 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Security/getinfo-probe-failed-for-external-search-command-a-rights-issue/m-p/151196#M4607</guid>
      <dc:creator>jhubbard74</dc:creator>
      <dc:date>2020-09-28T20:14:27Z</dc:date>
    </item>
    <item>
      <title>Re: getinfo probe failed for external search command - a rights issue</title>
      <link>https://community.splunk.com/t5/Security/getinfo-probe-failed-for-external-search-command-a-rights-issue/m-p/151197#M4608</link>
      <description>&lt;H2&gt;Short Solution&lt;/H2&gt;

&lt;P&gt;The SDK that I had previously downloaded and installed was missing &lt;CODE&gt;__init__.py&lt;/CODE&gt; and few other root python files in the &lt;EM&gt;splunklib&lt;/EM&gt; folder. Once I downloaded a NEW version of the python SDK and replaced the splunklib directory (and its recursive files/directories) I was able to restart Splunk as the splunk user and it worked. &lt;/P&gt;

&lt;H2&gt;Long Answer&lt;/H2&gt;

&lt;P&gt;I modified the &lt;CODE&gt;gmeans.py&lt;/CODE&gt; python file a bit; streamlined the code and added exception errors. This allowed the search.log to properly report that it was not finding the splunklib.searchcommands .&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;06-22-2015 10:27:46.297 ERROR ScriptRunner - stderr from '/opt/splunk/bin/python /opt/splunk/etc/apps/&amp;lt;appname&amp;gt;/bin/gmeans.py __GETINFO__ nums=scores field=score': ImportError: No module named splunklib.searchcommands
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Once I added the missing &lt;CODE&gt;__init__.py&lt;/CODE&gt; to &lt;EM&gt;../splunklib/&lt;/EM&gt; &lt;CODE&gt;search.log&lt;/CODE&gt; then started reporting on the missing *.py files like client, binding, data ..etc.&lt;/P&gt;

&lt;H2&gt;Updated gmeans.py&lt;/H2&gt;

&lt;PRE&gt;&lt;CODE&gt;import sys
from splunklib.searchcommands import \
    dispatch, StreamingCommand, Configuration, Option, validators

# Geometric Mean Calculator
def geomean(nums):
    """
        Return the geometric average of nums
        @param    list    nums    List of nums to avg
        @return   float   Geometric avg of nums
    """
    numbers = []
    for n in nums:
        if not isinstance(n, float):
            n = float(n)
            numbers.append(n)
        else:
            numbers.append(n)
    product = 1
    for n in numbers:
        if n &amp;lt; 0.25:
            n = 0.04
        product *= n
    return round(product ** (1.0 / len(numbers)), 2)

@Configuration()
class gmeansCommand(StreamingCommand):
    """ Computes the geometric mean of a list of numbers.
        | stats list(&amp;lt;field with non zero numbers&amp;gt;) | gmeans nums=&amp;lt;number list&amp;gt; field=&amp;lt;name&amp;gt;
    """

    # Options
    field = Option(name='field', require=True)
    nums = Option(name='nums', require=True)
    show_error = Option(name='show_error', require=False, default=False, validate=validators.Boolean())

    def stream(self, events):

        for event in events:
            try:
                event[self.field] = geomean(str(event[self.nums]).split())
            except Exception, e:
                if not self.show_error :
                    raise e            
            yield event

dispatch(gmeansCommand, sys.argv, sys.stdin, sys.stdout, __name__)
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 22 Jun 2015 16:14:36 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Security/getinfo-probe-failed-for-external-search-command-a-rights-issue/m-p/151197#M4608</guid>
      <dc:creator>jhubbard74</dc:creator>
      <dc:date>2015-06-22T16:14:36Z</dc:date>
    </item>
    <item>
      <title>Re: getinfo probe failed for external search command - a rights issue</title>
      <link>https://community.splunk.com/t5/Security/getinfo-probe-failed-for-external-search-command-a-rights-issue/m-p/151198#M4609</link>
      <description>&lt;P&gt;Hey, I had this same problem and it turned out that following the steps exactly as laid out online didn't work. It's not that the copy of the SDK didn't have &lt;CODE&gt;__init__.py&lt;/CODE&gt;, it's that the instructions don't have you copy it.&lt;/P&gt;

&lt;P&gt;When you copy &lt;CODE&gt;splunklib/searchcommands&lt;/CODE&gt; into your app's &lt;CODE&gt;bin&lt;/CODE&gt; directory &lt;A href="http://dev.splunk.com/view/python-sdk/SP-CAAAEU2"&gt;per instructions&lt;/A&gt; (section "Custom Search Command Example") that causes the &lt;CODE&gt;ImportError&lt;/CODE&gt; since there's no &lt;CODE&gt;__init__.py&lt;/CODE&gt; copied over, that &lt;CODE&gt;__init__.py&lt;/CODE&gt; you need is in &lt;CODE&gt;splunklib&lt;/CODE&gt;. Therefore a more correct instruction instead of &lt;EM&gt;"create splunklib dir in bin/ and copy searchcommands recursively into new splunklib dir"&lt;/EM&gt; would be &lt;EM&gt;"copy splunklib directory recursively into app's bin directory"&lt;/EM&gt;. That will eliminate the &lt;CODE&gt;ImportError&lt;/CODE&gt; I was seeing which I think is the same as yours.&lt;/P&gt;

&lt;P&gt;Sorry to resurrect a zombie but yours is the only good description and troubleshooting effort I've seen and I wanted to share for posterity. I've also submitted a correction to Splunk for the documentation I linked, which is what I think we both were following.&lt;/P&gt;</description>
      <pubDate>Wed, 28 Oct 2015 17:15:43 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Security/getinfo-probe-failed-for-external-search-command-a-rights-issue/m-p/151198#M4609</guid>
      <dc:creator>mikemishou</dc:creator>
      <dc:date>2015-10-28T17:15:43Z</dc:date>
    </item>
    <item>
      <title>Re: getinfo probe failed for external search command - a rights issue</title>
      <link>https://community.splunk.com/t5/Security/getinfo-probe-failed-for-external-search-command-a-rights-issue/m-p/151199#M4610</link>
      <description>&lt;P&gt;upvoting @jhubbard74 answer and @mikemishou comment because you folks did a lot of work and told us what we need to know.  &lt;/P&gt;</description>
      <pubDate>Fri, 09 Jun 2017 20:09:04 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Security/getinfo-probe-failed-for-external-search-command-a-rights-issue/m-p/151199#M4610</guid>
      <dc:creator>DalJeanis</dc:creator>
      <dc:date>2017-06-09T20:09:04Z</dc:date>
    </item>
  </channel>
</rss>

