<?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 make macro arguments get parsed as fields instead of literals? in Knowledge Management</title>
    <link>https://community.splunk.com/t5/Knowledge-Management/How-do-I-make-macro-arguments-get-parsed-as-fields-instead-of/m-p/416941#M3670</link>
    <description>&lt;P&gt;No, no, no.  Keep your SPL for testing the way that it is and change the definition of the &lt;CODE&gt;macro&lt;/CODE&gt; itself to be exactly what is in my solution.&lt;/P&gt;</description>
    <pubDate>Mon, 02 Jul 2018 14:09:28 GMT</pubDate>
    <dc:creator>woodcock</dc:creator>
    <dc:date>2018-07-02T14:09:28Z</dc:date>
    <item>
      <title>How do I make macro arguments get parsed as fields instead of literals?</title>
      <link>https://community.splunk.com/t5/Knowledge-Management/How-do-I-make-macro-arguments-get-parsed-as-fields-instead-of/m-p/416938#M3667</link>
      <description>&lt;P&gt;I am trying to create a macro that will take a field from an existing query.  But when I try to call it the macro treats its argument as a literal value rather than the search field value.&lt;/P&gt;

&lt;P&gt;Specifically what I am trying to do is to lookup info about a queried machine in Carbon Black.&lt;/P&gt;

&lt;P&gt;the macro looks like this&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;name: reqsensorsearch(1)
sensorsearch query="$sensor_search$"
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;I tried testing my macro with &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;|makeresults | eval sensor_search="hostname:&amp;lt;myhost&amp;gt;" | `reqsensorsearch(sensor_search)`
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;but if I do Ctrl+Shift+E (to expand and display), I see this&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| makeresults 
| eval sensor_search="hostname:&amp;lt;myhost&amp;gt;" 
| sensorsearch query="sensor_search"
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;What do I need to do to make the macro accept the value of the field sensor_search?  So I can get it to run as &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt; |sensorsearch query="hostname:&amp;lt;myhost&amp;gt;"
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 29 Jun 2018 21:05:21 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Knowledge-Management/How-do-I-make-macro-arguments-get-parsed-as-fields-instead-of/m-p/416938#M3667</guid>
      <dc:creator>MonkeyK</dc:creator>
      <dc:date>2018-06-29T21:05:21Z</dc:date>
    </item>
    <item>
      <title>Re: How do I make macro arguments get parsed as fields instead of literals?</title>
      <link>https://community.splunk.com/t5/Knowledge-Management/How-do-I-make-macro-arguments-get-parsed-as-fields-instead-of/m-p/416939#M3668</link>
      <description>&lt;P&gt;Change your &lt;CODE&gt;macro&lt;/CODE&gt; definition to this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt; eval sensorsearch query="\"" . $sensor_search$ . "\""
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 30 Jun 2018 02:52:50 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Knowledge-Management/How-do-I-make-macro-arguments-get-parsed-as-fields-instead-of/m-p/416939#M3668</guid>
      <dc:creator>woodcock</dc:creator>
      <dc:date>2018-06-30T02:52:50Z</dc:date>
    </item>
    <item>
      <title>Re: How do I make macro arguments get parsed as fields instead of literals?</title>
      <link>https://community.splunk.com/t5/Knowledge-Management/How-do-I-make-macro-arguments-get-parsed-as-fields-instead-of/m-p/416940#M3669</link>
      <description>&lt;P&gt;do you mean like this?&lt;BR /&gt;
    | makeresults &lt;BR /&gt;
    | eval sensor_search="hostname:&lt;MYHOST&gt;"&lt;BR /&gt;
    | eval sensorsearch query="\"" . $sensor_search$ . "\""&lt;/MYHOST&gt;&lt;/P&gt;

&lt;P&gt;in that case, it expands to&lt;BR /&gt;
    | makeresults &lt;BR /&gt;
    | eval sensor_search="hostname:&lt;MYHOST&gt;" &lt;BR /&gt;
    | eval sensorsearch query="\"" . $sensor_search$ . "\""&lt;/MYHOST&gt;&lt;/P&gt;

