<?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 to use macro in first pipe to generate some strptime value in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-to-use-macro-in-first-pipe-to-generate-some-strptime-value/m-p/290711#M87846</link>
    <description>&lt;P&gt;Thank you both for your answers, my goal is to have it like @DalJeanis way, I need it before the first pipe with index and sourcetype to eliminate extra work for Splunk. Trying DalJeanies method at this point. &lt;/P&gt;</description>
    <pubDate>Wed, 16 Aug 2017 13:13:03 GMT</pubDate>
    <dc:creator>akocak</dc:creator>
    <dc:date>2017-08-16T13:13:03Z</dc:date>
    <item>
      <title>How to use macro in first pipe to generate some strptime value</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-use-macro-in-first-pipe-to-generate-some-strptime-value/m-p/290708#M87843</link>
      <description>&lt;P&gt;Hi , &lt;BR /&gt;
I have a Splunk DB Connect batch input that runs every 24 hours to get some table result set in Splunk. &lt;BR /&gt;
Over the time since the index kept growing, in order to get best performance and keep data more historically, I added a variable to my SQL query that adds one more fields as PULL_DATE in the format of "%Y-%m-%d"&lt;/P&gt;

&lt;P&gt;In Splunk, so far I called this in the second pipe as:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=x source=y    |where PULL_DATE =  strftime(now(), "%Y-%m-%d")
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;and my goal is to take value into first pipe that my searches would provide a better performance,&lt;/P&gt;

&lt;P&gt;so far I tried, strftime in the first pipe as a value, it doesn't work, Now I am trying to create a macro just to return me a value of.&lt;BR /&gt;
strftime(now(), "%Y-%m-%d") as it is mentioned in this answer. &lt;BR /&gt;
Splunk Answers: &lt;A href="https://answers.splunk.com/answers/209270/is-there-a-way-to-use-eval-before-the-initial-even.html"&gt;Is there a way to use eval before the initial event search (sourcetype=xx)?&lt;/A&gt;&lt;/P&gt;

&lt;P&gt;My macro definition is:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;![alt text][1]
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;I feel like i am close to what I need, however, I appreciate you all for your time reading this. &lt;/P&gt;</description>
      <pubDate>Tue, 15 Aug 2017 21:22:26 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-use-macro-in-first-pipe-to-generate-some-strptime-value/m-p/290708#M87843</guid>
      <dc:creator>akocak</dc:creator>
      <dc:date>2017-08-15T21:22:26Z</dc:date>
    </item>
    <item>
      <title>Re: How to use macro in first pipe to generate some strptime value</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-use-macro-in-first-pipe-to-generate-some-strptime-value/m-p/290709#M87844</link>
      <description>&lt;P&gt;This is your macro:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;search PULL_DATE = [|makeresults | eval _time = strftime(now(), "%Y-%m-%d") | eval _time = "\"" . _time . "\"" | return $_time]
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;You call it like this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=x source=y | `YourMacroNameHere`
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 15 Aug 2017 23:40:53 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-use-macro-in-first-pipe-to-generate-some-strptime-value/m-p/290709#M87844</guid>
      <dc:creator>woodcock</dc:creator>
      <dc:date>2017-08-15T23:40:53Z</dc:date>
    </item>
    <item>
      <title>Re: How to use macro in first pipe to generate some strptime value</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-use-macro-in-first-pipe-to-generate-some-strptime-value/m-p/290710#M87845</link>
      <description>&lt;P&gt;Or you could do it this way... &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt; [| makeresults | eval search = "PULL_DATE=\"".strftime(now(), "%Y-%m-%d")."\"" | return $search]
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;...and call it like this...&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;  index=x source=y `YourMacroNameHere`
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 16 Aug 2017 02:08:27 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-use-macro-in-first-pipe-to-generate-some-strptime-value/m-p/290710#M87845</guid>
      <dc:creator>DalJeanis</dc:creator>
      <dc:date>2017-08-16T02:08:27Z</dc:date>
    </item>
    <item>
      <title>Re: How to use macro in first pipe to generate some strptime value</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-use-macro-in-first-pipe-to-generate-some-strptime-value/m-p/290711#M87846</link>
      <description>&lt;P&gt;Thank you both for your answers, my goal is to have it like @DalJeanis way, I need it before the first pipe with index and sourcetype to eliminate extra work for Splunk. Trying DalJeanies method at this point. &lt;/P&gt;</description>
      <pubDate>Wed, 16 Aug 2017 13:13:03 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-use-macro-in-first-pipe-to-generate-some-strptime-value/m-p/290711#M87846</guid>
      <dc:creator>akocak</dc:creator>
      <dc:date>2017-08-16T13:13:03Z</dc:date>
    </item>
    <item>
      <title>Re: How to use macro in first pipe to generate some strptime value</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-use-macro-in-first-pipe-to-generate-some-strptime-value/m-p/290712#M87847</link>
      <description>&lt;P&gt;Thanks Both again, so I made it work, job inspector results are interesting:&lt;BR /&gt;
