<?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: Can you use now() in eval-based macros? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Can-you-use-now-in-eval-based-macros/m-p/18279#M2634</link>
    <description>&lt;P&gt;Does it work if you use strftime() instead of tostring()?&lt;/P&gt;</description>
    <pubDate>Thu, 22 Jul 2010 05:59:59 GMT</pubDate>
    <dc:creator>gkanapathy</dc:creator>
    <dc:date>2010-07-22T05:59:59Z</dc:date>
    <item>
      <title>Can you use now() in eval-based macros?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Can-you-use-now-in-eval-based-macros/m-p/18278#M2633</link>
      <description>&lt;P&gt;Is it possible to use the &lt;CODE&gt;now()&lt;/CODE&gt; function in an macro?  And if so, are there any specific limitations?&lt;/P&gt;

&lt;P&gt;&amp;lt;p&amp;gt;Example macro:&amp;lt;/p&amp;gt;&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;[test_macro]
definition = tostring(now())
iseval = 1
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Trying to use this macro returns the following error message on the search screen:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;Error in 'SearchParser': The definition of macro 'test_macro' is expected to be an eval expression that returns a string.
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;&lt;STRONG&gt;Update:&lt;/STRONG&gt;  For the purpose of demonstration, here are other macro definitions I tried when attempting to track this down:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;[test_macro]
definition = now()
iseval = 1

[test_macro]
definition = strftime((now(), "%H:%M")
iseval = 1

[test_macro]
definition = a_non_existant_function()
iseval = 1
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;I see the same error message for all of these different macros.&lt;/P&gt;

&lt;P&gt;This last test makes me think that the within the context of a macro, splunk sees &lt;CODE&gt;now()&lt;/CODE&gt; just like "a_non_existant_function()" (which obviously doesn't exist).   It would be nice to get a more specific error message saying that the eval is invalid because of a non-existing function.&lt;/P&gt;</description>
      <pubDate>Mon, 28 Sep 2020 09:10:31 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Can-you-use-now-in-eval-based-macros/m-p/18278#M2633</guid>
      <dc:creator>Lowell</dc:creator>
      <dc:date>2020-09-28T09:10:31Z</dc:date>
    </item>
    <item>
      <title>Re: Can you use now() in eval-based macros?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Can-you-use-now-in-eval-based-macros/m-p/18279#M2634</link>
      <description>&lt;P&gt;Does it work if you use strftime() instead of tostring()?&lt;/P&gt;</description>
      <pubDate>Thu, 22 Jul 2010 05:59:59 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Can-you-use-now-in-eval-based-macros/m-p/18279#M2634</guid>
      <dc:creator>gkanapathy</dc:creator>
      <dc:date>2010-07-22T05:59:59Z</dc:date>
    </item>
    <item>
      <title>Re: Can you use now() in eval-based macros?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Can-you-use-now-in-eval-based-macros/m-p/18280#M2635</link>
      <description>&lt;P&gt;No using &lt;CODE&gt;strftime()&lt;/CODE&gt; doesn't make a difference.  I've added a few more examples of things I've tried to my question.  Seems like "now()" is unknown within the eval-based macro expansion.&lt;/P&gt;</description>
      <pubDate>Thu, 22 Jul 2010 22:23:09 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Can-you-use-now-in-eval-based-macros/m-p/18280#M2635</guid>
      <dc:creator>Lowell</dc:creator>
      <dc:date>2010-07-22T22:23:09Z</dc:date>
    </item>
    <item>
      <title>Re: Can you use now() in eval-based macros?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Can-you-use-now-in-eval-based-macros/m-p/18281#M2636</link>
      <description>&lt;P&gt;Looks like a bug.&lt;/P&gt;</description>
      <pubDate>Thu, 22 Jul 2010 23:13:11 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Can-you-use-now-in-eval-based-macros/m-p/18281#M2636</guid>
      <dc:creator>gkanapathy</dc:creator>
      <dc:date>2010-07-22T23:13:11Z</dc:date>
    </item>
    <item>
      <title>Re: Can you use now() in eval-based macros?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Can-you-use-now-in-eval-based-macros/m-p/18282#M2637</link>
      <description>&lt;P&gt;I opened a case with splunk support.  Thanks.&lt;/P&gt;</description>
      <pubDate>Fri, 23 Jul 2010 01:40:29 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Can-you-use-now-in-eval-based-macros/m-p/18282#M2637</guid>
      <dc:creator>Lowell</dc:creator>
      <dc:date>2010-07-23T01:40:29Z</dc:date>
    </item>
    <item>
      <title>Re: Can you use now() in eval-based macros?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Can-you-use-now-in-eval-based-macros/m-p/18283#M2638</link>
      <description>&lt;P&gt;Are you sure you want an eval-based definition?  What is your use case?&lt;/P&gt;

&lt;P&gt;If you want a macro that just evals to a string that represents the current time, use &lt;CODE&gt;time()&lt;/CODE&gt; instead of &lt;CODE&gt;now()&lt;/CODE&gt;&lt;/P&gt;

&lt;P&gt;&lt;CODE&gt;time()&lt;/CODE&gt; is the wall clock time.  &lt;CODE&gt;now()&lt;/CODE&gt; is the "nominal" start time of the search.  For example, the scheduler may run a search that is supposed to start at 2PM but really started at 2:15pm, &lt;CODE&gt;now()&lt;/CODE&gt; would still be 2pm)&lt;/P&gt;

&lt;P&gt;Therefore, &lt;CODE&gt;now()&lt;/CODE&gt; relys on run-time search info, which is not available for macro expansion.  A macro needs to be able to be expanded outside the scope of a particular search.&lt;/P&gt;

&lt;P&gt;There's some functions that are available in the eval command that are not available for eval-based macros.  These include:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;now()
searchmatch()
mvindex()
mvcount()
mvjoin()
commands()
split()
mvappend()
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Basically, any function that needs manipulates search-search-result specific information (e.g., multi-value fields, the search that was run, etc)&lt;/P&gt;</description>
      <pubDate>Fri, 23 Jul 2010 04:30:14 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Can-you-use-now-in-eval-based-macros/m-p/18283#M2638</guid>
      <dc:creator>steveyz</dc:creator>
      <dc:date>2010-07-23T04:30:14Z</dc:date>
    </item>
    <item>
      <title>Re: Can you use now() in eval-based macros?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Can-you-use-now-in-eval-based-macros/m-p/18284#M2639</link>
      <description>&lt;P&gt;Note that none of this applies if you aren't using an eval-based definition.  Simple definitions are just doing text replacement, so anything goes.&lt;/P&gt;</description>
      <pubDate>Fri, 23 Jul 2010 04:31:26 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Can-you-use-now-in-eval-based-macros/m-p/18284#M2639</guid>
      <dc:creator>steveyz</dc:creator>
      <dc:date>2010-07-23T04:31:26Z</dc:date>
    </item>
    <item>
      <title>Re: Can you use now() in eval-based macros?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Can-you-use-now-in-eval-based-macros/m-p/18285#M2640</link>
      <description>&lt;P&gt;Thanks, that answers my question.  I was guessing that the answer had something to do with runtime search info.  FYI, my use case is here: &lt;A href="http://answers.splunk.com/questions/4528/finding-your-local-timezone-with-eval/4909#4909"&gt;http://answers.splunk.com/questions/4528/finding-your-local-timezone-with-eval/4909#4909&lt;/A&gt;.&lt;/P&gt;</description>
      <pubDate>Mon, 02 Aug 2010 22:11:38 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Can-you-use-now-in-eval-based-macros/m-p/18285#M2640</guid>
      <dc:creator>Lowell</dc:creator>
      <dc:date>2010-08-02T22:11:38Z</dc:date>
    </item>
    <item>
      <title>Re: Can you use now() in eval-based macros?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Can-you-use-now-in-eval-based-macros/m-p/18286#M2641</link>
      <description>&lt;P&gt;Is &lt;CODE&gt;mvappend()&lt;/CODE&gt; new function?  Its not in the docs, but I had submitted a feature request for such a function)&lt;/P&gt;</description>
      <pubDate>Mon, 02 Aug 2010 22:12:50 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Can-you-use-now-in-eval-based-macros/m-p/18286#M2641</guid>
      <dc:creator>Lowell</dc:creator>
      <dc:date>2010-08-02T22:12:50Z</dc:date>
    </item>
    <item>
      <title>Re: Can you use now() in eval-based macros?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Can-you-use-now-in-eval-based-macros/m-p/18287#M2642</link>
      <description>&lt;P&gt;yes mvappend() is new to 4.1+&lt;/P&gt;</description>
      <pubDate>Tue, 03 Aug 2010 03:38:26 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Can-you-use-now-in-eval-based-macros/m-p/18287#M2642</guid>
      <dc:creator>steveyz</dc:creator>
      <dc:date>2010-08-03T03:38:26Z</dc:date>
    </item>
    <item>
      <title>Re: Can you use now() in eval-based macros?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Can-you-use-now-in-eval-based-macros/m-p/18288#M2643</link>
      <description>&lt;P&gt;An eval based macro must return a string.&lt;BR /&gt;
