<?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: why does my custom search command not take quoted string values for args? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/why-does-my-custom-search-command-not-take-quoted-string-values/m-p/166159#M47316</link>
    <description>&lt;P&gt;i ended up just parsing the argument as one giant string instead and then doing the string splitting inside my own script.  will have a search through my code to see if i can find it.&lt;/P&gt;</description>
    <pubDate>Mon, 28 Mar 2016 21:41:27 GMT</pubDate>
    <dc:creator>awurster</dc:creator>
    <dc:date>2016-03-28T21:41:27Z</dc:date>
    <item>
      <title>why does my custom search command not take quoted string values for args?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/why-does-my-custom-search-command-not-take-quoted-string-values/m-p/166154#M47311</link>
      <description>&lt;P&gt;just checking if this is true.. given a custom command i write with a single argument:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;... | mycommand arg1="this is value 1" arg2="foo"
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;i do not see the arg's value above returned correctly by intersplunk:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;&amp;gt;&amp;gt;&amp;gt; args, kwargs = splunk.Intersplunk.getKeywordsAndOptions()
&amp;gt;&amp;gt;&amp;gt; print str(kwargs)
&amp;gt;&amp;gt;&amp;gt; {'arg2': 'foo', 'arg1': 'this'}
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;is this expected? any way to get around this with a custom search command?  i'll be posting search data to a separate service, and need to set some values which of course have spaces in them and require quotes.&lt;/P&gt;</description>
      <pubDate>Sun, 26 Apr 2015 05:28:03 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/why-does-my-custom-search-command-not-take-quoted-string-values/m-p/166154#M47311</guid>
      <dc:creator>awurster</dc:creator>
      <dc:date>2015-04-26T05:28:03Z</dc:date>
    </item>
    <item>
      <title>Re: why does my custom search command not take quoted string values for args?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/why-does-my-custom-search-command-not-take-quoted-string-values/m-p/166155#M47312</link>
      <description>&lt;P&gt;Expected, maybe not.  But, yes, this is how &lt;CODE&gt;Intersplunk.getKeywordsAndOptions()&lt;/CODE&gt; works.  I wound up copypasting it into my own code and making changes in order to handle some of my arguments that needed quotes.  If I ever get something worth it sending back, I'll send patches to splunk and hope they make it into a future release.&lt;/P&gt;</description>
      <pubDate>Sun, 26 Apr 2015 15:46:05 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/why-does-my-custom-search-command-not-take-quoted-string-values/m-p/166155#M47312</guid>
      <dc:creator>dwaddle</dc:creator>
      <dc:date>2015-04-26T15:46:05Z</dc:date>
    </item>
    <item>
      <title>Re: why does my custom search command not take quoted string values for args?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/why-does-my-custom-search-command-not-take-quoted-string-values/m-p/166156#M47313</link>
      <description>&lt;P&gt;cheers @dwaddle.  yea maybe i'll have to pull that code out into my script and override the method.  seems kind of... &lt;EM&gt;counterintuitive&lt;/EM&gt;...&lt;/P&gt;</description>
      <pubDate>Mon, 27 Apr 2015 00:01:29 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/why-does-my-custom-search-command-not-take-quoted-string-values/m-p/166156#M47313</guid>
      <dc:creator>awurster</dc:creator>
      <dc:date>2015-04-27T00:01:29Z</dc:date>
    </item>
    <item>
      <title>Re: why does my custom search command not take quoted string values for args?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/why-does-my-custom-search-command-not-take-quoted-string-values/m-p/166157#M47314</link>
      <description>&lt;P&gt;i guess this is the code we need to override from getKeywordsAndOptions() in ./lib/python2.7/site-packages/splunk/Intersplunk.py&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;        else:
            # handle case where arg is surrounded by quotes
            # remove outter quotes and accept attr=&amp;lt;anything&amp;gt;
            if arg.startswith('"') and arg.endswith('"'):
                arg = arg[1:-1]
                matches = re.findall('(?:^|\s+)([a-zA-Z0-9_-]+)\\s*(::|==|=)\\s*(.*)', arg)
            else:
                matches = re.findall('(?:^|\s+)([a-zA-Z0-9_-]+)\\s*(::|==|=)\\s*((?:[^"\\s]+)|(?:"[^"]*"))', arg)
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 27 Apr 2015 01:10:40 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/why-does-my-custom-search-command-not-take-quoted-string-values/m-p/166157#M47314</guid>
      <dc:creator>awurster</dc:creator>
      <dc:date>2015-04-27T01:10:40Z</dc:date>
    </item>
    <item>
      <title>Re: why does my custom search command not take quoted string values for args?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/why-does-my-custom-search-command-not-take-quoted-string-values/m-p/166158#M47315</link>
      <description>&lt;P&gt;@awurster&lt;BR /&gt;
