<?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: Time Token Parsing to unix epoch in Dashboards &amp; Visualizations</title>
    <link>https://community.splunk.com/t5/Dashboards-Visualizations/Time-Token-Parsing-to-unix-epoch/m-p/307219#M19570</link>
    <description>&lt;P&gt;@momoXD, since there are two time inputs, you would need to have four separate tokens.&lt;/P&gt;</description>
    <pubDate>Thu, 30 Nov 2017 08:33:56 GMT</pubDate>
    <dc:creator>niketn</dc:creator>
    <dc:date>2017-11-30T08:33:56Z</dc:date>
    <item>
      <title>Time Token Parsing to unix epoch</title>
      <link>https://community.splunk.com/t5/Dashboards-Visualizations/Time-Token-Parsing-to-unix-epoch/m-p/307214#M19565</link>
      <description>&lt;P&gt;I am building a dashboard where I want to overlay data from user choosen time period with another user choosen time period. For example yesterday's average transaction duration compared to today's  average transaction duration. As an orientation I use the &lt;BR /&gt;
Splunk Book( &lt;A href="https://www.splunk.com/goto/book"&gt;https://www.splunk.com/goto/book&lt;/A&gt;)  chapter "Charting Week Over Week Results" (pages 85ff.). &lt;/P&gt;

&lt;P&gt;So I created a dashboard with two time picker named past and present so the four tokens are accessible using statements like "$past.earliest$". However my code only works if the time tokens are set to a relative value like "1d@d" or "now" and don't work if a user uses a concrete point time (which means a unix-epoch time). Here is my current search:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=some_index some_field="someValue" earliest=$past.earliest$ latest=$present.latest$
 | eval dur_sec=duration/1000000 
 | eval marker = if ( (_time &amp;gt; relative_time(now(), "$past.earliest$") and _time &amp;lt; relative_time(now(),"$past.latest$")), "past", "today")
 | eval _time = if (marker=="past", _time + relative_time(now(),"$present.earliest$")-relative_time(now(),"$past.earliest$"), _time)
 | timechart span=30min max(dur_sec) by marker 
 | trendline sma5("past") as trend_last_week 
 | eval upperBound=if( isnotnull(trend_last_week), 'trend_last_week'*1.5,'past'*1.5),lowerBound=0 
 | eval isOutlier=if('today'&amp;gt;upperBound or 'today'&amp;lt;lowerBound,1,0)| where _time &amp;gt;= relative_time(now(),"$present.earliest$")| fields _time,"today",lowerBound,upperBound,isOutlier,*
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;As explained above this only works for relative time spans like "-1d@d" and "now". In simpler words this solution is not flexible enough.  I also suspect that there might be an error in the line were I am recalculating the "_time" values, but I'm not sure yet.&lt;/P&gt;

&lt;P&gt;Because of these problems, I thought about converting all values from my tokens to Unix Epoch Times with the following code: &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt; | eval past_earliest=if(isnum(tonumber("$past.earliest$",10)),"$past.earliest$",relative_time(now(),"$past.earliest$"))
    | eval past_latest=if(isnum(tonumber("$past.latest$",10)),"$past.latest$",relative_time(now(),"$past.latest$"))
    | eval present_earliest=if(isnum(tonumber("$present.earliest$",10)),"$present.earliest$",relative_time(now(),"$present.earliest$"))
    | eval present_latest=if(isnum(tonumber("$present.latest$",10)),"$present.latest$",relative_time(now(),"$present.latest$"))
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;This does not work if  one of the tokens contains a non-numeric value. In this case the whole search can't be run.  But I guess this code can be fixed but I don't know how. &lt;/P&gt;

&lt;P&gt;Maybe somehow can help me complete this workaround or even has an idea fro improvement of the original search.&lt;/P&gt;

&lt;P&gt;Any help is appreciated. &lt;/P&gt;</description>
      <pubDate>Wed, 29 Nov 2017 12:35:38 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Dashboards-Visualizations/Time-Token-Parsing-to-unix-epoch/m-p/307214#M19565</guid>
      <dc:creator>momoXD</dc:creator>
      <dc:date>2017-11-29T12:35:38Z</dc:date>
    </item>
    <item>
      <title>Re: Time Token Parsing to unix epoch</title>
      <link>https://community.splunk.com/t5/Dashboards-Visualizations/Time-Token-Parsing-to-unix-epoch/m-p/307215#M19566</link>
      <description>&lt;P&gt;Add these search stanza to your dashboard (no visualization, searches to define tokens) which will get the epoch time ranges from each of the time range picker in new tokens.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;&amp;lt;search&amp;gt;
   &amp;lt;query&amp;gt;| makeresults | addinfo | table info_min_time info_max_time&amp;lt;/query&amp;gt;
   &amp;lt;!-- use the value of earliest_tok --&amp;gt;
   &amp;lt;earliest&amp;gt;$past.earliest$&amp;lt;/earliest&amp;gt;
   &amp;lt;latest&amp;gt;$past.latest$&amp;lt;/latest&amp;gt;
   &amp;lt;finalized&amp;gt;        
        &amp;lt;condition&amp;gt;
            &amp;lt;set token="past_earliest"&amp;gt;$result.info_min_time$&amp;lt;/set&amp;gt;
            &amp;lt;set token="past_latest"&amp;gt;$result.info_max_time$&amp;lt;/set&amp;gt;
        &amp;lt;/condition&amp;gt;
   &amp;lt;/finalized&amp;gt;
&amp;lt;/search&amp;gt;
&amp;lt;search&amp;gt;
   &amp;lt;query&amp;gt;| makeresults | addinfo | table info_min_time info_max_time&amp;lt;/query&amp;gt;
   &amp;lt;!-- use the value of earliest_tok --&amp;gt;
   &amp;lt;earliest&amp;gt;$present.earliest$&amp;lt;/earliest&amp;gt;
   &amp;lt;latest&amp;gt;$present.latest$&amp;lt;/latest&amp;gt;
   &amp;lt;finalized&amp;gt;        
        &amp;lt;condition&amp;gt;
            &amp;lt;set token="preset_earliest"&amp;gt;$result.info_min_time$&amp;lt;/set&amp;gt;
            &amp;lt;set token="present_latest"&amp;gt;$result.info_max_time$&amp;lt;/set&amp;gt;
        &amp;lt;/condition&amp;gt;
   &amp;lt;/finalized&amp;gt;
&amp;lt;/search&amp;gt;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 29 Nov 2017 15:39:03 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Dashboards-Visualizations/Time-Token-Parsing-to-unix-epoch/m-p/307215#M19566</guid>
      <dc:creator>somesoni2</dc:creator>
      <dc:date>2017-11-29T15:39:03Z</dc:date>
    </item>
    <item>
      <title>Re: Time Token Parsing to unix epoch</title>
      <link>https://community.splunk.com/t5/Dashboards-Visualizations/Time-Token-Parsing-to-unix-epoch/m-p/307216#M19567</link>
      <description>&lt;P&gt;@momoXD, refer to my answer on two options to get epoch time timepicker control.&lt;/P&gt;

&lt;P&gt;&lt;A href="https://answers.splunk.com/answers/578984/running-one-of-two-searches-based-on-time-picker-s.html"&gt;https://answers.splunk.com/answers/578984/running-one-of-two-searches-based-on-time-picker-s.html&lt;/A&gt;&lt;/P&gt;

&lt;P&gt;Once you always get epoch time from Time Picker, you will have to change from &lt;CODE&gt;relative_time()&lt;/CODE&gt; to direct epoch time difference, so that epoch times i.e. instead of &lt;CODE&gt;_time &amp;gt; relative_time(now(), "$past.earliest$"&lt;/CODE&gt; use this &lt;CODE&gt;_time &amp;gt; $past.earliest$&lt;/CODE&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 29 Nov 2017 17:06:02 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Dashboards-Visualizations/Time-Token-Parsing-to-unix-epoch/m-p/307216#M19567</guid>
      <dc:creator>niketn</dc:creator>
      <dc:date>2017-11-29T17:06:02Z</dc:date>
    </item>
    <item>
      <title>Re: Time Token Parsing to unix epoch</title>
      <link>https://community.splunk.com/t5/Dashboards-Visualizations/Time-Token-Parsing-to-unix-epoch/m-p/307217#M19568</link>
      <description>&lt;P&gt;@somesoni2, I have added the note to my answer that since this method gets epoch earliest and latest time from Time Picker, the SPL should be modified to remove &lt;CODE&gt;relative_time()&lt;/CODE&gt; and compare _time with epoch earliest or latest time directly.&lt;/P&gt;</description>
      <pubDate>Wed, 29 Nov 2017 17:08:05 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Dashboards-Visualizations/Time-Token-Parsing-to-unix-epoch/m-p/307217#M19568</guid>
      <dc:creator>niketn</dc:creator>
      <dc:date>2017-11-29T17:08:05Z</dc:date>
    </item>
    <item>
      <title>Re: Time Token Parsing to unix epoch</title>
      <link>https://community.splunk.com/t5/Dashboards-Visualizations/Time-Token-Parsing-to-unix-epoch/m-p/307218#M19569</link>
      <description>&lt;P&gt;there's a typo in line 20 it say "preset_earliest" but I assume you mean "present_earliest". If this is not a typo please give reasons for changing my naming convention.&lt;/P&gt;</description>
      <pubDate>Tue, 29 Sep 2020 16:59:16 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Dashboards-Visualizations/Time-Token-Parsing-to-unix-epoch/m-p/307218#M19569</guid>
      <dc:creator>momoXD</dc:creator>
      <dc:date>2020-09-29T16:59:16Z</dc:date>
    </item>
    <item>
      <title>Re: Time Token Parsing to unix epoch</title>
      <link>https://community.splunk.com/t5/Dashboards-Visualizations/Time-Token-Parsing-to-unix-epoch/m-p/307219#M19570</link>
      <description>&lt;P&gt;@momoXD, since there are two time inputs, you would need to have four separate tokens.&lt;/P&gt;</description>
      <pubDate>Thu, 30 Nov 2017 08:33:56 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Dashboards-Visualizations/Time-Token-Parsing-to-unix-epoch/m-p/307219#M19570</guid>
      <dc:creator>niketn</dc:creator>
      <dc:date>2017-11-30T08:33:56Z</dc:date>
    </item>
    <item>
      <title>Re: Time Token Parsing to unix epoch</title>
      <link>https://community.splunk.com/t5/Dashboards-Visualizations/Time-Token-Parsing-to-unix-epoch/m-p/307220#M19571</link>
      <description>&lt;P&gt;That is totally clear. &lt;BR /&gt;
So let me rephrase my question why did  somesoni2 rename one token to "preset_earliest"  which is a synonym for "predefined" and didn't stick with the more meaningful name "present_earliest" where "present" means a point in time. &lt;BR /&gt;
Did he just forget an "n" or is there more to it?&lt;/P&gt;</description>
      <pubDate>Tue, 29 Sep 2020 16:59:22 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Dashboards-Visualizations/Time-Token-Parsing-to-unix-epoch/m-p/307220#M19571</guid>
      <dc:creator>momoXD</dc:creator>
      <dc:date>2020-09-29T16:59:22Z</dc:date>
    </item>
  </channel>
</rss>

