<?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 streaming command receives no events in Splunk Dev</title>
    <link>https://community.splunk.com/t5/Splunk-Dev/Custom-streaming-command-receives-no-events/m-p/746681#M11931</link>
    <description>&lt;P&gt;&lt;SPAN&gt;This is a simple code to reproduce the problem. My actual code iterates over the events. The problem is when I dont use the table command before my customcommand there is no events to iterate over. In this case without table there is no results not even one. Also my search in this example uses head 1, thus there is only one input&amp;nbsp; result.&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;I will try your version when I got back to work.&lt;/SPAN&gt;&lt;/P&gt;</description>
    <pubDate>Wed, 21 May 2025 17:51:32 GMT</pubDate>
    <dc:creator>wipark</dc:creator>
    <dc:date>2025-05-21T17:51:32Z</dc:date>
    <item>
      <title>Custom streaming command receives no events</title>
      <link>https://community.splunk.com/t5/Splunk-Dev/Custom-streaming-command-receives-no-events/m-p/746678#M11928</link>
      <description>&lt;P&gt;I am developing a custom streaming command. During tests and debugging I noticed the command works fine in this search:&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;index="_internal" | head 1 | table host | customcommand&lt;/LI-CODE&gt;&lt;P&gt;and produces the following result:&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;&amp;lt;class 'generator'&amp;gt;&lt;/LI-CODE&gt;&lt;P&gt;But when I use the command in the following search it produces no results:&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;index="_internal" | head 1 | customcommand&lt;/LI-CODE&gt;&lt;P&gt;This is the code:&lt;/P&gt;&lt;LI-CODE lang="python"&gt;@Configuration()
class CustomCommand(StreamingCommand):

    def stream(self, events):
        yield {"event": str(type(events))}&lt;/LI-CODE&gt;&lt;P&gt;and this is commands.conf:&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;[customcommand]
chunked = true
filename = customcommand.py
python.version = python3
requires_srinfo = true
streaming = true&lt;/LI-CODE&gt;&lt;P&gt;How can I fix that?&lt;/P&gt;</description>
      <pubDate>Wed, 21 May 2025 15:26:58 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Dev/Custom-streaming-command-receives-no-events/m-p/746678#M11928</guid>
      <dc:creator>wipark</dc:creator>
      <dc:date>2025-05-21T15:26:58Z</dc:date>
    </item>
    <item>
      <title>Re: Custom streaming command receives no events</title>
      <link>https://community.splunk.com/t5/Splunk-Dev/Custom-streaming-command-receives-no-events/m-p/746679#M11929</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/268826"&gt;@wipark&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Your command yields a single event with the type of the events parameter, but does not process or yield the actual input events. In a streaming command, you must iterate over the incoming events and yield output for each one. Your current implementation only yields once, regardless of input.&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Try this updated code:&lt;/STRONG&gt;&lt;/P&gt;&lt;PRE&gt;@Configuration()