I am also trying to write a script which takes 2 arguments.&lt;/P&gt;

&lt;H1&gt;!/dir/splunk/bin/python2.7&lt;/H1&gt;

&lt;P&gt;iimport sys, time&lt;BR /&gt;
import splunk.Intersplunk&lt;BR /&gt;
import getopt&lt;BR /&gt;
from splunklib.searchcommands import \&lt;BR /&gt;
    dispatch, GeneratingCommand, Configuration, Option, validators&lt;BR /&gt;
def main(argv):&lt;/P&gt;

&lt;P&gt;print("hello")&lt;BR /&gt;
  opts, args = getopt.getopt(argv,["ifile=","ofile="])&lt;BR /&gt;
  for arg in args :&lt;BR /&gt;
     print (arg)&lt;BR /&gt;
main(sys.argv[1:])&lt;/P&gt;

&lt;P&gt;This executes fine from backend if I use the splunk python. &lt;/P&gt;

&lt;P&gt;/dir/splunk/bin/splunk cmd python command_test file1 file2&lt;/P&gt;

&lt;P&gt;But I am unable to execute it from search bar.&lt;/P&gt;

&lt;P&gt;Would you be able to advise anything regarding the script or share some part of your script.&lt;/P&gt;

&lt;P&gt;Thank you !!!&lt;/P&gt;</description>
      <pubDate>Mon, 28 Mar 2016 19:03:21 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/why-does-my-custom-search-command-not-take-quoted-string-values/m-p/166158#M47315</guid>
      <dc:creator>kamal_jagga</dc:creator>
      <dc:date>2016-03-28T19:03:21Z</dc:date>
    </item>
    <item>
      <title>Re: why does my custom search command not take quoted string values for args?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/why-does-my-custom-search-command-not-take-quoted-string-values/m-p/166159#M47316</link>
      <description>&lt;P&gt;i ended up just parsing the argument as one giant string instead and then doing the string splitting inside my own script.  will have a search through my code to see if i can find it.&lt;/P&gt;</description>
      <pubDate>Mon, 28 Mar 2016 21:41:27 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/why-does-my-custom-search-command-not-take-quoted-string-values/m-p/166159#M47316</guid>
      <dc:creator>awurster</dc:creator>
      <dc:date>2016-03-28T21:41:27Z</dc:date>
    </item>
    <item>
      <title>Re: why does my custom search command not take quoted string values for args?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/why-does-my-custom-search-command-not-take-quoted-string-values/m-p/166160#M47317</link>
      <description>&lt;P&gt;Thanks. My main issue is passing the argument from search to the script.&lt;/P&gt;</description>
      <pubDate>Tue, 29 Mar 2016 17:39:14 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/why-does-my-custom-search-command-not-take-quoted-string-values/m-p/166160#M47317</guid>
      <dc:creator>kamal_jagga</dc:creator>
      <dc:date>2016-03-29T17:39:14Z</dc:date>
    </item>
    <item>
      <title>Re: why does my custom search command not take quoted string values for args?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/why-does-my-custom-search-command-not-take-quoted-string-values/m-p/166161#M47318</link>
      <description>&lt;P&gt;@kamal_jagga - give this example a shot.  it's been a while since i've run this version of the script (i kind of abandoned the inline command approach in latest app version).  it's mostly using a keyword to do the arg splitting.&lt;/P&gt;

