<?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: How to pass parameters in custom search command without field camp? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-to-pass-parameters-in-custom-search-command-without-field/m-p/504276#M140765</link>
    <description>&lt;P&gt;I am using Python SDK. Watch "self.fieldname" routine. My command will have one argument - existing field from previous search (message_subject). With the code below I was successfull passing value from any field I add as an argument to SPL commmand: e.g. "| mimedecode message_subject"&lt;BR /&gt;&lt;BR /&gt;I got inspiration from:&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;&lt;A href="https://docs.splunk.com/DocumentationStatic/PythonSDK/1.6.0/searchcommands.html" target="_blank" rel="noopener"&gt;https://docs.splunk.com/DocumentationStatic/PythonSDK/1.6.0/searchcommands.html&lt;/A&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;class decodemimeCommand(StreamingCommand):
    def stream(self, records):
    # get the argument - fieldname with mime-encoded string 
    message_subject = self.fieldnames[0]

    for record in records:
        record['message_subject_decoded'] = main(record[message_subject])
        yield record

if __name__ == "__main__":
    dispatch(decodemimeCommand, sys.argv, sys.stdin, sys.stdout, __name__)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Sat, 13 Jun 2020 14:38:24 GMT</pubDate>
    <dc:creator>tomasmoser</dc:creator>
    <dc:date>2020-06-13T14:38:24Z</dc:date>
    <item>
      <title>How to pass parameters in custom search command without field camp?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-pass-parameters-in-custom-search-command-without-field/m-p/503432#M140045</link>
      <description>&lt;BLOCKQUOTE&gt;
&lt;P&gt;&lt;STRONG&gt;How can i run a search command passing an argument to python script via sys.argv?&lt;/STRONG&gt;&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;

&lt;P&gt;&lt;STRONG&gt;My script:&lt;/STRONG&gt;&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;import requests
import sys
import json
from splunklib.searchcommands import \
 dispatch, GeneratingCommand, Configuration, Option, validators

@Configuration()
class GenerateHelloCommand(GeneratingCommand):

    id = Option(require=True, validate=validators.Integer())


    def generate(self):



        site = "https://link/api/link.json?id=" + str(self.id) + "&amp;amp;username=x2&amp;amp;passhash=x"
        response = requests.get(site, timeout=10)
        filtro = json.loads(response.text)
        filt = filtro["sensordata"]["statustext"]
        yield {'ID' : str(self.id), 'STATUS' : filt}



dispatch(GenerateHelloCommand, sys.argv, sys.stdin, sys.stdout, __name__)
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Currently i run my command like this:&lt;/P&gt;

&lt;P&gt;| comando id=11249&lt;/P&gt;

&lt;P&gt;and it work, but I would like to run my command like this:&lt;/P&gt;

&lt;P&gt;| comando 11249&lt;/P&gt;

&lt;P&gt;Such that i get 11249 into the python script like a variable. Example:&lt;/P&gt;

&lt;P&gt;ID = arg.sysv[1]&lt;/P&gt;

&lt;P&gt;&lt;STRONG&gt;My commands.conf:&lt;/STRONG&gt;&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;[comando]
chunked=true
filename=comando.py
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Can someone help me?&lt;/P&gt;</description>
      <pubDate>Fri, 11 Oct 2019 20:06:40 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-pass-parameters-in-custom-search-command-without-field/m-p/503432#M140045</guid>
      <dc:creator>rmenchio</dc:creator>
      <dc:date>2019-10-11T20:06:40Z</dc:date>
    </item>
    <item>
      <title>Re: How to pass parameters in custom search command without field camp?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-pass-parameters-in-custom-search-command-without-field/m-p/503433#M140046</link>
      <description>&lt;P&gt;See my unaccepted answer here:&lt;BR /&gt;
&lt;A href="https://answers.splunk.com/answers/41949/passing-search-results-to-external-python-script.html"&gt;https://answers.splunk.com/answers/41949/passing-search-results-to-external-python-script.html&lt;/A&gt;&lt;BR /&gt;
&lt;CODE&gt;UpVotes&lt;/CODE&gt; appreciated.&lt;/P&gt;</description>
      <pubDate>Sat, 12 Oct 2019 17:09:55 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-pass-parameters-in-custom-search-command-without-field/m-p/503433#M140046</guid>
      <dc:creator>woodcock</dc:creator>
      <dc:date>2019-10-12T17:09:55Z</dc:date>
    </item>
    <item>
      <title>Re: How to pass parameters in custom search command without field camp?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-pass-parameters-in-custom-search-command-without-field/m-p/504276#M140765</link>
      <description>&lt;P&gt;I am using Python SDK. Watch "self.fieldname" routine. My command will have one argument - existing field from previous search (message_subject). With the code below I was successfull passing value from any field I add as an argument to SPL commmand: e.g. "| mimedecode message_subject"&lt;BR /&gt;&lt;BR /&gt;I got inspiration from:&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;&lt;A href="https://docs.splunk.com/DocumentationStatic/PythonSDK/1.6.0/searchcommands.html" target="_blank" rel="noopener"&gt;https://docs.splunk.com/DocumentationStatic/PythonSDK/1.6.0/searchcommands.html&lt;/A&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;class decodemimeCommand(StreamingCommand):
    def stream(self, records):
    # get the argument - fieldname with mime-encoded string 
    message_subject = self.fieldnames[0]

    for record in records:
        record['message_subject_decoded'] = main(record[message_subject])
        yield record

if __name__ == "__main__":
    dispatch(decodemimeCommand, sys.argv, sys.stdin, sys.stdout, __name__)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 13 Jun 2020 14:38:24 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-pass-parameters-in-custom-search-command-without-field/m-p/504276#M140765</guid>
      <dc:creator>tomasmoser</dc:creator>
      <dc:date>2020-06-13T14:38:24Z</dc:date>
    </item>
  </channel>
</rss>