index=x sourcetype=y 'my_macro'&lt;BR /&gt;
31 results by scanning 458 events in 6.727 seconds&lt;BR /&gt;
index=x sourcetype=y |where PULL_DATE= strftime(now(), "%Y-%m-%d")&lt;BR /&gt;
31 results by scanning 1,276 events in 2.465 seconds&lt;BR /&gt;
index=x sourcetype=y PULL_DATE="2017-08-16"&lt;BR /&gt;
31 results by scanning 458 events in 1.948 seconds&lt;/P&gt;

&lt;P&gt;Macro added many seconds in performance although it limited scanned events. In my opinion, splunk should allow functions like strftime to be in the value before first pipe. &lt;BR /&gt;
Performance wise, Did you guys have similar experience ever? or have any suggestions? &lt;/P&gt;</description>
      <pubDate>Tue, 29 Sep 2020 15:22:21 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-use-macro-in-first-pipe-to-generate-some-strptime-value/m-p/290712#M87847</guid>
      <dc:creator>akocak</dc:creator>
      <dc:date>2020-09-29T15:22:21Z</dc:date>
    </item>
    <item>
      <title>Re: How to use macro in first pipe to generate some strptime value</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-use-macro-in-first-pipe-to-generate-some-strptime-value/m-p/290713#M87848</link>
      <description>&lt;P&gt;First, again, thank you both. I made it work out with DalJeanis solution, however, performance metrics are interesting&lt;BR /&gt;
if i use my search as &lt;BR /&gt;
index=x sourcetype=y 'my_macro'&lt;BR /&gt;&lt;BR /&gt;
31 results by scanning 458 events in 6.727 seconds&lt;BR /&gt;
index=x sourcetype=y | where PULL_DATE = strftime(now(), "%Y-%m-%d")  --&amp;gt; 7 seconds&lt;BR /&gt;
31 results by scanning 1,276 events in 2.465 seconds&lt;BR /&gt;
index=x sourcetype=y PULL_DATE = "2017-08-16"&lt;BR /&gt;
31 results by scanning 458 events in 1.948 seconds&lt;/P&gt;

&lt;P&gt;looks like old way of doing this is faster others. &lt;BR /&gt;
would you guys enlighten me little as why what i expected is not there ? &lt;BR /&gt;
Moreover, Could you move your answer to below for me to validate as right answer (will validate both)&lt;/P&gt;</description>
      <pubDate>Tue, 29 Sep 2020 15:22:24 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-use-macro-in-first-pipe-to-generate-some-strptime-value/m-p/290713#M87848</guid>
      <dc:creator>akocak</dc:creator>
      <dc:date>2020-09-29T15:22:24Z</dc:date>
    </item>
    <item>
      <title>Re: How to use macro in first pipe to generate some strptime value</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-use-macro-in-first-pipe-to-generate-some-strptime-value/m-p/290714#M87849</link>
      <description>&lt;P&gt;Hard code is always going to be faster than running a subsearch, that's just common sense.&lt;/P&gt;

&lt;P&gt;Try it with a second eval macro that just always returns PULL_DATE="2017-08-16", and you can see how much of that 4.8 seconds difference is macro and how much is subsearch.&lt;/P&gt;

&lt;P&gt;You can also verify that by inserting the macro code directly into the search and seeing where on the spectrum it comes out.&lt;/P&gt;</description>
      <pubDate>Wed, 16 Aug 2017 15:29:55 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-use-macro-in-first-pipe-to-generate-some-strptime-value/m-p/290714#M87849</guid>
      <dc:creator>DalJeanis</dc:creator>
      <dc:date>2017-08-16T15:29:55Z</dc:date>
    </item>
    <item>
      <title>Re: How to use macro in first pipe to generate some strptime value</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-use-macro-in-first-pipe-to-generate-some-strptime-value/m-p/290715#M87850</link>
      <description>&lt;P&gt;@akocak - moved the comment to answer so that you can accept it and close the question.&lt;/P&gt;</description>
      <pubDate>Wed, 16 Aug 2017 15:35:47 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-use-macro-in-first-pipe-to-generate-some-strptime-value/m-p/290715#M87850</guid>
      <dc:creator>DalJeanis</dc:creator>
      <dc:date>2017-08-16T15:35:47Z</dc:date>
    </item>
  </channel>
</rss>

