Splunk Dev

How should I configure a custom python generating search command to use the events pipeline?

cnestrud
Explorer

I am trying to create a custom python generating search command which will be used with the events pipeline. It should generate events on the search head and should not distributed to indexers.

I am using splunk-sdk-python version 1.6.2 and Splunk version 6.5.1.

In commands.conf:

[abc]
filename = abc.py
chunked = true

In abc.py:

#!/usr/bin/env python

from __future__ import absolute_import, division, print_function, unicode_literals
from splunklib.searchcommands import dispatch, GeneratingCommand, Configuration, Option, validators
import sys
import time

@Configuration(type = 'eventing')
class AbcCommand(GeneratingCommand):
    [...]
    def generate(self):
        [...]
                yield event
        self.finish()

dispatch(AbcCommand, sys.argv, sys.stdin, sys.stdout, __name__)

From the search log:

02-01-2017 12:26:54.489 INFO  ChunkedExternProcessor - Running process: /opt/splunk/bin/python /opt/splunk/etc/apps/myapp/bin/abc.py
02-01-2017 12:26:54.615 INFO  ChunkedExternProcessor - Custom search command is a generating command.
02-01-2017 12:26:54.615 ERROR ChunkedExternProcessor - Invalid custom search command type: eventing
02-01-2017 12:26:54.716 ERROR ChunkedExternProcessor - Failure reading getinfo chunk

How should I configure this command so that it uses the events pipeline?

1 Solution

cnestrud
Explorer

I was able to get this to work by changing the decorator to:

@Configuration(type='events')

And also modifying our local copy of the Splunk Python SDK to allow ‘events’ as a valid option:

diff --git a/splunklib/searchcommands/internals.py b/splunklib/searchcommands/internals.py
index be57703..23989ad 100644
--- a/splunklib/searchcommands/internals.py
+++ b/splunklib/searchcommands/internals.py
@@ -326,7 +326,7 @@ class ConfigurationSettingsType(type):
             supporting_protocols=[1, 2]),
         'type': specification(
             type=(bytes, unicode),
-            constraint=lambda value: value in ('eventing', 'reporting', 'streaming'),
+            constraint=lambda value: value in ('eventing', 'reporting', 'streaming', 'events'),
             supporting_protocols=[2])}

View solution in original post

0 Karma

cnestrud
Explorer

I was able to get this to work by changing the decorator to:

@Configuration(type='events')

And also modifying our local copy of the Splunk Python SDK to allow ‘events’ as a valid option:

diff --git a/splunklib/searchcommands/internals.py b/splunklib/searchcommands/internals.py
index be57703..23989ad 100644
--- a/splunklib/searchcommands/internals.py
+++ b/splunklib/searchcommands/internals.py
@@ -326,7 +326,7 @@ class ConfigurationSettingsType(type):
             supporting_protocols=[1, 2]),
         'type': specification(
             type=(bytes, unicode),
-            constraint=lambda value: value in ('eventing', 'reporting', 'streaming'),
+            constraint=lambda value: value in ('eventing', 'reporting', 'streaming', 'events'),
             supporting_protocols=[2])}
0 Karma

aaraneta_splunk
Splunk Employee
Splunk Employee

@cnestrud - Glad you were able to find the solution. Please don't forget to resolve your post by clicking "Accept" below your answer so that others can easily find it if they are having the same issue. Thanks!

0 Karma
Career Survey
First 500 qualified respondents will receive a $20 gift card! Tell us about your professional Splunk journey.
Get Updates on the Splunk Community!

Thanks for the Memories! Splunk University, .conf25, and our Community

Thank you to everyone in the Splunk Community who joined us for .conf25, which kicked off with our iconic ...

Data Persistence in the OpenTelemetry Collector

This blog post is part of an ongoing series on OpenTelemetry. What happens if the OpenTelemetry collector ...

Introducing Splunk 10.0: Smarter, Faster, and More Powerful Than Ever

Now On Demand Whether you're managing complex deployments or looking to future-proof your data ...