<?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 Is it possible to pass an event field as an argument to a macro? in Knowledge Management</title>
    <link>https://community.splunk.com/t5/Knowledge-Management/Is-it-possible-to-pass-an-event-field-as-an-argument-to-a-macro/m-p/237614#M2060</link>
    <description>&lt;P&gt;Hello Fellow Splunkers,&lt;BR /&gt;
This is a question about Macros in Splunk.  I was wondering if its even possible to pass field name from Events as arguments to your macro.&lt;/P&gt;

&lt;P&gt;For eg:  If I have a macro configured to &lt;CODE&gt;getInfo(info_id,info_time)&lt;/CODE&gt;, &lt;STRONG&gt;info_id&lt;/STRONG&gt; and &lt;STRONG&gt;info_time&lt;/STRONG&gt; would be event fields from an index.&lt;BR /&gt;
something like index=infologs |&lt;CODE&gt;getinfo(info_id,info_time)&lt;/CODE&gt;&lt;/P&gt;

&lt;P&gt;Thanks.&lt;BR /&gt;
Mukund&lt;/P&gt;</description>
    <pubDate>Thu, 12 Jan 2017 20:43:39 GMT</pubDate>
    <dc:creator>mnm1987</dc:creator>
    <dc:date>2017-01-12T20:43:39Z</dc:date>
    <item>
      <title>Is it possible to pass an event field as an argument to a macro?</title>
      <link>https://community.splunk.com/t5/Knowledge-Management/Is-it-possible-to-pass-an-event-field-as-an-argument-to-a-macro/m-p/237614#M2060</link>
      <description>&lt;P&gt;Hello Fellow Splunkers,&lt;BR /&gt;
This is a question about Macros in Splunk.  I was wondering if its even possible to pass field name from Events as arguments to your macro.&lt;/P&gt;

&lt;P&gt;For eg:  If I have a macro configured to &lt;CODE&gt;getInfo(info_id,info_time)&lt;/CODE&gt;, &lt;STRONG&gt;info_id&lt;/STRONG&gt; and &lt;STRONG&gt;info_time&lt;/STRONG&gt; would be event fields from an index.&lt;BR /&gt;
something like index=infologs |&lt;CODE&gt;getinfo(info_id,info_time)&lt;/CODE&gt;&lt;/P&gt;

&lt;P&gt;Thanks.&lt;BR /&gt;
Mukund&lt;/P&gt;</description>
      <pubDate>Thu, 12 Jan 2017 20:43:39 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Knowledge-Management/Is-it-possible-to-pass-an-event-field-as-an-argument-to-a-macro/m-p/237614#M2060</guid>
      <dc:creator>mnm1987</dc:creator>
      <dc:date>2017-01-12T20:43:39Z</dc:date>
    </item>
    <item>
      <title>Re: Is it possible to pass an event field as an argument to a macro?</title>
      <link>https://community.splunk.com/t5/Knowledge-Management/Is-it-possible-to-pass-an-event-field-as-an-argument-to-a-macro/m-p/237615#M2061</link>
      <description>&lt;P&gt;Yes you can. &lt;A href="http://docs.splunk.com/Documentation/Splunk/6.5.1/Knowledge/Searchmacroexamples#Validating_arguments_to_determine_whether_or_not_they_are_numeric"&gt;Have a look here&lt;/A&gt; as an example which uses &lt;CODE&gt;revenue&lt;/CODE&gt; field being passed with another &lt;CODE&gt;rate&lt;/CODE&gt; value which then get multiplied inside the macro.&lt;/P&gt;

&lt;P&gt;Example in its simplest terms:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;GoTo Settings»  Advanced search » Search macros » Add new
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Update in the sections &lt;CODE&gt;Name&lt;/CODE&gt;, &lt;CODE&gt;Definition&lt;/CODE&gt; and &lt;CODE&gt;Argument&lt;/CODE&gt; respectively as &lt;CODE&gt;multiplyABC(3)&lt;/CODE&gt;, &lt;CODE&gt;eval dd=$a$*$b$*$c$&lt;/CODE&gt;, &lt;CODE&gt;a,b,c&lt;/CODE&gt;&lt;BR /&gt;
Call it as follows:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;`multiplyABC(field1,field2,field3)`
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 12 Jan 2017 23:07:11 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Knowledge-Management/Is-it-possible-to-pass-an-event-field-as-an-argument-to-a-macro/m-p/237615#M2061</guid>
      <dc:creator>gokadroid</dc:creator>
      <dc:date>2017-01-12T23:07:11Z</dc:date>
    </item>
    <item>
      <title>Re: Is it possible to pass an event field as an argument to a macro?</title>
      <link>https://community.splunk.com/t5/Knowledge-Management/Is-it-possible-to-pass-an-event-field-as-an-argument-to-a-macro/m-p/237616#M2062</link>
      <description>&lt;P&gt;gokadroid - Thanks for the response, I understand that the above steps are handy when creating a macro with Arguments.&lt;/P&gt;

&lt;P&gt;But my requirement was to be able to specify or call the macro in the following way&lt;BR /&gt;
index="blah" |&lt;CODE&gt;multiplyABC(field1,field2,field3)&lt;/CODE&gt; &lt;BR /&gt;
where field1,field2 and field3 are not explicitly hardcoded values, instead they are Fields in the events found for index="blah".&lt;/P&gt;

&lt;P&gt;Based on my observation, passing event fields get treated literally instead of interpreting their values, i.e.&lt;BR /&gt;
the expanded macro search would look as follows&lt;/P&gt;

&lt;P&gt;eval dd=field1*field2*field3&lt;/P&gt;</description>
      <pubDate>Tue, 29 Sep 2020 12:27:29 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Knowledge-Management/Is-it-possible-to-pass-an-event-field-as-an-argument-to-a-macro/m-p/237616#M2062</guid>
      <dc:creator>mnm1987</dc:creator>
      <dc:date>2020-09-29T12:27:29Z</dc:date>
    </item>
  </channel>
</rss>

