<?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 Search Commands: how to process positional args in command class? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Custom-Search-Commands-how-to-process-positional-args-in-command/m-p/445352#M126332</link>
    <description>&lt;P&gt;I have the same question. Any body can answer it ?&lt;/P&gt;</description>
    <pubDate>Mon, 22 Apr 2019 08:54:22 GMT</pubDate>
    <dc:creator>HackerHit</dc:creator>
    <dc:date>2019-04-22T08:54:22Z</dc:date>
    <item>
      <title>Custom Search Commands: how to process positional args in command class?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Custom-Search-Commands-how-to-process-positional-args-in-command/m-p/445351#M126331</link>
      <description>&lt;P&gt;i.e. we have some custom command &lt;CODE&gt;generatetext&lt;/CODE&gt;&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;@Configuration()
class GenerateTextCommand(GeneratingCommand):

    count = Option(require=True, validate=validators.Integer(0))
    text = Option(require=True)

    def generate(self):
        text = self.text
        for i in range(1, self.count + 1):
            yield {'_serial': i, '_time': time.time(), '_raw': six.text_type(i) + '. ' + text}
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;I'd like to pass args to it in positional manner, &lt;/P&gt;

&lt;P&gt;NOT&lt;BR /&gt;
&lt;CODE&gt;| generatetext count=10 text='hi'&lt;/CODE&gt;&lt;/P&gt;

&lt;P&gt;BUT&lt;BR /&gt;
&lt;CODE&gt;| generatetext 10 hi&lt;/CODE&gt;&lt;/P&gt;

&lt;P&gt;How!?&lt;/P&gt;</description>
      <pubDate>Tue, 25 Dec 2018 19:07:20 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Custom-Search-Commands-how-to-process-positional-args-in-command/m-p/445351#M126331</guid>
      <dc:creator>aovsiannikov</dc:creator>
      <dc:date>2018-12-25T19:07:20Z</dc:date>
    </item>
    <item>
      <title>Re: Custom Search Commands: how to process positional args in command class?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Custom-Search-Commands-how-to-process-positional-args-in-command/m-p/445352#M126332</link>
      <description>&lt;P&gt;I have the same question. Any body can answer it ?&lt;/P&gt;</description>
      <pubDate>Mon, 22 Apr 2019 08:54:22 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Custom-Search-Commands-how-to-process-positional-args-in-command/m-p/445352#M126332</guid>
      <dc:creator>HackerHit</dc:creator>
      <dc:date>2019-04-22T08:54:22Z</dc:date>
    </item>
    <item>
      <title>Re: Custom Search Commands: how to process positional args in command class?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Custom-Search-Commands-how-to-process-positional-args-in-command/m-p/445353#M126333</link>
      <description>&lt;P&gt;I have the same question. Now I figure it out. I think it will help you.&lt;/P&gt;

&lt;P&gt;We misunderstand the definition of &lt;STRONG&gt;Field&lt;/STRONG&gt; and &lt;STRONG&gt;Option&lt;/STRONG&gt;.&lt;/P&gt;

&lt;P&gt;So we miss the important property named &lt;STRONG&gt;fieldnames&lt;/STRONG&gt;  that defined in &lt;STRONG&gt;splunklib/searchcommands/search_command.py Line:201&lt;/STRONG&gt;&lt;/P&gt;

&lt;P&gt;Following code is what you want. Line 8-9&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;@Configuration()
class GenerateTextCommand(GeneratingCommand):
    # options
    .....

    def generate(self):
            # field names
            count = self.fieldnames[0] 
            text = self.fieldnames[1]

        for i in range(1, self.count + 1):
            yield {'_serial': i, '_time': time.time(), '_raw': six.text_type(i) + '. ' + text}
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Thank you.&lt;/P&gt;</description>
      <pubDate>Mon, 22 Apr 2019 09:56:24 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Custom-Search-Commands-how-to-process-positional-args-in-command/m-p/445353#M126333</guid>
      <dc:creator>HackerHit</dc:creator>
      <dc:date>2019-04-22T09:56:24Z</dc:date>
    </item>
  </channel>
</rss>

