<?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: Alert when request time taken is above threshold for specified consecutive requests in Alerting</title>
    <link>https://community.splunk.com/t5/Alerting/Alert-when-request-time-taken-is-above-threshold-for-specified/m-p/328017#M5823</link>
    <description>&lt;P&gt;@alex_egyed - did you get everything you needed?&lt;/P&gt;</description>
    <pubDate>Fri, 28 Jul 2017 14:15:27 GMT</pubDate>
    <dc:creator>DalJeanis</dc:creator>
    <dc:date>2017-07-28T14:15:27Z</dc:date>
    <item>
      <title>Alert when request time taken is above threshold for specified consecutive requests</title>
      <link>https://community.splunk.com/t5/Alerting/Alert-when-request-time-taken-is-above-threshold-for-specified/m-p/328015#M5821</link>
      <description>&lt;P&gt;I'm trying to set up an alert for this use case:&lt;/P&gt;

&lt;P&gt;&lt;EM&gt;When the request time taken for an API is above X seconds threshold for Y consecutive requests on a GET/POST/PUT request then send an alert.&lt;/EM&gt;&lt;/P&gt;

&lt;P&gt;The challenges that I'm facing are due to having multiple APIs, multiple HTTP methods, multiple seconds thresholds and multiple consecutive requests thresholds. The thresholds are declared in a .csv file which can be easily updated by anyone and then uploaded as a lookup table.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| api | GET_time_threshold_s | GET_count_consecutive_overtime_threshold | POST_time_threshold_s | POST_count_consecutive_overtime_threshold | PUT_time_threshold_s | PUT_count_consecutive_overtime_threshold |
| OrdersApi | 0.5 | 7 | 0.8 | 5 | 1.5 | 3 |
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;So far I came up with a solution that works just for a single API, but I'm unsure of what's the best solution that has less maintenance possible. I don't know how to pass a lookup table field to the  &lt;CODE&gt;window&lt;/CODE&gt; argument of  &lt;CODE&gt;streamstats&lt;/CODE&gt; command so I created a separate query to generate the search command.&lt;/P&gt;