class CustomCommand(StreamingCommand):
    def stream(self, events):
        for event in events:
            event["event"] = str(type(events))
            yield event&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The stream method receives an iterator of events. You need to loop over events and yield each event (usually you would modify the events to perform your commands intended function..!).&lt;BR /&gt;Your original code only yielded once, so unless the search pipeline expected a single event, nothing was passed downstream.&lt;/P&gt;&lt;P&gt;&lt;span class="lia-unicode-emoji" title=":glowing_star:"&gt;🌟&lt;/span&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;STRONG&gt;Did this answer help you?&lt;/STRONG&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;If so, please consider:&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;Adding karma to show it was useful&lt;/LI&gt;&lt;LI&gt;Marking it as the solution if it resolved your issue&lt;/LI&gt;&lt;LI&gt;Commenting if you need any clarification&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;Your feedback encourages the volunteers in this community to continue contributing&lt;/P&gt;</description>
      <pubDate>Wed, 21 May 2025 15:40:22 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Dev/Custom-streaming-command-receives-no-events/m-p/746679#M11929</guid>
      <dc:creator>livehybrid</dc:creator>
      <dc:date>2025-05-21T15:40:22Z</dc:date>
    </item>
    <item>
      <title>Re: Custom streaming command receives no events</title>
      <link>https://community.splunk.com/t5/Splunk-Dev/Custom-streaming-command-receives-no-events/m-p/746680#M11930</link>
      <description>&lt;P&gt;This is a simple code to reproduce the problem. My actual code iterates over the events. The problem is when I dont use the table command before my customcommand there is no events to iterate over. In this case without table there is no results not even one. Also my search in this example uses head 1, thus there is only one input&amp;nbsp; result.&lt;/P&gt;</description>
      <pubDate>Wed, 21 May 2025 16:01:19 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Dev/Custom-streaming-command-receives-no-events/m-p/746680#M11930</guid>
      <dc:creator>wipark</dc:creator>
      <dc:date>2025-05-21T16:01:19Z</dc:date>
    </item>
    <item>
      <title>Re: Custom streaming command receives no events</title>
      <link>https://community.splunk.com/t5/Splunk-Dev/Custom-streaming-command-receives-no-events/m-p/746681#M11931</link>
      <description>&lt;P&gt;&lt;SPAN&gt;This is a simple code to reproduce the problem. My actual code iterates over the events. The problem is when I dont use the table command before my customcommand there is no events to iterate over. In this case without table there is no results not even one. Also my search in this example uses head 1, thus there is only one input&amp;nbsp; result.&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;I will try your version when I got back to work.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 21 May 2025 17:51:32 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Dev/Custom-streaming-command-receives-no-events/m-p/746681#M11931</guid>
      <dc:creator>wipark</dc:creator>
      <dc:date>2025-05-21T17:51:32Z</dc:date>
    </item>
    <item>
      <title>Re: Custom streaming command receives no events</title>
      <link>https://community.splunk.com/t5/Splunk-Dev/Custom-streaming-command-receives-no-events/m-p/746725#M11932</link>
      <description>&lt;P&gt;Thanks, that solved the problem. It seems that for the code to work correctly, I need to yield the original record, or at least some fields of it. I haven’t tested thoroughly yet, but today I started testing based on &lt;A href="https://github.com/splunk/splunk-app-examples/tree/master/custom_search_commands/python/streamingsearchcommands_app" target="_blank" rel="noopener"&gt;this example.&amp;nbsp;&lt;/A&gt;&lt;/P&gt;&lt;P&gt;The following code works as expected for both of these queries:&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;index=_internal | head 1 | table host | streamingcsc&lt;/LI-CODE&gt;&lt;LI-CODE lang="markup"&gt;index=_internal | head 1 | streamingcsc&lt;/LI-CODE&gt;&lt;LI-CODE lang="python"&gt;#!/usr/bin/env python

import os, sys

sys.path.insert(0, os.path.join(os.path.dirname(__file__), "..", "lib"))
from splunklib.searchcommands import dispatch, StreamingCommand, Configuration, Option, validators


@Configuration()
class StreamingCSC(StreamingCommand):
    def stream(self, records):
        for record in records:
            record["event"] = str(type(records))
            yield record


dispatch(StreamingCSC, sys.argv, sys.stdin, sys.stdout, __name__)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;But The following code only works with this query:&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;index=_internal | head 1 | table host | streamingcsc&lt;/LI-CODE&gt;&lt;LI-CODE lang="python"&gt;#!/usr/bin/env python

import os, sys

sys.path.insert(0, os.path.join(os.path.dirname(__file__), "..", "lib"))
from splunklib.searchcommands import dispatch, StreamingCommand, Configuration, Option, validators


@Configuration()
class StreamingCSC(StreamingCommand):
    def stream(self, records):
        for record in records:
            yield {"event": str(type(records))}


dispatch(StreamingCSC, sys.argv, sys.stdin, sys.stdout, __name__)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 22 May 2025 10:42:36 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Dev/Custom-streaming-command-receives-no-events/m-p/746725#M11932</guid>
      <dc:creator>wipark</dc:creator>
      <dc:date>2025-05-22T10:42:36Z</dc:date>
    </item>
    <item>
      <title>Re: Custom streaming command receives no events</title>
      <link>https://community.splunk.com/t5/Splunk-Dev/Custom-streaming-command-receives-no-events/m-p/746878#M11936</link>
      <description>&lt;P&gt;Upon further investigation It seems the _time field needs to be present for Splunk to show the results.&amp;nbsp; A code like this works:&lt;/P&gt;&lt;LI-CODE lang="python"&gt;def stream(self, events):
    yield {"myfield": "fff", "_time": "1748073052.114"}&lt;/LI-CODE&gt;</description>
      <pubDate>Sat, 24 May 2025 08:38:02 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Dev/Custom-streaming-command-receives-no-events/m-p/746878#M11936</guid>
      <dc:creator>wipark</dc:creator>
      <dc:date>2025-05-24T08:38:02Z</dc:date>
    </item>
  </channel>
</rss>

