Getting error while running custom command on Splunk windows build having python 3.7
The custom command is throwing (which uses splunklib) following error on Splunk installed on Windows machine (having python 3 build)
Error in 'script': Getinfo probe failed for external search command 'ldapsearch'.
Details splunklib version: 1.6.6 platform: Windows framework version: Python 3.7.2 Splunk version: splunk-8.0.0-86b1693e81bb-windows-64
The same command is working properly on the following builds
- Splunk Linux build 8.0.0 (Py2)
- Splunk Linux build PY3 8.0.0 (Py3)
- Splunk Windows build 8.0.0 (Py2)
Code Snippet
from future import absolute_import, division, print_function, unicode_literals import default
from splunklib.searchcommands import dispatch, GeneratingCommand, Configuration, Option, validators import datetime from splunklib.six.moves import map from splunklib.six import iteritems, b, binary_type
@Configuration(retainsevents=True) class LdapSearchCommand(GeneratingCommand): """ Retrieves results from the specified search in a configured domain and generates events.
This command must be placed at the beginning of a search pipeline:
.. code-block:: text
| ldapsearch domain=splunk.com search="(objectCategory=User)" attrs="distinguishedName"
"""
search = Option(
doc=''' Specifies an RFC 2254 compliant search string.
''',
require=True)
domain = Option(
doc=''' Specifies the LDAP or Active Directory domain directory to search.
''',
default='default')
def generate(self):
try:
# Some code for generating events
except Exception as error:
self.error_exit(error, message)
return
dispatch(LdapSearchCommand, module_name=name)
Adding search.log from job inspect
08-09-2019 15:21:40.378 INFO SearchParser - PARSING: |ldapsearch debug=true search="(sAMAccountName=)"|fields * 08-09-2019 15:21:40.380 INFO dispatchRunner - SearchHeadInitSearchMs=15 08-09-2019 15:21:40.380 INFO SearchParser - PARSING: |ldapsearch debug=true search="(sAMAccountName=)"|fields * 08-09-2019 15:21:40.381 INFO SearchParser - PARSING: |ldapsearch debug=true search="(sAMAccountName=)"|fields * 08-09-2019 15:21:40.381 INFO dispatchRunner - Executing the Search orchestrator and iterator model (dfs=0). 08-09-2019 15:21:40.381 INFO SearchOrchestrator - SearchOrchestrator getting constructed 08-09-2019 15:21:40.381 INFO SearchOrchestrator - Initialized the SRI 08-09-2019 15:21:40.391 INFO ISplunkDispatch - Not running in splunkd. Bundle replication not triggered. 08-09-2019 15:21:40.391 INFO SearchOrchestrator - Initialzing the run time settings for the orchestrator. 08-09-2019 15:21:40.392 INFO UserManager - Setting user context: admin 08-09-2019 15:21:40.392 INFO UserManager - Done setting user context: NULL -> admin 08-09-2019 15:21:40.401 INFO SearchOrchestrator - Creating the search DAG. 08-09-2019 15:21:40.401 INFO SearchParser - PARSING: |ldapsearch debug=true search="(sAMAccountName=)"|fields * 08-09-2019 15:21:40.426 INFO script - found script file=C:\Program Files\Splunk\etc\apps\SA-ldapsearch\bin\ldapsearch.py 08-09-2019 15:21:40.426 INFO script - stderr for script ldapsearch will be added to search.log 08-09-2019 15:21:41.948 WARN SearchResultsCSVSerializer - CSV file contains invalid field '', ignoring column. 08-09-2019 15:21:42.027 ERROR script - Getinfo probe failed for external search command 'ldapsearch'. 08-09-2019 15:21:42.030 INFO SearchParser - PARSING: |ldapsearch debug=true search="(sAMAccountName=)"|fields * 08-09-2019 15:21:42.030 INFO script - found script file=C:\Program Files\Splunk\etc\apps\SA-ldapsearch\bin\ldapsearch.py 08-09-2019 15:21:42.031 INFO script - stderr for script ldapsearch will be added to search.log 08-09-2019 15:21:43.553 WARN SearchResultsCSVSerializer - CSV file contains invalid field '', ignoring column. 08-09-2019 15:21:43.553 ERROR script - Getinfo probe failed for external search command 'ldapsearch'. 08-09-2019 15:21:43.553 INFO ScopedTimer - search.optimize 1.531 08-09-2019 15:21:43.553 INFO SearchPhaseGenerator - Failed to create phases using AST:Error in 'script': Getinfo probe failed for external search command 'ldapsearch'.. Falling back to 2 phase mode. 08-09-2019 15:21:43.553 INFO SearchPhaseGenerator - Executing two phase fallback for the search=|ldapsearch debug=true search="(sAMAccountName=)"|fields * 08-09-2019 15:21:43.553 INFO SearchParser - PARSING: |ldapsearch debug=true search="(sAMAccountName=*)"|fields * 08-09-2019 15:21:43.554 INFO script - found script file=C:\Program Files\Splunk\etc\apps\SA-ldapsearch\bin\ldapsearch.py 08-09-2019 15:21:43.554 INFO script - stderr for script ldapsearch will be added to search.log 08-09-2019 15:21:45.074 WARN SearchResultsCSVSerializer - CSV file contains invalid field '', ignoring column. 08-09-2019 15:21:45.074 ERROR script - Getinfo probe failed for external search command 'ldapsearch'. 08-09-2019 15:21:45.074 ERROR SearchPhaseGenerator - Fallback to two phase search failed:Error in 'script': Getinfo probe failed for external search command 'ldapsearch'. 08-09-2019 15:21:45.097 ERROR SearchOrchestrator - Error in 'script': Getinfo probe failed for external search command 'ldapsearch'. 08-09-2019 15:21:45.097 ERROR SearchStatusEnforcer - sid:1565344299.8 Error in 'script': Getinfo probe failed for external search command 'ldapsearch'. 08-09-2019 15:21:45.257 ERROR dispatchRunner - RunDispatch::runDispatchThread threw error: Error in 'script': Getinfo probe failed for external search command 'ldapsearch
Hi @bj8798 , I'm able to run search commands successfully after a few changes in the code. Please try with below mentioned code and check if it is working for you or not. If you are still facing this issue then please do let us know and also share the event generating code, it'll help us.
commands.conf file:
[generatingcsc]
filename = LdapSearchCommand.py
type = python
chunked = true
LdapSearchCommand.py file:
import sys
from splunklib.searchcommands import dispatch, GeneratingCommand, Configuration, Option, validators
import datetime, time
from splunklib.six.moves import map
from splunklib.six import iteritems, b, binary_type
@Configuration(retainsevents=True)
class LdapSearchCommand(GeneratingCommand):
""" Retrieves results from the specified search in a configured domain and generates events.
This command must be placed at the beginning of a search pipeline:
.. code-block:: text
| ldapsearch domain=splunk.com search="(objectCategory=User)" attrs="distinguishedName"
"""
search = Option(
doc=''' Specifies an RFC 2254 compliant search string.
''',
require=True)
domain = Option(
doc=''' Specifies the LDAP or Active Directory domain directory to search.
''',
default='default')
def generate(self):
try:
yield {'_time':time.time(), 'count':1}
yield {'_time':time.time(), 'count':2}
yield {'_time':time.time(), 'count':3}
yield {'_time':time.time(), 'count':4}
except Exception as error:
self.error_exit(error, "message")
return
dispatch(LdapSearchCommand, sys.argv, sys.stdin, sys.stdout, __name__)
Hi @bj8798 Closing this issue due to no response on it. Please try the solution provided and reopen if this is still an issue .