<?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 Sanity check: using makeresults and a case for earliest/latest in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Sanity-check-using-makeresults-and-a-case-for-earliest-latest/m-p/680961#M232722</link>
    <description>&lt;P&gt;In a perfect world I'd find a way to get this into the time picker,&lt;BR /&gt;but I haven't seen suggestions for that (please warn me if I've&lt;BR /&gt;missed something).&lt;/P&gt;
&lt;P&gt;Q:&amp;nbsp; Is the solution I've found for dealing with previous business&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; day workable or have I missed an edge case that people have&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; seen before (e.g., it blows up in cron)?&lt;BR /&gt;&lt;BR /&gt;Thanks&lt;/P&gt;
&lt;P&gt;I'm trying to find some way to evaluate a window time during a&lt;BR /&gt;business week. Goal is having a dashboard w/ drilldown to the&lt;BR /&gt;previous business day (for comparison to the main graph giving&lt;BR /&gt;today's data). This means processing last Friday on Monday.&lt;/P&gt;
&lt;P&gt;The basic question has been asked any number of times but the&lt;BR /&gt;answers vary in complexity.&lt;/P&gt;
&lt;P&gt;The simplest approach I could find was using a 3-day window in&lt;BR /&gt;the time picker and then adding an earliest/latest value via&lt;BR /&gt;sub-select to limit the data:&lt;/P&gt;
&lt;P&gt;&lt;A href="https://community.splunk.com/t5/Splunk-Search/How-to-to-dynamically-change-earliest-amp-latest-in-subsearch-to/m-p/631220" target="_blank" rel="noopener"&gt;https://community.splunk.com/t5/Splunk-Search/How-to-to-dynamically-change-earliest-amp-latest-in-subsearch-to/m-p/631220&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;The approach of:&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;&amp;lt;your index search&amp;gt; [
search index=summary source="summaryName" sourcetype=stash search_name="summaryName field1=*
| stats count by _time
| streamstats window=2 range(_time) as interval
| where interval &amp;gt; 60 * 15
| eval earliest=_time-interval+900, latest=_time
| fields earliest latest ]

&lt;/LI-CODE&gt;
&lt;P&gt;Seems simple enough: Generate an earliest/latest based on the weekday.&lt;/P&gt;
&lt;P&gt;Applying this to my specific case of business hours during&lt;BR /&gt;the business week I get this with a case on the weekday from&lt;BR /&gt;makeresults, which at least seems like a lightweight solution:&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;index="foo"
[
  | makeresults
  | eval wkday = strftime( _time, "%a" )
  | eval earliest = case( wkday = "Mon", "-3d@d+8h", wkday = "Sun", "-2d@d+8h", wkday = "Sat", "-1d@d+8h", 1=1, "@d+8h" )
  | eval latest = case( wkday = "Mon", "-3d@d+17h", wkday = "Sun", "-2d@d+17h", wkday = "Sat", "-1d@d+17h", 1=1, "@d+17h" )
  | fields earliest latest
]
| stats earliest( _time ) as prior latest( _time ) as after

| eval prior = strftime( prior, "%Y.%m.%d %H:%M:%S" )
| eval after = strftime( after, "%Y.%m.%d %H:%M:%S" )

| table prior after