tostring(now()) is not a string ... dough ! &lt;BR /&gt;
you need to ensapsulate it with double quotes&lt;BR /&gt;
&lt;CODE&gt;[macronow]&lt;BR /&gt;
 definition = "tostring(now())"&lt;BR /&gt;
 iseval = 1&lt;/CODE&gt;&lt;/P&gt;

&lt;P&gt;To test with&lt;BR /&gt;
&lt;CODE&gt;|makeresults count=2  |eval show=strftime(&lt;CODE&gt;macronow&lt;/CODE&gt;,"%D %T")&lt;/CODE&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 30 Oct 2018 12:47:27 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Can-you-use-now-in-eval-based-macros/m-p/18288#M2643</guid>
      <dc:creator>ldongradi_SPL</dc:creator>
      <dc:date>2018-10-30T12:47:27Z</dc:date>
    </item>
    <item>
      <title>Re: Can you use now() in eval-based macros?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Can-you-use-now-in-eval-based-macros/m-p/678557#M232036</link>
      <description>&lt;P&gt;you are 200% correct.&amp;nbsp;&lt;BR /&gt;to use iseval = 1&amp;nbsp;&lt;BR /&gt;we must specify the definition within double quotes.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 24 Feb 2024 03:31:46 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Can-you-use-now-in-eval-based-macros/m-p/678557#M232036</guid>
      <dc:creator>thambisetty</dc:creator>
      <dc:date>2024-02-24T03:31:46Z</dc:date>
    </item>
  </channel>
</rss>

