<?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 Using field values as paramaters for macros in Reporting</title>
    <link>https://community.splunk.com/t5/Reporting/Using-field-values-as-paramaters-for-macros/m-p/14189#M159</link>
    <description>&lt;P&gt;I am trying to create a macro that would take as it's input the result of an eval earlier in the search string, for example:&lt;/P&gt;

&lt;P&gt;eval mytime=now() | &lt;CODE&gt;extract_duplicate(mytime)&lt;/CODE&gt;&lt;/P&gt;

&lt;P&gt;Is there a way to do this? mytime might even be substituted as part of a scheduled saved search (for example mytime=starttimeu) to collect summary index data.&lt;/P&gt;

&lt;P&gt;Running the search with a literal works fine:
&lt;CODE&gt;extract_duplicate(1271816301)&lt;/CODE&gt;&lt;/P&gt;</description>
    <pubDate>Tue, 25 May 2010 20:43:36 GMT</pubDate>
    <dc:creator>stephanbuys</dc:creator>
    <dc:date>2010-05-25T20:43:36Z</dc:date>
    <item>
      <title>Using field values as paramaters for macros</title>
      <link>https://community.splunk.com/t5/Reporting/Using-field-values-as-paramaters-for-macros/m-p/14189#M159</link>
      <description>&lt;P&gt;I am trying to create a macro that would take as it's input the result of an eval earlier in the search string, for example:&lt;/P&gt;

&lt;P&gt;eval mytime=now() | &lt;CODE&gt;extract_duplicate(mytime)&lt;/CODE&gt;&lt;/P&gt;

&lt;P&gt;Is there a way to do this? mytime might even be substituted as part of a scheduled saved search (for example mytime=starttimeu) to collect summary index data.&lt;/P&gt;

&lt;P&gt;Running the search with a literal works fine:
&lt;CODE&gt;extract_duplicate(1271816301)&lt;/CODE&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 25 May 2010 20:43:36 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Reporting/Using-field-values-as-paramaters-for-macros/m-p/14189#M159</guid>
      <dc:creator>stephanbuys</dc:creator>
      <dc:date>2010-05-25T20:43:36Z</dc:date>
    </item>
    <item>
      <title>Re: Using field values as paramaters for macros</title>
      <link>https://community.splunk.com/t5/Reporting/Using-field-values-as-paramaters-for-macros/m-p/14190#M160</link>
      <description>&lt;P&gt;No it is not possible. Macros are distinct from functions, and are simple string substitutions and do not pass values. For this you would need functions. It is possible to "almost" do it, but it would require you to rewrite the macro, e.g.,&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;[extract_duplicate(1)]
args = a1
definition = eval mytime = $a1$ | blah xxx=mytime
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;called with:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;`extract_duplicate(now())`
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Separately, you can't get &lt;CODE&gt;starttimeu&lt;/CODE&gt; either from within a search query. Also, &lt;CODE&gt;starttimeeu&lt;/CODE&gt; is deprecated in favor of &lt;CODE&gt;earliest&lt;/CODE&gt;.&lt;/P&gt;</description>
      <pubDate>Tue, 25 May 2010 21:02:27 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Reporting/Using-field-values-as-paramaters-for-macros/m-p/14190#M160</guid>
      <dc:creator>gkanapathy</dc:creator>
      <dc:date>2010-05-25T21:02:27Z</dc:date>
    </item>
    <item>
      <title>Re: Using field values as paramaters for macros</title>
      <link>https://community.splunk.com/t5/Reporting/Using-field-values-as-paramaters-for-macros/m-p/14191#M161</link>
      <description>&lt;P&gt;Hmm.  This is not an answer to your question, exactly, but I suspect that since your talking about passing time values into macros and you're looking to use this for summary indexing, then I suspect that you may be trying to post-filter your search with something like a &lt;CODE&gt;| where _time&amp;lt;my_field&lt;/CODE&gt;&lt;/P&gt;

&lt;P&gt;If I'm wrong about this, then you can just ignore the rest.&lt;/P&gt;

&lt;P&gt;&lt;/P&gt;&lt;HR /&gt;&lt;P&gt;&lt;/P&gt;

&lt;P&gt;I use the following macro as a post-search command that will drop off a given number of hours from the end of a search time range.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;[si_txn_trim_h(1)]
args = hours
definition = addinfo | where _time &amp;lt; (info_max_time-($hours$*3600)) | fields - info_*
iseval = 0
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;I use the &lt;CODE&gt;addinfo&lt;/CODE&gt; search command to get the &lt;CODE&gt;info_max_time&lt;/CODE&gt; (or you can use the &lt;CODE&gt;info_min_time&lt;/CODE&gt;, if you want the &lt;CODE&gt;earliest&lt;/CODE&gt; value instead of the &lt;CODE&gt;latest&lt;/CODE&gt; value).&lt;/P&gt;

&lt;P&gt;Also note that I wrote this for Splunk 4.0.  Now, I would recommend instead using the &lt;CODE&gt;relative_time&lt;/CODE&gt; eval function instead of assuming "hours", which would be much more flexible.  But for the purpose of comparison, I suspect I would replace this with the following in 4.1:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;definition = addinfo | where _time &amp;lt; relative_time(info_max_time,"-$hours$h") | fields - info_*
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 26 May 2010 00:11:11 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Reporting/Using-field-values-as-paramaters-for-macros/m-p/14191#M161</guid>
      <dc:creator>Lowell</dc:creator>
      <dc:date>2010-05-26T00:11:11Z</dc:date>
    </item>
    <item>
      <title>Re: Using field values as paramaters for macros</title>
      <link>https://community.splunk.com/t5/Reporting/Using-field-values-as-paramaters-for-macros/m-p/14192#M162</link>
      <description>&lt;P&gt;This is a great tip, I have also verified that you can use addinfo in subsearches of a scheduled search, so this will solve my problem. Thanks!&lt;/P&gt;</description>
      <pubDate>Thu, 27 May 2010 13:22:47 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Reporting/Using-field-values-as-paramaters-for-macros/m-p/14192#M162</guid>
      <dc:creator>stephanbuys</dc:creator>
      <dc:date>2010-05-27T13:22:47Z</dc:date>
    </item>
    <item>
      <title>Re: Using field values as paramaters for macros</title>
      <link>https://community.splunk.com/t5/Reporting/Using-field-values-as-paramaters-for-macros/m-p/14193#M163</link>
      <description>&lt;P&gt;Thank you! We were looking for function capabilities, but Lowell's solution will help us to get the search working.&lt;/P&gt;</description>
      <pubDate>Thu, 27 May 2010 13:25:55 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Reporting/Using-field-values-as-paramaters-for-macros/m-p/14193#M163</guid>
      <dc:creator>stephanbuys</dc:creator>
      <dc:date>2010-05-27T13:25:55Z</dc:date>
    </item>
  </channel>
</rss>

