<?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 Dynamic time range in Splunk query in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Dynamic-time-range-in-Splunk-query/m-p/575219#M200440</link>
    <description>&lt;P&gt;&lt;SPAN&gt;Hi&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;I write the Splunk query below to monitor server log&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;index="abc" sourcetype="abc" login "response.status"=200 source="abc.log"&lt;BR /&gt;| timechart span=2m count&lt;BR /&gt;| timewrap d series=short&lt;BR /&gt;| addtotals s*&lt;BR /&gt;| eval daysAvg=round(Total/14.0,0)&lt;BR /&gt;| eval yesterday_time=strftime(_time,"%H:%M")&lt;BR /&gt;| table _time, yesterday_time, s0, daysAvg,s6 | outputlookup openapi_login_last_days_lam.csv&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-center" image-alt="1.png" style="width: 999px;"&gt;&lt;img src="https://community.splunk.com/t5/image/serverpage/image-id/16883iA08EB0641C12A991/image-size/large?v=v2&amp;amp;px=999" role="button" title="1.png" alt="1.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;However, my query is rely on time range to count&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;daysAvg&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;value, for example in this case time range is 14 day so&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;eval daysAvg=round(Total/14.0,0).&lt;/P&gt;&lt;P&gt;I want to calculate&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;daysAvg&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;dynamic. That means I don't need to change time range value when I apply other range.&lt;/P&gt;&lt;P&gt;To achieve that, I wrote code to calculate time range like this&lt;/P&gt;&lt;P&gt;index="abc" sourcetype="abc" login "response.status"=200 source="abc.log"&lt;BR /&gt;&amp;nbsp; &amp;nbsp;| stats earliest(_time) as earliest_time&lt;BR /&gt;&amp;nbsp; &amp;nbsp;| eval latest_time=now()&lt;BR /&gt;&amp;nbsp; &amp;nbsp;| eval difference=floor((latest_time-earliest_time)/(3600*24))&lt;BR /&gt;&amp;nbsp; &amp;nbsp;| table earliest_time, latest_time, difference&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-center" image-alt="2.png" style="width: 999px;"&gt;&lt;img src="https://community.splunk.com/t5/image/serverpage/image-id/16884i41ED69FC0296AFCC/image-size/large?v=v2&amp;amp;px=999" role="button" title="2.png" alt="2.png" /&gt;&lt;/span&gt;&lt;SPAN&gt;Finally, I combine two search like this&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;index="abc" sourcetype="abc" login&lt;BR /&gt;"response.status"=200 source="abc.log"&lt;BR /&gt;| timechart span=2m count&lt;BR /&gt;| timewrap d series=short&lt;BR /&gt;| addtotals s*&lt;BR /&gt;| append&lt;BR /&gt;&amp;nbsp; &amp;nbsp; [ search index="abc" sourcetype="abc" login "response.status"=200 source="abc.log"&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; | stats earliest(_time) as earliest_time&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; | eval earliest=earliest_time&lt;BR /&gt;&amp;nbsp; &amp;nbsp; ]&lt;BR /&gt;| eval latest_time=now()&lt;BR /&gt;| eval daysAvg=round(Total/14.0,0)&lt;BR /&gt;| eval yesterday_time=strftime(_time,"%H:%M")&lt;BR /&gt;| table _time, yesterday_time, s0, daysAvg, s6, latest_time, earliest&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-center" image-alt="3.png" style="width: 999px;"&gt;&lt;img src="https://community.splunk.com/t5/image/serverpage/image-id/16885i3598D00D2217F09A/image-size/large?v=v2&amp;amp;px=999" role="button" title="3.png" alt="3.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;But&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;earliest&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;from subsearch did not pass to outer search.&lt;/P&gt;&lt;P&gt;Please help me.&lt;/P&gt;&lt;P&gt;Thank you&lt;/P&gt;</description>
    <pubDate>Wed, 17 Nov 2021 08:36:39 GMT</pubDate>
    <dc:creator>lamnguyentt1</dc:creator>
    <dc:date>2021-11-17T08:36:39Z</dc:date>
    <item>
      <title>Dynamic time range in Splunk query</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Dynamic-time-range-in-Splunk-query/m-p/575219#M200440</link>
      <description>&lt;P&gt;&lt;SPAN&gt;Hi&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;I write the Splunk query below to monitor server log&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;index="abc" sourcetype="abc" login "response.status"=200 source="abc.log"&lt;BR /&gt;| timechart span=2m count&lt;BR /&gt;| timewrap d series=short&lt;BR /&gt;| addtotals s*&lt;BR /&gt;| eval daysAvg=round(Total/14.0,0)&lt;BR /&gt;| eval yesterday_time=strftime(_time,"%H:%M")&lt;BR /&gt;| table _time, yesterday_time, s0, daysAvg,s6 | outputlookup openapi_login_last_days_lam.csv&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-center" image-alt="1.png" style="width: 999px;"&gt;&lt;img src="https://community.splunk.com/t5/image/serverpage/image-id/16883iA08EB0641C12A991/image-size/large?v=v2&amp;amp;px=999" role="button" title="1.png" alt="1.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;However, my query is rely on time range to count&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;daysAvg&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;value, for example in this case time range is 14 day so&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;eval daysAvg=round(Total/14.0,0).&lt;/P&gt;&lt;P&gt;I want to calculate&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;daysAvg&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;dynamic. That means I don't need to change time range value when I apply other range.&lt;/P&gt;&lt;P&gt;To achieve that, I wrote code to calculate time range like this&lt;/P&gt;&lt;P&gt;index="abc" sourcetype="abc" login "response.status"=200 source="abc.log"&lt;BR /&gt;&amp;nbsp; &amp;nbsp;| stats earliest(_time) as earliest_time&lt;BR /&gt;&amp;nbsp; &amp;nbsp;| eval latest_time=now()&lt;BR /&gt;&amp;nbsp; &amp;nbsp;| eval difference=floor((latest_time-earliest_time)/(3600*24))&lt;BR /&gt;&amp;nbsp; &amp;nbsp;| table earliest_time, latest_time, difference&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-center" image-alt="2.png" style="width: 999px;"&gt;&lt;img src="https://community.splunk.com/t5/image/serverpage/image-id/16884i41ED69FC0296AFCC/image-size/large?v=v2&amp;amp;px=999" role="button" title="2.png" alt="2.png" /&gt;&lt;/span&gt;&lt;SPAN&gt;Finally, I combine two search like this&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;index="abc" sourcetype="abc" login&lt;BR /&gt;"response.status"=200 source="abc.log"&lt;BR /&gt;| timechart span=2m count&lt;BR /&gt;| timewrap d series=short&lt;BR /&gt;| addtotals s*&lt;BR /&gt;| append&lt;BR /&gt;&amp;nbsp; &amp;nbsp; [ search index="abc" sourcetype="abc" login "response.status"=200 source="abc.log"&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; | stats earliest(_time) as earliest_time&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; | eval earliest=earliest_time&lt;BR /&gt;&amp;nbsp; &amp;nbsp; ]&lt;BR /&gt;| eval latest_time=now()&lt;BR /&gt;| eval daysAvg=round(Total/14.0,0)&lt;BR /&gt;| eval yesterday_time=strftime(_time,"%H:%M")&lt;BR /&gt;| table _time, yesterday_time, s0, daysAvg, s6, latest_time, earliest&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-center" image-alt="3.png" style="width: 999px;"&gt;&lt;img src="https://community.splunk.com/t5/image/serverpage/image-id/16885i3598D00D2217F09A/image-size/large?v=v2&amp;amp;px=999" role="button" title="3.png" alt="3.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;But&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;earliest&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;from subsearch did not pass to outer search.&lt;/P&gt;&lt;P&gt;Please help me.&lt;/P&gt;&lt;P&gt;Thank you&lt;/P&gt;</description>
      <pubDate>Wed, 17 Nov 2021 08:36:39 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Dynamic-time-range-in-Splunk-query/m-p/575219#M200440</guid>
      <dc:creator>lamnguyentt1</dc:creator>
      <dc:date>2021-11-17T08:36:39Z</dc:date>
    </item>
    <item>
      <title>Re: Dynamic time range in Splunk query</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Dynamic-time-range-in-Splunk-query/m-p/575223#M200442</link>
      <description>&lt;P&gt;To get the earliest and latest time used in the search, try addinfo&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| addinfo
| eval timespan=info_max_time-info_min_time
| eval partialdays=floor((timespan-1)/86400)+1&lt;/LI-CODE&gt;</description>
      <pubDate>Wed, 17 Nov 2021 08:55:36 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Dynamic-time-range-in-Splunk-query/m-p/575223#M200442</guid>
      <dc:creator>ITWhisperer</dc:creator>
      <dc:date>2021-11-17T08:55:36Z</dc:date>
    </item>
  </channel>
</rss>

