<?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: multiple conditions spl help in Alerting</title>
    <link>https://community.splunk.com/t5/Alerting/multiple-conditions-spl-help/m-p/377081#M11513</link>
    <description>&lt;P&gt;If you want to do this in one search, here is how.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;1st to eval the time period that is 24hrs ago from -1h@h to @h 

| eval 25hrAgo=relative_time(now(),"-25h@h")
| eval 24hrAgo=relative_time(now(),"-24h@h")
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;2nd to get the counts of uri requests per hour in our time frames&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;|  stats count(eval(_time&amp;gt;=24hrAgo AND _time&amp;lt;=25hrAgo)) as yesterdayCount  count(eval(_time&amp;gt;=relative_time(now(),"-1h@h")) AND _time&amp;lt;=relative_time(now(),"-0h@h")) as lastHourCount  count(eval(_time&amp;gt;=relative_time(now(),"-2h@h")) AND _time&amp;lt;=relative_time(now(),"-1h@h")) as 2hrAgoCount 
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;3rd to math if alert is needed&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt; | eval 80percA=if((2hrAgoCount/(lastHourCount-2hrAgoCount)*100)&amp;gt;80,1,0)
 | eval 80percB=if((yesterdayCount/(lastHourCount-yesterdayCount)*100)&amp;gt;80,1,0)
| eval 50percA=if((2hrAgoCount/(lastHourCount-2hrAgoCount)*100)&amp;gt;50,1,0)
 | eval 50percB=if((yesterdayCount/(lastHourCount-yesterdayCount)*100)&amp;gt;50,1,0)
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Now to send email based on if any of above = 1&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt; |  where 80percA=1 OR 80percB=1 OR 50percA=1 OR 50percB=1 
  | map search="|sendemail subject=\"$80percA$ $80percB$ $50percA$ $50percB$\" to=youremail@mail.com"
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;This should send you an email with subject of 1 0 0 0 for example which would mean there were more than 100 requests in the last hour and that was 80% more than the same hour 2 hours ago.&lt;/P&gt;</description>
    <pubDate>Fri, 12 Jul 2019 03:06:06 GMT</pubDate>
    <dc:creator>jkat54</dc:creator>
    <dc:date>2019-07-12T03:06:06Z</dc:date>
    <item>
      <title>multiple conditions spl help</title>
      <link>https://community.splunk.com/t5/Alerting/multiple-conditions-spl-help/m-p/377080#M11512</link>
      <description>&lt;P&gt;hello everyone!&lt;BR /&gt;
     I have a program  that  counts the number of requests for website api  per minute.the log format is as following, where  field &lt;CODE&gt;time&lt;/CODE&gt; is the time of the statistics.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;    request_domain             time                           uri                      min_count
    &lt;A href="https://community.splunk.com/www.test.com" target="test_blank"&gt;www.test.com&lt;/A&gt;         11/Jul/2019 15:51                  /api/test                     19
    &lt;A href="https://community.splunk.com/www.test.com" target="test_blank"&gt;www.test.com&lt;/A&gt;         11/Jul/2019 15:51                  /api/exmple                   208
    m.test.com           11/Jul/2019 15:52                 /api/search                    80
    &lt;A href="https://community.splunk.com/www.test.com" target="test_blank"&gt;www.test.com&lt;/A&gt;         11/Jul/2019 15:52                  /api/test                     31
    &lt;A href="https://community.splunk.com/www.test.com" target="test_blank"&gt;www.test.com&lt;/A&gt;         11/Jul/2019 15:52                  /api/exmple                   253
    m.test.com           11/Jul/2019 15:52                 /api/search                     62
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;I want to create an alert based on the following requirements, but I don't know how to do it.&lt;/P&gt;

&lt;P&gt;If the number of uri requests is greater than 100 times per hour. &lt;/P&gt;

&lt;OL&gt;
&lt;LI&gt;Compare the previous hour, if the growth rate is greater than 80%, then alert&lt;/LI&gt;
&lt;LI&gt;Compare the same time period yesterday, if the growth rate is greater than 80%, then the alarm.&lt;/LI&gt;
&lt;/OL&gt;