&lt;P&gt;and the results come out as&lt;BR /&gt;
_time   sensor_search   sensorsearch query&lt;BR /&gt;
2018-07-02 08:45:03 hostname:&lt;MYHOST&gt;   "hostname:&lt;MYHOST&gt;"&lt;/MYHOST&gt;&lt;/MYHOST&gt;&lt;/P&gt;

&lt;P&gt;so that just eval's "seansorsearch query" as a value&lt;/P&gt;

&lt;P&gt;I also tried removing the second eval, for which sensorsearch command still failed.  I should note that if I run sensorsearch directly, it works fine, but if it is run as&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| makeresults 
| eval sensor_search="hostname:&amp;lt;myhost&amp;gt;"
| sensorsearch query="\"" . $sensor_search$ . "\""
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;I get back and error message and searchlog shows:&lt;BR /&gt;
07-02-2018 08:47:42.608 INFO  SearchParser - PARSING: | makeresults | eval sensor_search="hostname:" | sensorsearch query="\"" . $sensor_search$ . "\""&lt;/P&gt;</description>
      <pubDate>Tue, 29 Sep 2020 20:15:29 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Knowledge-Management/How-do-I-make-macro-arguments-get-parsed-as-fields-instead-of/m-p/416940#M3669</guid>
      <dc:creator>MonkeyK</dc:creator>
      <dc:date>2020-09-29T20:15:29Z</dc:date>
    </item>
    <item>
      <title>Re: How do I make macro arguments get parsed as fields instead of literals?</title>
      <link>https://community.splunk.com/t5/Knowledge-Management/How-do-I-make-macro-arguments-get-parsed-as-fields-instead-of/m-p/416941#M3670</link>
      <description>&lt;P&gt;No, no, no.  Keep your SPL for testing the way that it is and change the definition of the &lt;CODE&gt;macro&lt;/CODE&gt; itself to be exactly what is in my solution.&lt;/P&gt;</description>
      <pubDate>Mon, 02 Jul 2018 14:09:28 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Knowledge-Management/How-do-I-make-macro-arguments-get-parsed-as-fields-instead-of/m-p/416941#M3670</guid>
      <dc:creator>woodcock</dc:creator>
      <dc:date>2018-07-02T14:09:28Z</dc:date>
    </item>
    <item>
      <title>Re: How do I make macro arguments get parsed as fields instead of literals?</title>
      <link>https://community.splunk.com/t5/Knowledge-Management/How-do-I-make-macro-arguments-get-parsed-as-fields-instead-of/m-p/416942#M3671</link>
      <description>&lt;P&gt;Oh.  Of course, sorry.  But then I still get the same results as when it is inline.  That is it just writes the string rather than running the command:&lt;/P&gt;

&lt;P&gt;_time   sensor_search   sensorsearch query&lt;BR /&gt;
2018-07-02 10:01:43 hostname:wxlpf0v968r    "hostname:wxlpf0v968r"&lt;/P&gt;</description>
      <pubDate>Tue, 29 Sep 2020 20:15:37 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Knowledge-Management/How-do-I-make-macro-arguments-get-parsed-as-fields-instead-of/m-p/416942#M3671</guid>
      <dc:creator>MonkeyK</dc:creator>
      <dc:date>2020-09-29T20:15:37Z</dc:date>
    </item>
    <item>
      <title>Re: How do I make macro arguments get parsed as fields instead of literals?</title>
      <link>https://community.splunk.com/t5/Knowledge-Management/How-do-I-make-macro-arguments-get-parsed-as-fields-instead-of/m-p/416943#M3672</link>
      <description>&lt;P&gt;OK, look, define the &lt;CODE&gt;macro&lt;/CODE&gt; the way that I showed you and then run this search:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;|makeresults | eval sensor_search="hostname:&amp;lt;myhost&amp;gt;" | `reqsensorsearch(sensor_search)`
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 03 Jul 2018 02:33:06 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Knowledge-Management/How-do-I-make-macro-arguments-get-parsed-as-fields-instead-of/m-p/416943#M3672</guid>
      <dc:creator>woodcock</dc:creator>
      <dc:date>2018-07-03T02:33:06Z</dc:date>
    </item>
    <item>
      <title>Re: How do I make macro arguments get parsed as fields instead of literals?</title>
      <link>https://community.splunk.com/t5/Knowledge-Management/How-do-I-make-macro-arguments-get-parsed-as-fields-instead-of/m-p/416944#M3673</link>
      <description>&lt;P&gt;I really think that is what I am doing&lt;/P&gt;