&lt;P&gt;&lt;A href="https://bitbucket.org/snippets/awurster/ERLbG"&gt;https://bitbucket.org/snippets/awurster/ERLbG&lt;/A&gt;&lt;/P&gt;

&lt;P&gt;any issues and you can ping me &lt;A href="mailto:awurster@atlassian.com"&gt;awurster@atlassian.com&lt;/A&gt;.  although ideally, a splunk developer person should be able to chime in here on the conversation.&lt;/P&gt;</description>
      <pubDate>Tue, 29 Mar 2016 22:46:41 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/why-does-my-custom-search-command-not-take-quoted-string-values/m-p/166161#M47318</guid>
      <dc:creator>awurster</dc:creator>
      <dc:date>2016-03-29T22:46:41Z</dc:date>
    </item>
    <item>
      <title>Re: why does my custom search command not take quoted string values for args?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/why-does-my-custom-search-command-not-take-quoted-string-values/m-p/166162#M47319</link>
      <description>&lt;P&gt;update: i ended up kind of abandoning the approach to use that method cause it just wouldn't work.  so i just took the whole search command and split it manually myself.&lt;/P&gt;

&lt;P&gt;find the details on BitBucket @ &lt;A href="https://bitbucket.org/snippets/awurster/ERLbG"&gt;https://bitbucket.org/snippets/awurster/ERLbG&lt;/A&gt; but here's a preview below:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;def getCmdArgs(settings):
    """ usage: jira &amp;lt;action&amp;gt; &amp;lt;args...&amp;gt;
        * action:
        ** create summary=&amp;lt;summary&amp;gt; template_name=&amp;lt;template_name&amp;gt;
        ** update issue=&amp;lt;issue_key&amp;gt; comment=&amp;lt;comment&amp;gt; template_name=&amp;lt;template_name&amp;gt;
    """
    sessionKey = settings['sessionKey']

    search_string, jira_command = settings['search'].rsplit('|',1)
    try:
        search_string = search_string.split('search ')[1]
    except IndexError:
        # if first command is not a "search"
        search_string = search_string.strip()
        first_cmd = search_string.split('|')[1].strip()
    parsed_cmd = re.search('\s+jira\s+(?P&amp;lt;cmd_action&amp;gt;(create|update))\s+(?P&amp;lt;cmd_options&amp;gt;.+)', jira_command).groupdict()
    cmd_action = parsed_cmd['cmd_action'].lower()
    cmd_options = {k:v.strip('"') for k,v in re.findall(r'(\S+)=(".*?"|\S+)', parsed_cmd['cmd_options'])}
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 29 Mar 2016 22:52:01 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/why-does-my-custom-search-command-not-take-quoted-string-values/m-p/166162#M47319</guid>
      <dc:creator>awurster</dc:creator>
      <dc:date>2016-03-29T22:52:01Z</dc:date>
    </item>
    <item>
      <title>Re: why does my custom search command not take quoted string values for args?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/why-does-my-custom-search-command-not-take-quoted-string-values/m-p/166163#M47320</link>
      <description>&lt;P&gt;also, you should consider making your original reply a comment not an answer &lt;span class="lia-unicode-emoji" title=":winking_face:"&gt;😉&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 29 Mar 2016 22:54:50 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/why-does-my-custom-search-command-not-take-quoted-string-values/m-p/166163#M47320</guid>
      <dc:creator>awurster</dc:creator>
      <dc:date>2016-03-29T22:54:50Z</dc:date>
    </item>
  </channel>
</rss>

