<?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 compare data in 2 time buckets and alert based on results? in Alerting</title>
    <link>https://community.splunk.com/t5/Alerting/How-to-compare-data-in-2-time-buckets-and-alert-based-on-results/m-p/235694#M4408</link>
    <description>&lt;P&gt;My bad in the above search, there was an extra pipe. But if I remove it&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=trendingnow sourcetype=yapache_access_trending status=200 colo=bf1 url="/tn?category=general&amp;amp;locale=en_us&amp;amp;source=mobile_distro"
date_minute&amp;gt;=30 earliest=-24h@h date_hour=eval strftime(_time, "%H") |
stats c as count1 |
appendcols [search index=trendingnow sourcetype=yapache_access_trending status=200 colo=bf1
url="/tn?category=general&amp;amp;locale=en_us&amp;amp;source=mobile_distro"
date_minute&amp;gt;=30 earliest=-7d@d date_hour=eval strftime(_time, "%H") |
stats count(url) as count2] | 
eval count3=round(count2/7,0) | 
eval issue1=if(count1&amp;lt;=(count3*.5),"true","false") | 
eval issue2=if(count1&amp;gt;=(count3*1.5),"true","false") | 
eval condition=if((issue1="true") OR (issue2="true"),"true","false") | 
table count1 count3 issue1 issue2 condition
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;I still get count1 and count3 as zero. Is it because of timezone issues?&lt;/P&gt;</description>
    <pubDate>Tue, 10 May 2016 01:11:31 GMT</pubDate>
    <dc:creator>hvaithia</dc:creator>
    <dc:date>2016-05-10T01:11:31Z</dc:date>
    <item>
      <title>How to compare data in 2 time buckets and alert based on results?</title>
      <link>https://community.splunk.com/t5/Alerting/How-to-compare-data-in-2-time-buckets-and-alert-based-on-results/m-p/235691#M4405</link>
      <description>&lt;P&gt;bucket 1 -&amp;gt; Last 30 mins (say 10.30 AM to 11 AM) &lt;BR /&gt;
bucket 2 -&amp;gt; Get avg count of events for the same time period for the last 7 days (10.30 AM to 11 AM) &lt;BR /&gt;
compare bucket 1 and bucket 2. If bucket 1 is 50% less than bucket 2, then send me an alert Email&lt;/P&gt;

&lt;P&gt;I am trying to get the number of URL hits and if its substantially less than avg of last 7 days for the same time period, I need to be notified. How can I achieve this in splunk?&lt;/P&gt;</description>
      <pubDate>Mon, 09 May 2016 19:17:10 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Alerting/How-to-compare-data-in-2-time-buckets-and-alert-based-on-results/m-p/235691#M4405</guid>
      <dc:creator>hvaithia</dc:creator>
      <dc:date>2016-05-09T19:17:10Z</dc:date>
    </item>
    <item>
      <title>Re: How to compare data in 2 time buckets and alert based on results?</title>
      <link>https://community.splunk.com/t5/Alerting/How-to-compare-data-in-2-time-buckets-and-alert-based-on-results/m-p/235692#M4406</link>
      <description>&lt;P&gt;Set this up as an alert that triggers an email if the results count is greater than 0.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=indexName date_hour=10 date_minute&amp;gt;=30  
| stats c AS count1 
| appendcols [ search index=indexName date_hour=11 date_hour=10 date_minute&amp;gt;=30 earliest=-7d@d | stats avg(count) AS count2] 
| eval issue=if(count1&amp;lt;=(count2*.5),"true","false") 
| table count1 count2 
| where issue=true
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 09 May 2016 19:40:54 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Alerting/How-to-compare-data-in-2-time-buckets-and-alert-based-on-results/m-p/235692#M4406</guid>
      <dc:creator>jkat54</dc:creator>
      <dc:date>2016-05-09T19:40:54Z</dc:date>
    </item>
    <item>
      <title>Re: How to compare data in 2 time buckets and alert based on results?</title>
      <link>https://community.splunk.com/t5/Alerting/How-to-compare-data-in-2-time-buckets-and-alert-based-on-results/m-p/235693#M4407</link>
      <description>&lt;P&gt;Thanks for your response. I have got parts of what I need from your answer. Here is how my current search looks&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=abc url="/xyz"
