<?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 Custom search command executed multiple times with protocol v2 in Splunk Dev</title>
    <link>https://community.splunk.com/t5/Splunk-Dev/Custom-search-command-executed-multiple-times-with-protocol-v2/m-p/446939#M8099</link>
    <description>&lt;P&gt;Hi, I thought my custom search command was working fine, until I added some logs.&lt;BR /&gt;The logs showed me that for a single call to the command, the code was run multiple (3-4) times.&lt;BR /&gt;My command is built using protocol version 2.&lt;/P&gt;
&lt;P&gt;I'm aware of &lt;A href="https://answers.splunk.com/answers/577530/custom-search-command-called-multiple-times.html" target="_blank"&gt;this question&lt;/A&gt;, but the answer looks like a hack.&lt;/P&gt;
&lt;P&gt;Checkout the logs below. Does everything look fine to you? How can I fix it?&lt;/P&gt;
&lt;P&gt;Example:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE&gt;import logging

from splunklib.searchcommands import dispatch, EventingCommand, Configuration

logger = setup_logger(logging.DEBUG)
logger.info("start log")

@Configuration()
class OutputFTP(EventingCommand):

    def transform(self, records):
        logger.info('inside transform')
        for record in records:
            yield record


logger.info("before dispatch")
dispatch(OutputFTP, sys.argv, sys.stdin, sys.stdout, __name__)
logger.info("after dispatch")
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Result logs:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE&gt;2018-10-26 15:49:34,196 INFO start log
2018-10-26 15:49:34,196 INFO before dispatch
2018-10-26 15:49:34,197 INFO inside transform
2018-10-26 15:49:34,198 INFO after dispatch
2018-10-26 15:49:34,262 INFO start log
2018-10-26 15:49:34,263 INFO before dispatch
2018-10-26 15:49:34,264 INFO inside transform
2018-10-26 15:49:34,265 INFO after dispatch
2018-10-26 15:49:34,358 INFO start log
2018-10-26 15:49:34,359 INFO before dispatch
2018-10-26 15:49:34,360 INFO inside transform
2018-10-26 15:49:34,425 INFO start log
2018-10-26 15:49:34,425 INFO before dispatch
2018-10-26 15:49:34,426 INFO inside transform
2018-10-26 15:49:34,429 INFO after dispatch
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;commands.conf&lt;/P&gt;
&lt;PRE&gt;&lt;CODE&gt;[my_command]
filename = my_command.py
chunked = true
run_in_preview = false
&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Sun, 07 Jun 2020 18:44:21 GMT</pubDate>
    <dc:creator>twesthead</dc:creator>
    <dc:date>2020-06-07T18:44:21Z</dc:date>
    <item>
      <title>Custom search command executed multiple times with protocol v2</title>
      <link>https://community.splunk.com/t5/Splunk-Dev/Custom-search-command-executed-multiple-times-with-protocol-v2/m-p/446939#M8099</link>
      <description>&lt;P&gt;Hi, I thought my custom search command was working fine, until I added some logs.&lt;BR /&gt;The logs showed me that for a single call to the command, the code was run multiple (3-4) times.&lt;BR /&gt;My command is built using protocol version 2.&lt;/P&gt;
&lt;P&gt;I'm aware of &lt;A href="https://answers.splunk.com/answers/577530/custom-search-command-called-multiple-times.html" target="_blank"&gt;this question&lt;/A&gt;, but the answer looks like a hack.&lt;/P&gt;
&lt;P&gt;Checkout the logs below. Does everything look fine to you? How can I fix it?&lt;/P&gt;
&lt;P&gt;Example:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE&gt;import logging

from splunklib.searchcommands import dispatch, EventingCommand, Configuration

logger = setup_logger(logging.DEBUG)
logger.info("start log")

@Configuration()
class OutputFTP(EventingCommand):

    def transform(self, records):
        logger.info('inside transform')
        for record in records:
            yield record


logger.info("before dispatch")
dispatch(OutputFTP, sys.argv, sys.stdin, sys.stdout, __name__)
logger.info("after dispatch")
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Result logs:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE&gt;2018-10-26 15:49:34,196 INFO start log
2018-10-26 15:49:34,196 INFO before dispatch
2018-10-26 15:49:34,197 INFO inside transform
2018-10-26 15:49:34,198 INFO after dispatch
2018-10-26 15:49:34,262 INFO start log
2018-10-26 15:49:34,263 INFO before dispatch
2018-10-26 15:49:34,264 INFO inside transform
2018-10-26 15:49:34,265 INFO after dispatch
2018-10-26 15:49:34,358 INFO start log
2018-10-26 15:49:34,359 INFO before dispatch
2018-10-26 15:49:34,360 INFO inside transform
2018-10-26 15:49:34,425 INFO start log
2018-10-26 15:49:34,425 INFO before dispatch
2018-10-26 15:49:34,426 INFO inside transform
2018-10-26 15:49:34,429 INFO after dispatch
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;commands.conf&lt;/P&gt;
&lt;PRE&gt;&lt;CODE&gt;[my_command]
filename = my_command.py
chunked = true
run_in_preview = false
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sun, 07 Jun 2020 18:44:21 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Dev/Custom-search-command-executed-multiple-times-with-protocol-v2/m-p/446939#M8099</guid>
      <dc:creator>twesthead</dc:creator>
      <dc:date>2020-06-07T18:44:21Z</dc:date>
    </item>
    <item>
      <title>Re: Custom search command executed multiple times with protocol v2</title>
      <link>https://community.splunk.com/t5/Splunk-Dev/Custom-search-command-executed-multiple-times-with-protocol-v2/m-p/446940#M8100</link>
      <description>&lt;P&gt;It has been some time since you asked but do you have any idea why it was happening? I have the same issue, my script starts logger +2 times every time and sometimes even fails. I wonder if it is logger related issue or python interpreter issue.&lt;/P&gt;</description>
      <pubDate>Mon, 02 Dec 2019 11:26:23 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Dev/Custom-search-command-executed-multiple-times-with-protocol-v2/m-p/446940#M8100</guid>
      <dc:creator>seva98</dc:creator>
      <dc:date>2019-12-02T11:26:23Z</dc:date>
    </item>
    <item>
      <title>Re: Custom search command executed multiple times with protocol v2</title>
      <link>https://community.splunk.com/t5/Splunk-Dev/Custom-search-command-executed-multiple-times-with-protocol-v2/m-p/446941#M8101</link>
      <description>&lt;P&gt;It has been some time since you asked but do you have any idea why it was happening? I have the same issue, my script starts logger +2 times every time and sometimes even fails. I wonder if it is logger related issue or python interpreter issue.&lt;/P&gt;</description>
      <pubDate>Mon, 02 Dec 2019 11:26:25 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Dev/Custom-search-command-executed-multiple-times-with-protocol-v2/m-p/446941#M8101</guid>
      <dc:creator>seva98</dc:creator>
      <dc:date>2019-12-02T11:26:25Z</dc:date>
    </item>
  </channel>
</rss>