&lt;P&gt;My macro:&lt;BR /&gt;
Definition: eval sensorsearch query="\"" . $sensor_search$ . "\""&lt;BR /&gt;
user eval-based definition: not checked&lt;BR /&gt;
Arguments: sensor_search&lt;/P&gt;

&lt;P&gt;search line:&lt;BR /&gt;
|makeresults | eval sensor_search="hostname:" | &lt;CODE&gt;reqsensorsearch(sensor_search)&lt;/CODE&gt;&lt;/P&gt;

&lt;P&gt;results:&lt;BR /&gt;
_time   sensor_search   sensorsearch query&lt;BR /&gt;
2018-07-03 08:38:14 hostname:&lt;MYHOST&gt;   "hostname:&lt;MYHOST&gt;"&lt;/MYHOST&gt;&lt;/MYHOST&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 29 Sep 2020 20:16:08 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Knowledge-Management/How-do-I-make-macro-arguments-get-parsed-as-fields-instead-of/m-p/416944#M3673</guid>
      <dc:creator>MonkeyK</dc:creator>
      <dc:date>2020-09-29T20:16:08Z</dc:date>
    </item>
    <item>
      <title>Re: How do I make macro arguments get parsed as fields instead of literals?</title>
      <link>https://community.splunk.com/t5/Knowledge-Management/How-do-I-make-macro-arguments-get-parsed-as-fields-instead-of/m-p/416945#M3674</link>
      <description>&lt;P&gt;OK, let's back all the way up.&lt;BR /&gt;
I have your original &lt;CODE&gt;macro&lt;/CODE&gt; defined as &lt;CODE&gt;reqsensorsearch_bad&lt;/CODE&gt; with:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;eval sensorsearch query="$sensor_search$"
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;The result of this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;|makeresults | eval sensor_search="hostname:&amp;lt;myhost&amp;gt;" | `reqsensorsearch_bad(sensor_search)`
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;is this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;_time   sensor_search   sensorsearch query
2018-07-03 18:20:01 hostname:&amp;lt;myhost&amp;gt;   sensor_search
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;The result of this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;|makeresults | eval sensor_search="hostname:&amp;lt;myhost&amp;gt;" | `reqsensorsearch(sensor_search)`
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Is this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;_time   sensor_search   sensorsearch query
2018-07-03 18:19:03 hostname:&amp;lt;myhost&amp;gt;   "hostname:&amp;lt;myhost&amp;gt;"
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;The bottom line is that &lt;CODE&gt;macro&lt;/CODE&gt; arguments behave the way that you treat them.  If you treat them as &lt;CODE&gt;string literals&lt;/CODE&gt;, then they will behave that way; if you treat them as &lt;CODE&gt;field names&lt;/CODE&gt;, then they will behave that way.&lt;/P&gt;</description>
      <pubDate>Tue, 03 Jul 2018 23:23:04 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Knowledge-Management/How-do-I-make-macro-arguments-get-parsed-as-fields-instead-of/m-p/416945#M3674</guid>
      <dc:creator>woodcock</dc:creator>
      <dc:date>2018-07-03T23:23:04Z</dc:date>
    </item>
  </channel>
</rss>