&lt;P&gt;&lt;STRONG&gt;Generate search query&lt;/STRONG&gt;&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| inputlookup api_lookup_with_thresholds.csv
| where api="OrdersApi"
| eval query="sourcetype=IIS host=\"Prod*\" api=\"OrdersApi\" 
| eval time_taken_s = round(time_taken/1000, 3) 
| lookup api_lookup_with_thresholds.csv api 
| eval is_GET_time_over_threshold=if(cs_method=\"GET\" AND time_taken_s &amp;gt;= GET_time_threshold_s, 1, 0), 
    is_POST_time_over_threshold=if(cs_method=\"POST\" AND time_taken_s &amp;gt;= POST_time_threshold_s, 1, 0), 
    is_PUT_time_over_threshold=if(cs_method=\"PUT\" AND time_taken_s &amp;gt;= PUT_time_threshold_s, 1, 0) 
| sort +_time 
| streamstats window=" + GET_count_consecutive_overtime_threshold  + " global=false sum(is_GET_time_over_threshold)  as rolling_over_GET_threshold  by api, cs_method,
| streamstats window=" + POST_count_consecutive_overtime_threshold + " global=false sum(is_POST_time_over_threshold) as rolling_over_POST_threshold by api, cs_method,
| streamstats window=" + PUT_count_consecutive_overtime_threshold  + " global=false sum(is_PUT_time_over_threshold)  as rolling_over_PUT_threshold  by api, cs_method | table _time, api, cs_method, time_taken_s, rolling_over_GET_threshold, rolling_over_POST_threshold, is_GET_time_over_threshold, is_POST_time_over_threshold" | return $query
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;The result would be a query like below that targets only OrdersApi.&lt;/P&gt;

&lt;P&gt;&lt;STRONG&gt;Monitor search query&lt;/STRONG&gt;&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;sourcetype=IIS host="Prod*" api="OrdersApi" 
| eval time_taken_s = round(time_taken/1000, 3) 
| lookup api_lookup_with_thresholds.csv api 
| eval is_GET_time_over_threshold=if(cs_method="GET" AND time_taken_s &amp;gt;= GET_time_threshold_s, 1, 0),
  is_POST_time_over_threshold=if(cs_method="POST" AND time_taken_s &amp;gt;= POST_time_threshold_s, 1, 0),
  is_PUT_time_over_threshold=if(cs_method="PUT" AND time_taken_s &amp;gt;= PUT_time_threshold_s, 1, 0) 
| sort +_time 
| streamstats window=7 global=false sum(is_GET_time_over_threshold)  as rolling_over_GET_threshold  by api, cs_method 
| streamstats window=5 global=false sum(is_POST_time_over_threshold) as rolling_over_POST_threshold by api, cs_method 
| streamstats window=3 global=false sum(is_PUT_time_over_threshold)  as rolling_over_PUT_threshold  by api, cs_method
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Is there a way to execute the generated search command in another search? Is there a better way to solve the use case while keeping maintenance as low as possible? Should I think about using the API to generate all the searches automatically?&lt;BR /&gt;
I'm trying to find a solution that when uploading the new .csv file doesn't require updating all the search queries.&lt;/P&gt;

&lt;P&gt;As an alternative solution I was thinking of saving the search above as a  &lt;CODE&gt;savedsearch&lt;/CODE&gt; with  &lt;CODE&gt;api&lt;/CODE&gt;,  &lt;CODE&gt;get_window&lt;/CODE&gt;,  &lt;CODE&gt;post_window&lt;/CODE&gt;,  &lt;CODE&gt;put_window&lt;/CODE&gt; parameters and call it from another search, one for each API but I couldn't read the values from the lookup table and pass them to the saved search. &lt;/P&gt;</description>
      <pubDate>Mon, 24 Jul 2017 04:13:23 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Alerting/Alert-when-request-time-taken-is-above-threshold-for-specified/m-p/328015#M5821</guid>
      <dc:creator>alex_egyed</dc:creator>
      <dc:date>2017-07-24T04:13:23Z</dc:date>
    </item>
    <item>
      <title>Re: Alert when request time taken is above threshold for specified consecutive requests</title>
      <link>https://community.splunk.com/t5/Alerting/Alert-when-request-time-taken-is-above-threshold-for-specified/m-p/328016#M5822</link>
      <description>&lt;P&gt;1) Restructure your file as so -&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;reqapi reqtype reqelapsed reqcount
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;This is not completely necessary, but it will help your brain see the simplicity of the solution.&lt;/P&gt;

&lt;P&gt;2)  Then try this...&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;your search that gets _time, reqapi, reqtype and reqelapsed

| rename COMMENT as "first we put the records into order" 
| sort 0 reqapi reqtype _time   

| rename COMMENT as "now we look up the trigger time and flag the records which qualify for the trigger" 
| lookup mylookup reqapi reqtype OUTPUT reqtrigger reqcount
| eval overtime=if(reqelapsed&amp;gt;=reqtrigger,1,0)

| rename COMMENT as "use streamstats to check whether the record is different from the prior record" 
| streamstats current=f last(overtime) as priortime by reqapi reqtype
| eval newgroup=if(overtime=priortime,0,1) 
| streamstats sum(newgroup) as groupno by reqapi reqtype

| rename COMMENT as "figure out how many records belong to the group"
| rename COMMENT as "and let a trigger=1 group pass if it's bigger than the required count" 
| eventstats count as groupsize by reqapi reqtype groupno
| where (groupsize &amp;gt;= reqcount) AND (overtime=1)
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 24 Jul 2017 23:52:02 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Alerting/Alert-when-request-time-taken-is-above-threshold-for-specified/m-p/328016#M5822</guid>
      <dc:creator>DalJeanis</dc:creator>
      <dc:date>2017-07-24T23:52:02Z</dc:date>
    </item>
    <item>
      <title>Re: Alert when request time taken is above threshold for specified consecutive requests</title>
      <link>https://community.splunk.com/t5/Alerting/Alert-when-request-time-taken-is-above-threshold-for-specified/m-p/328017#M5823</link>
      <description>&lt;P&gt;@alex_egyed - did you get everything you needed?&lt;/P&gt;</description>
      <pubDate>Fri, 28 Jul 2017 14:15:27 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Alerting/Alert-when-request-time-taken-is-above-threshold-for-specified/m-p/328017#M5823</guid>
      <dc:creator>DalJeanis</dc:creator>
      <dc:date>2017-07-28T14:15:27Z</dc:date>
    </item>
  </channel>
</rss>

