<?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 macro with parameter as eval-base definition in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/macro-with-parameter-as-eval-base-definition/m-p/581391#M202544</link>
    <description>&lt;P&gt;My main query looks like:&lt;BR /&gt;...| stats&amp;nbsp;min(_time) AS SESSION_START_TIME max(Source_Network_Address) AS EMP_SRC_IP...&lt;BR /&gt;| eval empID=`my_macro($EMP_SRC_IP$, $SESSION_START_TIME $)`&amp;nbsp;&lt;/P&gt;&lt;P&gt;My macro definition is:&lt;BR /&gt;index=my_idx event.eventID=4624 event.Come_From=$ip_address$&amp;nbsp; latest=$time$ | sort - _time | head 1| table event.Who_Is_It&lt;BR /&gt;&lt;BR /&gt;My questions are:&lt;BR /&gt;1. How can I make my macro, my_macro, returns a String which is the value of event.Who_IS_It ?&lt;/P&gt;&lt;P&gt;2. Is the way I assign the macro returned value to param name empID is the right way?&lt;/P&gt;</description>
    <pubDate>Mon, 17 Jan 2022 20:57:02 GMT</pubDate>
    <dc:creator>eranhauser</dc:creator>
    <dc:date>2022-01-17T20:57:02Z</dc:date>
    <item>
      <title>macro with parameter as eval-base definition</title>
      <link>https://community.splunk.com/t5/Splunk-Search/macro-with-parameter-as-eval-base-definition/m-p/581391#M202544</link>
      <description>&lt;P&gt;My main query looks like:&lt;BR /&gt;...| stats&amp;nbsp;min(_time) AS SESSION_START_TIME max(Source_Network_Address) AS EMP_SRC_IP...&lt;BR /&gt;| eval empID=`my_macro($EMP_SRC_IP$, $SESSION_START_TIME $)`&amp;nbsp;&lt;/P&gt;&lt;P&gt;My macro definition is:&lt;BR /&gt;index=my_idx event.eventID=4624 event.Come_From=$ip_address$&amp;nbsp; latest=$time$ | sort - _time | head 1| table event.Who_Is_It&lt;BR /&gt;&lt;BR /&gt;My questions are:&lt;BR /&gt;1. How can I make my macro, my_macro, returns a String which is the value of event.Who_IS_It ?&lt;/P&gt;&lt;P&gt;2. Is the way I assign the macro returned value to param name empID is the right way?&lt;/P&gt;</description>
      <pubDate>Mon, 17 Jan 2022 20:57:02 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/macro-with-parameter-as-eval-base-definition/m-p/581391#M202544</guid>
      <dc:creator>eranhauser</dc:creator>
      <dc:date>2022-01-17T20:57:02Z</dc:date>
    </item>
    <item>
      <title>Re: macro with parameter as eval-base definition</title>
      <link>https://community.splunk.com/t5/Splunk-Search/macro-with-parameter-as-eval-base-definition/m-p/581410#M202549</link>
      <description>&lt;P&gt;Try setting your macro up like this:&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;[search index=my_idx event.eventID=4624 event.Come_From=$ip_address$  latest=$time$ 
| sort - _time 
| head 1
| table 'event.Who_Is_It'
| rename "event.Who_Is_It" as query | fields query | format "\"" "" "" "" "" "\""]&lt;/LI-CODE&gt;&lt;P&gt;You may also need to trim the result&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| eval empID=trim(`my_macro($EMP_SRC_IP$, $SESSION_START_TIME $)`)&lt;/LI-CODE&gt;</description>
      <pubDate>Tue, 18 Jan 2022 00:10:00 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/macro-with-parameter-as-eval-base-definition/m-p/581410#M202549</guid>
      <dc:creator>ITWhisperer</dc:creator>
      <dc:date>2022-01-18T00:10:00Z</dc:date>
    </item>
    <item>
      <title>Re: macro with parameter as eval-base definition</title>
      <link>https://community.splunk.com/t5/Splunk-Search/macro-with-parameter-as-eval-base-definition/m-p/581477#M202578</link>
      <description>&lt;P&gt;Something strange is going on. When I run the query of the macro as you suggested on Splunk UI (as a subsearch) I got zero results back. If I remove the last part of "| rename" I got 11 results back as if it ignore the "| head 1". When I run it NOT as a subsearch I got one result as expected.&amp;nbsp;&lt;BR /&gt;What should I do to fix it?&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;Why is that?&lt;/P&gt;</description>
      <pubDate>Tue, 18 Jan 2022 15:44:51 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/macro-with-parameter-as-eval-base-definition/m-p/581477#M202578</guid>
      <dc:creator>eranhauser</dc:creator>
      <dc:date>2022-01-18T15:44:51Z</dc:date>
    </item>
    <item>
      <title>Re: macro with parameter as eval-base definition</title>
      <link>https://community.splunk.com/t5/Splunk-Search/macro-with-parameter-as-eval-base-definition/m-p/581494#M202583</link>
      <description>&lt;P&gt;What do you mean "as a subsearch"? Can you share exactly what you have in the search in a code block &amp;lt;/&amp;gt;&lt;/P&gt;</description>
      <pubDate>Tue, 18 Jan 2022 16:18:51 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/macro-with-parameter-as-eval-base-definition/m-p/581494#M202583</guid>
      <dc:creator>ITWhisperer</dc:creator>
      <dc:date>2022-01-18T16:18:51Z</dc:date>
    </item>
    <item>
      <title>Re: macro with parameter as eval-base definition</title>
      <link>https://community.splunk.com/t5/Splunk-Search/macro-with-parameter-as-eval-base-definition/m-p/581514#M202587</link>
      <description>&lt;P&gt;I created the macro as a subsearch as you suggested below:&lt;/P&gt;&lt;PRE&gt;[search index=my_idx event.eventID=4624 event.Come_From=$ip_address$  latest=$time$ 
| sort - _time 
| head 1
| table 'event.Who_Is_It'
| rename "event.Who_Is_It" as query | fields query | format "\"" "" "" "" "" "\""]&lt;/PRE&gt;&lt;P&gt;and when I call it on Splunk UI :&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;`my_macro($EMP_SRC_IP$, $SESSION_START_TIME $)`&lt;/PRE&gt;&lt;P&gt;I got the results I mentioned above&lt;/P&gt;</description>
      <pubDate>Tue, 18 Jan 2022 17:50:32 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/macro-with-parameter-as-eval-base-definition/m-p/581514#M202587</guid>
      <dc:creator>eranhauser</dc:creator>
      <dc:date>2022-01-18T17:50:32Z</dc:date>
    </item>
    <item>
      <title>Re: macro with parameter as eval-base definition</title>
      <link>https://community.splunk.com/t5/Splunk-Search/macro-with-parameter-as-eval-base-definition/m-p/581518#M202588</link>
      <description>&lt;P&gt;On the splunk search UI call it like this&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| makeresults