date_minute&amp;gt;=30 earliest=-24h@h | 
date_hour=eval strftime(_time, "%H") |
stats c as count1 |
appendcols [search index=abc
url="/xyz"
date_minute&amp;gt;=30 earliest=-7d@d | 
date_hour=eval strftime(_time, "%H") |
stats count(url) as count2] | 
eval count3=round(count2/7,0) | 
eval issue1=if(count1&amp;lt;=(count3*.5),"true","false") | 
eval issue2=if(count1&amp;gt;=(count3*1.5),"true","false") | 
eval condition=if((issue1="true") OR (issue2="true"),"true","false") | 
table count1 count3 issue1 issue2 condition
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;I am planning to run this search every half hour or hourly. So I need to find the date_hour dynamically every time. I figured the above method would help but somehow I get a &lt;CODE&gt;Unknown search command 'date'.&lt;/CODE&gt; error. If I remove the &lt;CODE&gt;eval strftime(_time, "%H")&lt;/CODE&gt; in both the searches and just put in plain integers, it works! How do I solve this?&lt;/P&gt;</description>
      <pubDate>Tue, 29 Sep 2020 09:38:04 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Alerting/How-to-compare-data-in-2-time-buckets-and-alert-based-on-results/m-p/235693#M4407</guid>
      <dc:creator>hvaithia</dc:creator>
      <dc:date>2020-09-29T09:38:04Z</dc:date>
    </item>
    <item>
      <title>Re: How to compare data in 2 time buckets and alert based on results?</title>
      <link>https://community.splunk.com/t5/Alerting/How-to-compare-data-in-2-time-buckets-and-alert-based-on-results/m-p/235694#M4408</link>
      <description>&lt;P&gt;My bad in the above search, there was an extra pipe. But if I remove it&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=trendingnow sourcetype=yapache_access_trending status=200 colo=bf1 url="/tn?category=general&amp;amp;locale=en_us&amp;amp;source=mobile_distro"
date_minute&amp;gt;=30 earliest=-24h@h date_hour=eval strftime(_time, "%H") |
stats c as count1 |
appendcols [search index=trendingnow sourcetype=yapache_access_trending status=200 colo=bf1
url="/tn?category=general&amp;amp;locale=en_us&amp;amp;source=mobile_distro"
date_minute&amp;gt;=30 earliest=-7d@d date_hour=eval strftime(_time, "%H") |
stats count(url) as count2] | 
eval count3=round(count2/7,0) | 
eval issue1=if(count1&amp;lt;=(count3*.5),"true","false") | 
eval issue2=if(count1&amp;gt;=(count3*1.5),"true","false") | 
eval condition=if((issue1="true") OR (issue2="true"),"true","false") | 
table count1 count3 issue1 issue2 condition
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;I still get count1 and count3 as zero. Is it because of timezone issues?&lt;/P&gt;</description>
      <pubDate>Tue, 10 May 2016 01:11:31 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Alerting/How-to-compare-data-in-2-time-buckets-and-alert-based-on-results/m-p/235694#M4408</guid>
      <dc:creator>hvaithia</dc:creator>
      <dc:date>2016-05-10T01:11:31Z</dc:date>
    </item>
    <item>
      <title>Re: How to compare data in 2 time buckets and alert based on results?</title>
      <link>https://community.splunk.com/t5/Alerting/How-to-compare-data-in-2-time-buckets-and-alert-based-on-results/m-p/235695#M4409</link>
      <description>&lt;P&gt;I was afraid you'd say that.  I've been trying to figure out how to do it dynamically for hours now &lt;span class="lia-unicode-emoji" title=":winking_face:"&gt;😉&lt;/span&gt;&lt;/P&gt;

&lt;P&gt;Will let you know if I ever solve the problem.&lt;/P&gt;</description>
      <pubDate>Tue, 10 May 2016 01:13:27 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Alerting/How-to-compare-data-in-2-time-buckets-and-alert-based-on-results/m-p/235695#M4409</guid>
      <dc:creator>jkat54</dc:creator>
      <dc:date>2016-05-10T01:13:27Z</dc:date>
    </item>
    <item>
      <title>Re: How to compare data in 2 time buckets and alert based on results?</title>
      <link>https://community.splunk.com/t5/Alerting/How-to-compare-data-in-2-time-buckets-and-alert-based-on-results/m-p/235696#M4410</link>
      <description>&lt;P&gt;sure! Thanks. I have been trying to do the same for the past couple hours now. Will let the forum know if anything turns up.&lt;/P&gt;</description>
      <pubDate>Tue, 10 May 2016 01:16:05 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Alerting/How-to-compare-data-in-2-time-buckets-and-alert-based-on-results/m-p/235696#M4410</guid>
      <dc:creator>hvaithia</dc:creator>
      <dc:date>2016-05-10T01:16:05Z</dc:date>
    </item>
    <item>
      <title>Re: How to compare data in 2 time buckets and alert based on results?</title>
      <link>https://community.splunk.com/t5/Alerting/How-to-compare-data-in-2-time-buckets-and-alert-based-on-results/m-p/235697#M4411</link>
      <description>&lt;P&gt;DO NOT USE the "free" &lt;CODE&gt;date_*&lt;/CODE&gt; fields; they are PRE-TZ-normalization artifacts.  Try this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=trendingnow earliest=-24h@h
 sourcetype=yapache_access_trending status=200 colo=bf1 url="/tn?category=general&amp;amp;locale=en_us&amp;amp;source=mobile_distro"
