<?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 Commands - Can Streaming Command return more than 1 row per result??? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Custom-Commands-Can-Streaming-Command-return-more-than-1-row-per/m-p/464998#M191653</link>
    <description>&lt;P&gt;Please mark as answer if this is what you were looking for&lt;/P&gt;</description>
    <pubDate>Thu, 24 Oct 2019 14:42:48 GMT</pubDate>
    <dc:creator>arjunpkishore5</dc:creator>
    <dc:date>2019-10-24T14:42:48Z</dc:date>
    <item>
      <title>Custom Commands - Can Streaming Command return more than 1 row per result???</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Custom-Commands-Can-Streaming-Command-return-more-than-1-row-per/m-p/464996#M191651</link>
      <description>&lt;P&gt;Hello, I'm creating a custom command on splunk (as you can see bellow), my problem is that from one row I want to create two.&lt;/P&gt;

&lt;P&gt;Is it possible? &lt;/P&gt;

&lt;P&gt;Just to keep you in the context, what i'm trying to change this single line:&lt;BR /&gt;
main_app          first_relation          second_relation&lt;/P&gt;

&lt;P&gt;into two:&lt;BR /&gt;
main_app          first_relation&lt;BR /&gt;
main_app          second_relation&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;import sys
import re
from splunklib.searchcommands import dispatch, StreamingCommand, Configuration


@Configuration(local=True)
class ExtractDicom(StreamingCommand):
    def stream(self, records):
        for record in records:
            record['from'] = None
            record['to'] = None
            if record['main_app'] is not None or record['main_app']!='':
                record['from'] = record['main_app']
                record['to'] = record['first_relation']
                record['from'] = record['main_app']
                record['to'] = record['second_relation']

            record['meh'] = {'data2', 'data3'}

            yield record


if __name__ == "__main__":
    dispatch(ExtractDicom, sys.argv, sys.stdin, sys.stdout, __name__)
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Any kind of help I would appreciate &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 30 Sep 2020 02:41:03 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Custom-Commands-Can-Streaming-Command-return-more-than-1-row-per/m-p/464996#M191651</guid>
      <dc:creator>ppatrikfr</dc:creator>
      <dc:date>2020-09-30T02:41:03Z</dc:date>
    </item>
    <item>
      <title>Re: Custom Commands - Can Streaming Command return more than 1 row per result???</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Custom-Commands-Can-Streaming-Command-return-more-than-1-row-per/m-p/464997#M191652</link>
      <description>&lt;P&gt;In Line 13 and 14, you're creating your first row, in line 15 and 16, you are overriding the same row instead of crating a new row. That is why you see only one row. Not sure what you're trying to achieve here, here is the quick hack.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;import sys
import re
import copy

from splunklib.searchcommands import dispatch, StreamingCommand, Configuration


 @Configuration(local=True)
 class ExtractDicom(StreamingCommand):
     def stream(self, records):
         for record in records:
             record['from'] = None
             record['to'] = None
             ret_records=[]
             if record['main_app'] is not None or record['main_app']!='':
                 ret_records[0] = copy.deepCopy(record)
                 ret_records[0]['from'] = record['main_app']
                 ret_records[0]['to'] = record['first_relation']
                 ret_records[1] = copy.deepCopy(record)
                 ret_records[1]['from'] = record['main_app']
                 ret_records[1]['to'] = record['second_relation']

             #Totally unsure what this row is trying to do!
             record['meh'] = {'data2', 'data3'}

             for ret_record in ret_records:
                yield ret_record


 if __name__ == "__main__":
     dispatch(ExtractDicom, sys.argv, sys.stdin, sys.stdout, __name__)
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;This is in no way production ready code. Like I said, I am unsure what you're trying to acheive. I'm just pointing out where you're going wrong.&lt;/P&gt;

&lt;P&gt;You could also totally achieve this directly in SPL as below&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| &amp;lt;your search&amp;gt;
| eval from=if(isnotnull(main_app), main_app, null())
| eval to=if(isnotnull(main_app), mvappend(first_relation, second_relation), null())
| mvexpand to
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 24 Oct 2019 12:32:36 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Custom-Commands-Can-Streaming-Command-return-more-than-1-row-per/m-p/464997#M191652</guid>
      <dc:creator>arjunpkishore5</dc:creator>
      <dc:date>2019-10-24T12:32:36Z</dc:date>
    </item>
    <item>
      <title>Re: Custom Commands - Can Streaming Command return more than 1 row per result???</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Custom-Commands-Can-Streaming-Command-return-more-than-1-row-per/m-p/464998#M191653</link>
      <description>&lt;P&gt;Please mark as answer if this is what you were looking for&lt;/P&gt;</description>
      <pubDate>Thu, 24 Oct 2019 14:42:48 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Custom-Commands-Can-Streaming-Command-return-more-than-1-row-per/m-p/464998#M191653</guid>
      <dc:creator>arjunpkishore5</dc:creator>
      <dc:date>2019-10-24T14:42:48Z</dc:date>
    </item>
  </channel>
</rss>