| eval empID=trim(`my_macro($EMP_SRC_IP$, $SESSION_START_TIME $)`)&lt;/LI-CODE&gt;</description>
      <pubDate>Tue, 18 Jan 2022 18:07:17 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/macro-with-parameter-as-eval-base-definition/m-p/581518#M202588</guid>
      <dc:creator>ITWhisperer</dc:creator>
      <dc:date>2022-01-18T18:07:17Z</dc:date>
    </item>
    <item>
      <title>Re: macro with parameter as eval-base definition</title>
      <link>https://community.splunk.com/t5/Splunk-Search/macro-with-parameter-as-eval-base-definition/m-p/581523#M202590</link>
      <description>&lt;P&gt;I found the issue: The macro should be a little different:&lt;/P&gt;&lt;PRE&gt;[search index=my_idx event.eventID=4624 event.Come_From=$ip_address$  latest=$time$ 
| sort - _time 
| head 1
| rename "event.Who_Is_It" as query | fields query | format "\"" "" "" "" "" "\"" | table search]&lt;BR /&gt;&lt;BR /&gt;The problem now is that I get error passing parameters.&lt;/PRE&gt;&lt;PRE&gt;| eval empID=trim(`my_macro($EMP_SRC_IP$, $SESSION_START_TIME $)`)&lt;/PRE&gt;&lt;PRE&gt;&lt;SPAN&gt;Invalid value "$SESSION_START_TIME$" for time term 'latest' &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/PRE&gt;&lt;P&gt;&lt;SPAN&gt;Any idea what is wrong?&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 18 Jan 2022 18:51:58 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/macro-with-parameter-as-eval-base-definition/m-p/581523#M202590</guid>
      <dc:creator>eranhauser</dc:creator>
      <dc:date>2022-01-18T18:51:58Z</dc:date>
    </item>
    <item>
      <title>Re: macro with parameter as eval-base definition</title>
      <link>https://community.splunk.com/t5/Splunk-Search/macro-with-parameter-as-eval-base-definition/m-p/581525#M202591</link>
      <description>&lt;P&gt;My query looks like:&lt;BR /&gt;... | stats min(_time) AS SESSION_START_TIME max(Source_Network_Address) AS EMP_SRC_IP ...&amp;nbsp;| eval empID=trim(`my_macro($EMP_SRC_IP$, $SESSION_START_TIME$)`)&lt;/P&gt;&lt;PRE&gt;&amp;nbsp;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 18 Jan 2022 19:03:59 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/macro-with-parameter-as-eval-base-definition/m-p/581525#M202591</guid>
      <dc:creator>eranhauser</dc:creator>
      <dc:date>2022-01-18T19:03:59Z</dc:date>
    </item>
    <item>
      <title>Re: macro with parameter as eval-base definition</title>
      <link>https://community.splunk.com/t5/Splunk-Search/macro-with-parameter-as-eval-base-definition/m-p/581526#M202592</link>
      <description>&lt;P&gt;You don't need $ around the field names you are passing into the macro&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| eval empID=trim(`my_macro(EMP_SRC_IP, SESSION_START_TIME)`)&lt;/LI-CODE&gt;</description>
      <pubDate>Tue, 18 Jan 2022 18:59:03 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/macro-with-parameter-as-eval-base-definition/m-p/581526#M202592</guid>
      <dc:creator>ITWhisperer</dc:creator>
      <dc:date>2022-01-18T18:59:03Z</dc:date>
    </item>
    <item>
      <title>Re: macro with parameter as eval-base definition</title>
      <link>https://community.splunk.com/t5/Splunk-Search/macro-with-parameter-as-eval-base-definition/m-p/581533#M202593</link>
      <description>&lt;P&gt;After removing the $ I get the following error:&lt;BR /&gt;&lt;SPAN&gt;Invalid value "SESSION_START_TIME" for time term 'latest'&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 18 Jan 2022 19:11:01 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/macro-with-parameter-as-eval-base-definition/m-p/581533#M202593</guid>
      <dc:creator>eranhauser</dc:creator>
      <dc:date>2022-01-18T19:11:01Z</dc:date>
    </item>
    <item>
      <title>Re: macro with parameter as eval-base definition</title>
      <link>https://community.splunk.com/t5/Splunk-Search/macro-with-parameter-as-eval-base-definition/m-p/581535#M202594</link>
      <description>&lt;P&gt;The query works great if I pass to the macro values and not params:&lt;BR /&gt;trim(`&lt;SPAN&gt;my_macro&lt;/SPAN&gt;("8.8.8.8", 1642031990)`) but once&amp;nbsp; try to use params I get the errors&lt;/P&gt;</description>
      <pubDate>Tue, 18 Jan 2022 19:17:59 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/macro-with-parameter-as-eval-base-definition/m-p/581535#M202594</guid>
      <dc:creator>eranhauser</dc:creator>
      <dc:date>2022-01-18T19:17:59Z</dc:date>
    </item>
    <item>
      <title>Re: macro with parameter as eval-base definition</title>
      <link>https://community.splunk.com/t5/Splunk-Search/macro-with-parameter-as-eval-base-definition/m-p/581536#M202595</link>
      <description>&lt;P&gt;How are you passing the parameters?&lt;/P&gt;</description>
      <pubDate>Tue, 18 Jan 2022 19:19:30 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/macro-with-parameter-as-eval-base-definition/m-p/581536#M202595</guid>
      <dc:creator>ITWhisperer</dc:creator>
      <dc:date>2022-01-18T19:19:30Z</dc:date>
    </item>
    <item>
      <title>Re: macro with parameter as eval-base definition</title>
      <link>https://community.splunk.com/t5/Splunk-Search/macro-with-parameter-as-eval-base-definition/m-p/581545#M202596</link>
      <description>&lt;P&gt;&lt;SPAN&gt;&amp;nbsp;eval empID=trim(`my_macro(EMP_SRC_IP, SESSION_START_TIME)`)&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 18 Jan 2022 20:02:02 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/macro-with-parameter-as-eval-base-definition/m-p/581545#M202596</guid>
      <dc:creator>eranhauser</dc:creator>
      <dc:date>2022-01-18T20:02:02Z</dc:date>
    </item>
  </channel>
</rss>