| eval date_hourmin=strftime(_time, "%H%M")
| eval date_hourmin_thisHour = strftime(relative_time(now(), "@h"), "%H%M")
| where date_hourmin&amp;gt;=date_hourmin_thisHour AND date_hourmin&amp;lt;=tonumber(date_hourmin_thisHour + 59)
| stats count(url) AS count1
| appendcols [search
       index=trendingnow earliest=-7d@d
       sourcetype=yapache_access_trending status=200 colo=bf1 url="/tn?category=general&amp;amp;locale=en_us&amp;amp;source=mobile_distro"
   | eval date_hourmin=strftime(_time, "%H%M")
   | eval date_hourmin_thisHour = strftime(relative_time(now(), "@h"), "%H%M")
   | where date_hourmin&amp;gt;=date_hourmin_thisHour AND date_hourmin&amp;lt;=tonumber(date_hourmin_thisHour + 59)
   | stats count(url) as count2]
| eval count3=round(count2/7,0)
| eval issue1=if(count1&amp;lt;=(count3*.5),"true","false")
| eval issue2=if(count1&amp;gt;=(count3*1.5),"true","false")
| eval condition=if((issue1="true") OR (issue2="true"),"true","false")
| table count1 count3 issue1 issue2 condition
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 10 May 2016 04:49:06 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Alerting/How-to-compare-data-in-2-time-buckets-and-alert-based-on-results/m-p/235697#M4411</guid>
      <dc:creator>woodcock</dc:creator>
      <dc:date>2016-05-10T04:49:06Z</dc:date>
    </item>
    <item>
      <title>Re: How to compare data in 2 time buckets and alert based on results?</title>
      <link>https://community.splunk.com/t5/Alerting/How-to-compare-data-in-2-time-buckets-and-alert-based-on-results/m-p/235698#M4412</link>
      <description>&lt;P&gt;Hi @woodcock&lt;/P&gt;

&lt;P&gt;I am trying to get the time range from the hour/min when the search is executed. Lets say I set up a hourly cron to run the search at 59th minute of each hour&lt;/P&gt;

&lt;P&gt;At 10.59 AM the time comparison will be between 10 - 10.59 today and the average of 10-10.59 AM for the past 7 days&lt;BR /&gt;
Same when the search is ran again at 11.59 AM. Time range will be 11 - 11.59.&lt;/P&gt;

&lt;P&gt;How can I modify the above search to do that? Basically how to modify the search time dynamically?&lt;/P&gt;

&lt;P&gt;Thanks,&lt;BR /&gt;
Hari&lt;/P&gt;</description>
      <pubDate>Tue, 10 May 2016 20:06:23 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Alerting/How-to-compare-data-in-2-time-buckets-and-alert-based-on-results/m-p/235698#M4412</guid>
      <dc:creator>hvaithia</dc:creator>
      <dc:date>2016-05-10T20:06:23Z</dc:date>
    </item>
    <item>
      <title>Re: How to compare data in 2 time buckets and alert based on results?</title>
      <link>https://community.splunk.com/t5/Alerting/How-to-compare-data-in-2-time-buckets-and-alert-based-on-results/m-p/235699#M4413</link>
      <description>&lt;P&gt;I have updated the answer accordingly; try it again.&lt;/P&gt;</description>
      <pubDate>Tue, 10 May 2016 22:13:48 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Alerting/How-to-compare-data-in-2-time-buckets-and-alert-based-on-results/m-p/235699#M4413</guid>
      <dc:creator>woodcock</dc:creator>
      <dc:date>2016-05-10T22:13:48Z</dc:date>
    </item>
    <item>
      <title>Re: How to compare data in 2 time buckets and alert based on results?</title>
      <link>https://community.splunk.com/t5/Alerting/How-to-compare-data-in-2-time-buckets-and-alert-based-on-results/m-p/235700#M4414</link>
      <description>&lt;P&gt;That makes much more sense. I thought we were going down the date_hour route again and you made a typo in the search line here -&amp;gt; date_hourmin.&lt;/P&gt;

&lt;P&gt;I didn't know that where can be used to specify time ranges like above! Thats really useful! I will keep that in mind.&lt;/P&gt;

&lt;P&gt;And the above query works exactly as expected &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;

&lt;P&gt;Thanks a lot!!&lt;BR /&gt;
Hari V&lt;/P&gt;</description>
      <pubDate>Tue, 29 Sep 2020 09:40:57 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Alerting/How-to-compare-data-in-2-time-buckets-and-alert-based-on-results/m-p/235700#M4414</guid>
      <dc:creator>hvaithia</dc:creator>
      <dc:date>2020-09-29T09:40:57Z</dc:date>
    </item>
  </channel>
</rss>