&lt;P&gt;If the number of uri requests is less than 100 times per hour. &lt;/P&gt;

&lt;OL&gt;
&lt;LI&gt;Compare the previous hour, if the growth number is greater than 50 times, then alert&lt;/LI&gt;
&lt;LI&gt;Compare the same time period yesterday, if the growth number is greater than 50 times,then alert&lt;/LI&gt;
&lt;/OL&gt;

&lt;P&gt;I think it needs to be split into at least 2 alert to achieve&lt;/P&gt;

&lt;P&gt;all help will be greatly appreciated!&lt;/P&gt;</description>
      <pubDate>Thu, 11 Jul 2019 13:41:46 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Alerting/multiple-conditions-spl-help/m-p/377080#M11512</guid>
      <dc:creator>bestSplunker</dc:creator>
      <dc:date>2019-07-11T13:41:46Z</dc:date>
    </item>
    <item>
      <title>Re: multiple conditions spl help</title>
      <link>https://community.splunk.com/t5/Alerting/multiple-conditions-spl-help/m-p/377081#M11513</link>
      <description>&lt;P&gt;If you want to do this in one search, here is how.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;1st to eval the time period that is 24hrs ago from -1h@h to @h 

| eval 25hrAgo=relative_time(now(),"-25h@h")
| eval 24hrAgo=relative_time(now(),"-24h@h")
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;2nd to get the counts of uri requests per hour in our time frames&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;|  stats count(eval(_time&amp;gt;=24hrAgo AND _time&amp;lt;=25hrAgo)) as yesterdayCount  count(eval(_time&amp;gt;=relative_time(now(),"-1h@h")) AND _time&amp;lt;=relative_time(now(),"-0h@h")) as lastHourCount  count(eval(_time&amp;gt;=relative_time(now(),"-2h@h")) AND _time&amp;lt;=relative_time(now(),"-1h@h")) as 2hrAgoCount 
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;3rd to math if alert is needed&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt; | eval 80percA=if((2hrAgoCount/(lastHourCount-2hrAgoCount)*100)&amp;gt;80,1,0)
 | eval 80percB=if((yesterdayCount/(lastHourCount-yesterdayCount)*100)&amp;gt;80,1,0)
| eval 50percA=if((2hrAgoCount/(lastHourCount-2hrAgoCount)*100)&amp;gt;50,1,0)
 | eval 50percB=if((yesterdayCount/(lastHourCount-yesterdayCount)*100)&amp;gt;50,1,0)
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Now to send email based on if any of above = 1&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt; |  where 80percA=1 OR 80percB=1 OR 50percA=1 OR 50percB=1 
  | map search="|sendemail subject=\"$80percA$ $80percB$ $50percA$ $50percB$\" to=youremail@mail.com"
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;This should send you an email with subject of 1 0 0 0 for example which would mean there were more than 100 requests in the last hour and that was 80% more than the same hour 2 hours ago.&lt;/P&gt;</description>
      <pubDate>Fri, 12 Jul 2019 03:06:06 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Alerting/multiple-conditions-spl-help/m-p/377081#M11513</guid>
      <dc:creator>jkat54</dc:creator>
      <dc:date>2019-07-12T03:06:06Z</dc:date>
    </item>
    <item>
      <title>Re: multiple conditions spl help</title>
      <link>https://community.splunk.com/t5/Alerting/multiple-conditions-spl-help/m-p/377082#M11514</link>
      <description>&lt;P&gt;@jkat54  thank you for your reply.&lt;/P&gt;

&lt;P&gt;When I tried to search for the first step, splunk prompted an error.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt; Error in 'stats' command: The eval expression for dynamic field 'eval(_time&amp;gt;=24hrAgo AND _time&amp;lt;=25hrAgo)' is invalid. Error='The operator at 'hrAgo AND _time&amp;lt;=25hrAgo' is invalid.'
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;This error may be because you are using numbers as the beginning of the field&lt;/P&gt;