&lt;/LI-CODE&gt;
&lt;P&gt;And even seems to work: on Sunday the 17th I get:&lt;/P&gt;
&lt;P&gt;prior&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; after&lt;BR /&gt;2024.03.15 08:00:00 2024.03.15 16:59:59&lt;/P&gt;
&lt;P&gt;Only question now is whether there is some edge case I've missed&lt;BR /&gt;(e.g., running via crontab) where the makeresults will generate an&lt;BR /&gt;offball time or something.&lt;/P&gt;
&lt;P&gt;Thanks&lt;/P&gt;</description>
    <pubDate>Sun, 17 Mar 2024 19:37:24 GMT</pubDate>
    <dc:creator>lembark</dc:creator>
    <dc:date>2024-03-17T19:37:24Z</dc:date>
    <item>
      <title>Sanity check: using makeresults and a case for earliest/latest</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Sanity-check-using-makeresults-and-a-case-for-earliest-latest/m-p/680961#M232722</link>
      <description>&lt;P&gt;In a perfect world I'd find a way to get this into the time picker,&lt;BR /&gt;but I haven't seen suggestions for that (please warn me if I've&lt;BR /&gt;missed something).&lt;/P&gt;
&lt;P&gt;Q:&amp;nbsp; Is the solution I've found for dealing with previous business&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; day workable or have I missed an edge case that people have&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; seen before (e.g., it blows up in cron)?&lt;BR /&gt;&lt;BR /&gt;Thanks&lt;/P&gt;
&lt;P&gt;I'm trying to find some way to evaluate a window time during a&lt;BR /&gt;business week. Goal is having a dashboard w/ drilldown to the&lt;BR /&gt;previous business day (for comparison to the main graph giving&lt;BR /&gt;today's data). This means processing last Friday on Monday.&lt;/P&gt;
&lt;P&gt;The basic question has been asked any number of times but the&lt;BR /&gt;answers vary in complexity.&lt;/P&gt;
&lt;P&gt;The simplest approach I could find was using a 3-day window in&lt;BR /&gt;the time picker and then adding an earliest/latest value via&lt;BR /&gt;sub-select to limit the data:&lt;/P&gt;
&lt;P&gt;&lt;A href="https://community.splunk.com/t5/Splunk-Search/How-to-to-dynamically-change-earliest-amp-latest-in-subsearch-to/m-p/631220" target="_blank" rel="noopener"&gt;https://community.splunk.com/t5/Splunk-Search/How-to-to-dynamically-change-earliest-amp-latest-in-subsearch-to/m-p/631220&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;The approach of:&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;&amp;lt;your index search&amp;gt; [
search index=summary source="summaryName" sourcetype=stash search_name="summaryName field1=*
| stats count by _time
| streamstats window=2 range(_time) as interval
| where interval &amp;gt; 60 * 15
| eval earliest=_time-interval+900, latest=_time
| fields earliest latest ]

&lt;/LI-CODE&gt;
&lt;P&gt;Seems simple enough: Generate an earliest/latest based on the weekday.&lt;/P&gt;
&lt;P&gt;Applying this to my specific case of business hours during&lt;BR /&gt;the business week I get this with a case on the weekday from&lt;BR /&gt;makeresults, which at least seems like a lightweight solution:&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;index="foo"
[
  | makeresults
  | eval wkday = strftime( _time, "%a" )
  | eval earliest = case( wkday = "Mon", "-3d@d+8h", wkday = "Sun", "-2d@d+8h", wkday = "Sat", "-1d@d+8h", 1=1, "@d+8h" )
  | eval latest = case( wkday = "Mon", "-3d@d+17h", wkday = "Sun", "-2d@d+17h", wkday = "Sat", "-1d@d+17h", 1=1, "@d+17h" )
  | fields earliest latest
]
| stats earliest( _time ) as prior latest( _time ) as after

| eval prior = strftime( prior, "%Y.%m.%d %H:%M:%S" )
| eval after = strftime( after, "%Y.%m.%d %H:%M:%S" )

| table prior after

&lt;/LI-CODE&gt;
&lt;P&gt;And even seems to work: on Sunday the 17th I get:&lt;/P&gt;
&lt;P&gt;prior&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; after&lt;BR /&gt;2024.03.15 08:00:00 2024.03.15 16:59:59&lt;/P&gt;
&lt;P&gt;Only question now is whether there is some edge case I've missed&lt;BR /&gt;(e.g., running via crontab) where the makeresults will generate an&lt;BR /&gt;offball time or something.&lt;/P&gt;
&lt;P&gt;Thanks&lt;/P&gt;</description>
      <pubDate>Sun, 17 Mar 2024 19:37:24 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Sanity-check-using-makeresults-and-a-case-for-earliest-latest/m-p/680961#M232722</guid>
      <dc:creator>lembark</dc:creator>
      <dc:date>2024-03-17T19:37:24Z</dc:date>
    </item>
    <item>
      <title>Re: Sanity check: using makeresults and a case for earliest/latest</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Sanity-check-using-makeresults-and-a-case-for-earliest-latest/m-p/680965#M232724</link>
      <description>&lt;P&gt;Assuming you just want to go back to the previous Friday, if it is Saturday, Sunday or Monday, or the previous day otherwise, you could use addinfo to get the start of the search period and reset the earliest and latest like this&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;index="foo" [
| makeresults 
| fields - _time
| addinfo
| eval num=(tonumber(strftime(info_min_time, "%w"))+5)%7
| eval shift=if(num&amp;lt;4, -1, -num+3)
| eval earliest=relative_time(info_min_time,shift."d@d+8h")
| eval latest=relative_time(earliest,"+9h")
| fields earliest latest
]&lt;/LI-CODE&gt;</description>
      <pubDate>Sun, 17 Mar 2024 22:10:03 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Sanity-check-using-makeresults-and-a-case-for-earliest-latest/m-p/680965#M232724</guid>
      <dc:creator>ITWhisperer</dc:creator>
      <dc:date>2024-03-17T22:10:03Z</dc:date>
    </item>
  </channel>
</rss>

