<?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 Is there a way to run map function in a custom command reporting command map, when only reduce executes?? in Splunk Dev</title>
    <link>https://community.splunk.com/t5/Splunk-Dev/Is-there-a-way-to-run-map-function-in-a-custom-command-reporting/m-p/609818#M10735</link>
    <description>&lt;P class=""&gt;&lt;SPAN class=""&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;SPAN class=""&gt;I am developing a Reporting command. However, a problem was found in the search command I made. To explain the problem, I have attached some code snippets of splunk_python_sdk. &lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN class=""&gt;0.&amp;nbsp;First, the final query I want to run is&lt;/SPAN&gt;&lt;/P&gt;
&lt;PRE&gt;index=splunk_example &lt;BR /&gt;| table test, test_results&lt;BR /&gt;| customcommand(reporting command)&lt;/PRE&gt;
&lt;P&gt;&lt;SPAN class=""&gt;However, the command was not executed properly. However, the strange thing was that this command was executed using the index stored in the search header. However, the command was not executed on the index stored in the indexer.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN class=""&gt;1.&amp;nbsp;found out&lt;BR /&gt;- So what I found out was that the map phase runs on the indexer and the rest of the reduce phase runs on the search header. &lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN class=""&gt;- And I checked the source code provided by the SDK, and I thought that the data extracted from the indexer can be passed as records when the map function is executed after checking the following related to the map function.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN class=""&gt;-&amp;gt; Q) Execution of the reporting command is done in two stages: map and reduce, but only&amp;nbsp; the reduce function actually executes. Is there any way to run the map function?&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="python"&gt;## 1-1. Here is the code provided by the sdk. 

def map(self, records):
        """ Override this method to compute partial results.
        :param records:
        :type records:
        You must override this method, if :code:`requires_preop=True`.
        """
        return NotImplemented

    def prepare(self):

        phase = self.phase

        if phase == 'map':
            # noinspection PyUnresolvedReferences
            self._configuration = self.map.ConfigurationSettings(self)
            return

        if phase == 'reduce':
            streaming_preop = chain((self.name, 'phase="map"', str(self._options)), self.fieldnames)
            self._configuration.streaming_preop = ' '.join(streaming_preop)
            return

        raise RuntimeError('Unrecognized reporting command phase: {}'.format(json_encode_string(six.text_type(phase))))

    def reduce(self, records):
        """ Override this method to produce a reporting data structure.
        You must override this method.
        """
        raise NotImplementedError('reduce(self, records)')&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;2.&amp;nbsp;how i tried&lt;/P&gt;
&lt;P&gt;- In this code, it is suggested to enable the requires_preop option to true to run the map function.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="python"&gt;@Configuration()
    class TestReportingCommand(ReportingCommand):

@Configuration(requires_preop = True)
def map(self, records):
...

def reduce(self, records):&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;- commands.conf (add)&lt;/P&gt;
&lt;P&gt;requires_preop = true&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So, I tried both methods, but when I took a log, only the reduce function was executed and the map function was not executed.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you know how to use map, please share.&lt;/P&gt;
&lt;P&gt;I used a translator, so there may be some awkwardness in the text.&lt;/P&gt;</description>
    <pubDate>Wed, 17 Aug 2022 14:47:45 GMT</pubDate>
    <dc:creator>munang</dc:creator>
    <dc:date>2022-08-17T14:47:45Z</dc:date>
    <item>
      <title>Is there a way to run map function in a custom command reporting command map, when only reduce executes??</title>
      <link>https://community.splunk.com/t5/Splunk-Dev/Is-there-a-way-to-run-map-function-in-a-custom-command-reporting/m-p/609818#M10735</link>
      <description>&lt;P class=""&gt;&lt;SPAN class=""&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;SPAN class=""&gt;I am developing a Reporting command. However, a problem was found in the search command I made. To explain the problem, I have attached some code snippets of splunk_python_sdk. &lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN class=""&gt;0.&amp;nbsp;First, the final query I want to run is&lt;/SPAN&gt;&lt;/P&gt;
&lt;PRE&gt;index=splunk_example &lt;BR /&gt;| table test, test_results&lt;BR /&gt;| customcommand(reporting command)&lt;/PRE&gt;
&lt;P&gt;&lt;SPAN class=""&gt;However, the command was not executed properly. However, the strange thing was that this command was executed using the index stored in the search header. However, the command was not executed on the index stored in the indexer.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN class=""&gt;1.&amp;nbsp;found out&lt;BR /&gt;- So what I found out was that the map phase runs on the indexer and the rest of the reduce phase runs on the search header. &lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN class=""&gt;- And I checked the source code provided by the SDK, and I thought that the data extracted from the indexer can be passed as records when the map function is executed after checking the following related to the map function.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN class=""&gt;-&amp;gt; Q) Execution of the reporting command is done in two stages: map and reduce, but only&amp;nbsp; the reduce function actually executes. Is there any way to run the map function?&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="python"&gt;## 1-1. Here is the code provided by the sdk. 

def map(self, records):
        """ Override this method to compute partial results.
        :param records:
        :type records:
        You must override this method, if :code:`requires_preop=True`.
        """
        return NotImplemented

    def prepare(self):

        phase = self.phase

        if phase == 'map':
            # noinspection PyUnresolvedReferences
            self._configuration = self.map.ConfigurationSettings(self)
            return

        if phase == 'reduce':
            streaming_preop = chain((self.name, 'phase="map"', str(self._options)), self.fieldnames)
            self._configuration.streaming_preop = ' '.join(streaming_preop)
            return

        raise RuntimeError('Unrecognized reporting command phase: {}'.format(json_encode_string(six.text_type(phase))))

    def reduce(self, records):
        """ Override this method to produce a reporting data structure.
        You must override this method.
        """
        raise NotImplementedError('reduce(self, records)')&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;2.&amp;nbsp;how i tried&lt;/P&gt;
&lt;P&gt;- In this code, it is suggested to enable the requires_preop option to true to run the map function.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="python"&gt;@Configuration()
    class TestReportingCommand(ReportingCommand):

@Configuration(requires_preop = True)
def map(self, records):
...

def reduce(self, records):&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;- commands.conf (add)&lt;/P&gt;
&lt;P&gt;requires_preop = true&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So, I tried both methods, but when I took a log, only the reduce function was executed and the map function was not executed.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you know how to use map, please share.&lt;/P&gt;
&lt;P&gt;I used a translator, so there may be some awkwardness in the text.&lt;/P&gt;</description>
      <pubDate>Wed, 17 Aug 2022 14:47:45 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Dev/Is-there-a-way-to-run-map-function-in-a-custom-command-reporting/m-p/609818#M10735</guid>
      <dc:creator>munang</dc:creator>
      <dc:date>2022-08-17T14:47:45Z</dc:date>
    </item>
  </channel>
</rss>

