<?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 do I avoid using an eval for a fixed value parameter in a custom command? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-do-I-avoid-using-an-eval-for-a-fixed-value-parameter-in-a/m-p/502888#M139938</link>
    <description>&lt;P&gt;Figured it out finally, was quite obvious in the end.  Anyways, here is a snippet that should help anyone who comes across the same problem.  I used &lt;CODE&gt;Intersplunk&lt;/CODE&gt; library and the difference is between a &lt;CODE&gt;keyword&lt;/CODE&gt; and an &lt;CODE&gt;option&lt;/CODE&gt;:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;keywords, options = splunk.Intersplunk.getKeywordsAndOptions()
...
parameter1 = str(options.get("parameter1","NULL"))
parameter2 = str(result[keywords[0]])
...
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Custom command can then be invoked like this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| customcommand parameter1=fixedvalue parameter2
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Hope this helps!&lt;/P&gt;</description>
    <pubDate>Sun, 29 Mar 2020 08:24:49 GMT</pubDate>
    <dc:creator>andrewtrobec</dc:creator>
    <dc:date>2020-03-29T08:24:49Z</dc:date>
    <item>
      <title>How do I avoid using an eval for a fixed value parameter in a custom command?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-I-avoid-using-an-eval-for-a-fixed-value-parameter-in-a/m-p/502887#M139937</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;

&lt;P&gt;I have a custom command, let's call it &lt;CODE&gt;customcommand&lt;/CODE&gt;.  This command takes two parameters, &lt;CODE&gt;parameter1&lt;/CODE&gt; and &lt;CODE&gt;parameter2&lt;/CODE&gt;.&lt;/P&gt;

&lt;P&gt;&lt;CODE&gt;parameter1&lt;/CODE&gt; should be a fixed value, &lt;CODE&gt;fixedvalue&lt;/CODE&gt;, while &lt;CODE&gt;parameter2&lt;/CODE&gt; comes from a field in the search.  In order to get the custom command working, I am currently using an &lt;CODE&gt;eval&lt;/CODE&gt; before the custom command to fix the value for &lt;CODE&gt;parameter1&lt;/CODE&gt;.  It looks like this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;...
| eval parameter1 = "fixedvalue"
| customcommand parameter1 parameter2
...
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Is there a way of setting parameter1 directly in the customcommand call?  Something like:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| customcommand parameter1="fixedvalue" parameter2
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;I added &lt;CODE&gt;supports_rawargs = true&lt;/CODE&gt; to my &lt;CODE&gt;commands.conf&lt;/CODE&gt;, but it doesn't seem to resolve.&lt;/P&gt;

&lt;P&gt;Can somebody point me in the right direction?&lt;/P&gt;

&lt;P&gt;Thanks!&lt;/P&gt;

&lt;P&gt;Andrew&lt;/P&gt;</description>
      <pubDate>Wed, 25 Mar 2020 09:38:45 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-I-avoid-using-an-eval-for-a-fixed-value-parameter-in-a/m-p/502887#M139937</guid>
      <dc:creator>andrewtrobec</dc:creator>
      <dc:date>2020-03-25T09:38:45Z</dc:date>
    </item>
    <item>
      <title>Re: How do I avoid using an eval for a fixed value parameter in a custom command?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-I-avoid-using-an-eval-for-a-fixed-value-parameter-in-a/m-p/502888#M139938</link>
      <description>&lt;P&gt;Figured it out finally, was quite obvious in the end.  Anyways, here is a snippet that should help anyone who comes across the same problem.  I used &lt;CODE&gt;Intersplunk&lt;/CODE&gt; library and the difference is between a &lt;CODE&gt;keyword&lt;/CODE&gt; and an &lt;CODE&gt;option&lt;/CODE&gt;:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;keywords, options = splunk.Intersplunk.getKeywordsAndOptions()
...
parameter1 = str(options.get("parameter1","NULL"))
parameter2 = str(result[keywords[0]])
...
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Custom command can then be invoked like this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| customcommand parameter1=fixedvalue parameter2
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Hope this helps!&lt;/P&gt;</description>
      <pubDate>Sun, 29 Mar 2020 08:24:49 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-I-avoid-using-an-eval-for-a-fixed-value-parameter-in-a/m-p/502888#M139938</guid>
      <dc:creator>andrewtrobec</dc:creator>
      <dc:date>2020-03-29T08:24:49Z</dc:date>
    </item>
  </channel>
</rss>