&lt;P&gt;In addition, my program is counting the number of uri requests per minute. maybe i need add &lt;CODE&gt;|bin _time span=1h&lt;/CODE&gt; to the search statement you provided?&lt;/P&gt;</description>
      <pubDate>Fri, 12 Jul 2019 08:22:37 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Alerting/multiple-conditions-spl-help/m-p/377082#M11514</guid>
      <dc:creator>bestSplunker</dc:creator>
      <dc:date>2019-07-12T08:22:37Z</dc:date>
    </item>
    <item>
      <title>Re: multiple conditions spl help</title>
      <link>https://community.splunk.com/t5/Alerting/multiple-conditions-spl-help/m-p/377083#M11515</link>
      <description>&lt;P&gt;I&lt;BR /&gt;
Guess the stats doesn't work. With AND in the eval.. I wrote this on my phone without testing &lt;/P&gt;</description>
      <pubDate>Fri, 12 Jul 2019 11:49:22 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Alerting/multiple-conditions-spl-help/m-p/377083#M11515</guid>
      <dc:creator>jkat54</dc:creator>
      <dc:date>2019-07-12T11:49:22Z</dc:date>
    </item>
    <item>
      <title>Re: multiple conditions spl help</title>
      <link>https://community.splunk.com/t5/Alerting/multiple-conditions-spl-help/m-p/377084#M11516</link>
      <description>&lt;P&gt;@jkat54 How to fix this error?   &lt;CODE&gt;_time&amp;gt;=24hrAgo AND _time&amp;lt;=25hrAgo&lt;/CODE&gt;&lt;/P&gt;

&lt;P&gt;the field &lt;CODE&gt;_time'&lt;/CODE&gt; with a minute (%Y/%m/%d  %H:%M:%S) ,   but the  &lt;CODE&gt;24hrAgo&lt;/CODE&gt; and &lt;CODE&gt;25hrAgo&lt;/CODE&gt;  with a hour time format (%Y/%m/%d  %H)&lt;/P&gt;</description>
      <pubDate>Mon, 15 Jul 2019 01:15:55 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Alerting/multiple-conditions-spl-help/m-p/377084#M11516</guid>
      <dc:creator>bestSplunker</dc:creator>
      <dc:date>2019-07-15T01:15:55Z</dc:date>
    </item>
    <item>
      <title>Re: multiple conditions spl help</title>
      <link>https://community.splunk.com/t5/Alerting/multiple-conditions-spl-help/m-p/377085#M11517</link>
      <description>&lt;P&gt;First of all, this is a prime candidate for an hourly summary index rollup so consider that (it makes the SPL easy).  Short of that, try this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=&amp;lt;You should always specify an index&amp;gt; AND sourcetype=&amp;lt;And sourcetype too&amp;gt;
((earliest=-1d@h-1h latest=-1d@h) OR (earliest=-2h@h latest=now))
| bin span=1h _time
| stats count BY uri _time
| streamstats count AS _time BY uri
| eval _time = case(_time==1, "last_hour", _time==2, "prev_hour", _time==3, "yesterday_last_hour", true(), "ERROR")
| xyseries uri _time count
| eval growth_from_last_hour = (100 * (last_hour -           prev_hour) /           prev_hour)
| eval growth_from_yesterday = (100 * (last_hour - yesterday_last_hour) / yesterday_last_hour)
| where (((last_hour &amp;gt; 100) AND ((growth_from_last_hour &amp;gt; 80) OR (growth_from_yesterday &amp;gt; 80))) OR ((last_hour &amp;lt; 100) AND (growth_from_last_hour &amp;gt; 80)))
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 15 Jul 2019 03:01:06 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Alerting/multiple-conditions-spl-help/m-p/377085#M11517</guid>
      <dc:creator>woodcock</dc:creator>
      <dc:date>2019-07-15T03:01:06Z</dc:date>
    </item>
  </channel>
</rss>

