<?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: splunk query for consecutive event in less than 5 s window in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/splunk-query-for-consecutive-event-in-less-than-5-s-window/m-p/415981#M168573</link>
    <description>&lt;P&gt;@maniishpawar - &lt;/P&gt;

&lt;P&gt;You are heading in the right direction...  &lt;CODE&gt;streamstats&lt;/CODE&gt; is the right tool for this.  However, you don't want to use &lt;CODE&gt;sum()&lt;/CODE&gt;.  &lt;/P&gt;

&lt;P&gt;First, you need to get all the events that you need, and throw out any that aren't relevant to your question.  Then, you need to copy the information forward from the 3201 to the 3202 record.  Finally, you need to test whether the difference is more than five seconds.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt; your search that gets all the 3201 and 3202 events, with fields  _time, EventCode and cloudServiceName
| sort 0 cloudServiceName _time 
| eval startTime = case(EventCode==3201,_time)
| streamstats current=f last(startTime) as prevStartTime by cloudServiceName 
| eval duration=_time - prevStartTime
| where EventCode=3202 AND duration &amp;gt;5
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Here we take advantage of the assumption that the event immediately before a 3202 must be the paired 3201. If you might have multiple of either, then use the next version. &lt;/P&gt;</description>
    <pubDate>Tue, 03 Jul 2018 17:31:14 GMT</pubDate>
    <dc:creator>DalJeanis</dc:creator>
    <dc:date>2018-07-03T17:31:14Z</dc:date>
    <item>
      <title>splunk query for consecutive event in less than 5 s window</title>
      <link>https://community.splunk.com/t5/Splunk-Search/splunk-query-for-consecutive-event-in-less-than-5-s-window/m-p/415978#M168570</link>
      <description>&lt;P&gt;Hi&lt;BR /&gt;
I am trying to write a query to detect IIS start stop event 3201 and 3202 respectively.&lt;BR /&gt;
I wanted to create a query that can check these two events and if they do not fall through in 5s gap, then generate an alert.&lt;BR /&gt;
For ex&lt;/P&gt;

&lt;P&gt;12:00:01 3201 logged&lt;BR /&gt;
12:00:02 3230 logged &lt;BR /&gt;
for this no alert should be generated.&lt;/P&gt;

&lt;P&gt;12:00:10 3201 logged&lt;BR /&gt;
12:00:15 1234 logged&lt;BR /&gt;
12:00:20 3202 logged &lt;BR /&gt;
for this there should be an alert as the difference is more than 5s. &lt;/P&gt;</description>
      <pubDate>Mon, 02 Jul 2018 13:16:33 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/splunk-query-for-consecutive-event-in-less-than-5-s-window/m-p/415978#M168570</guid>
      <dc:creator>maniishpawar</dc:creator>
      <dc:date>2018-07-02T13:16:33Z</dc:date>
    </item>
    <item>
      <title>Re: splunk query for consecutive event in less than 5 s window</title>
      <link>https://community.splunk.com/t5/Splunk-Search/splunk-query-for-consecutive-event-in-less-than-5-s-window/m-p/415979#M168571</link>
      <description>&lt;P&gt;after going through online. I came up with something below. Can someone please suggest if this will work or if this the correct answer . &lt;BR /&gt;
Will be more than happy to have alternatives.&lt;/P&gt;

&lt;P&gt;index=*    cloudServiceName="onref*cls*"   "SourceName=Microsoft-Windows-IIS-IISReset"&lt;BR /&gt;&lt;BR /&gt;
| streamstats time_window=5s sum(EventCode) as Previous_Event by cloudServiceName | search Previous_Event&amp;gt;6401&lt;/P&gt;</description>
      <pubDate>Tue, 29 Sep 2020 20:14:20 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/splunk-query-for-consecutive-event-in-less-than-5-s-window/m-p/415979#M168571</guid>
      <dc:creator>maniishpawar</dc:creator>
      <dc:date>2020-09-29T20:14:20Z</dc:date>
    </item>
    <item>
      <title>Re: splunk query for consecutive event in less than 5 s window</title>
      <link>https://community.splunk.com/t5/Splunk-Search/splunk-query-for-consecutive-event-in-less-than-5-s-window/m-p/415980#M168572</link>
      <description>&lt;P&gt;Any one has any suggestions/comments ?&lt;/P&gt;</description>
      <pubDate>Tue, 03 Jul 2018 16:26:25 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/splunk-query-for-consecutive-event-in-less-than-5-s-window/m-p/415980#M168572</guid>
      <dc:creator>maniishpawar</dc:creator>
      <dc:date>2018-07-03T16:26:25Z</dc:date>
    </item>
    <item>
      <title>Re: splunk query for consecutive event in less than 5 s window</title>
      <link>https://community.splunk.com/t5/Splunk-Search/splunk-query-for-consecutive-event-in-less-than-5-s-window/m-p/415981#M168573</link>
      <description>&lt;P&gt;@maniishpawar - &lt;/P&gt;

&lt;P&gt;You are heading in the right direction...  &lt;CODE&gt;streamstats&lt;/CODE&gt; is the right tool for this.  However, you don't want to use &lt;CODE&gt;sum()&lt;/CODE&gt;.  &lt;/P&gt;

&lt;P&gt;First, you need to get all the events that you need, and throw out any that aren't relevant to your question.  Then, you need to copy the information forward from the 3201 to the 3202 record.  Finally, you need to test whether the difference is more than five seconds.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt; your search that gets all the 3201 and 3202 events, with fields  _time, EventCode and cloudServiceName
| sort 0 cloudServiceName _time 
| eval startTime = case(EventCode==3201,_time)
| streamstats current=f last(startTime) as prevStartTime by cloudServiceName 
| eval duration=_time - prevStartTime
| where EventCode=3202 AND duration &amp;gt;5
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Here we take advantage of the assumption that the event immediately before a 3202 must be the paired 3201. If you might have multiple of either, then use the next version. &lt;/P&gt;</description>
      <pubDate>Tue, 03 Jul 2018 17:31:14 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/splunk-query-for-consecutive-event-in-less-than-5-s-window/m-p/415981#M168573</guid>
      <dc:creator>DalJeanis</dc:creator>
      <dc:date>2018-07-03T17:31:14Z</dc:date>
    </item>
    <item>
      <title>Re: splunk query for consecutive event in less than 5 s window</title>
      <link>https://community.splunk.com/t5/Splunk-Search/splunk-query-for-consecutive-event-in-less-than-5-s-window/m-p/415982#M168574</link>
      <description>&lt;P&gt;If you also want to test for stop records without start records and vice versa, it is going to need to be slightly more complex. &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt; your search that gets all the 3201 and 3202 events, with fields  _time, EventCode and cloudServiceName
 | sort 0 cloudServiceName _time 
 | eval startTime = case(EventCode==3201,_time)
 | streamstats count(startTime) as startSequence by cloudServiceName 
 | eval startSequence = coalesce(startSequence,0)
 | stats range(_time) as duration min(_time) as _time list(EventCode) as EventCode by cloudServiceName startSequence
 | where mvcount(EventCode)&amp;lt;2 OR  mvcount(EventCode)&amp;gt;2  OR duration &amp;gt;5
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 03 Jul 2018 17:38:16 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/splunk-query-for-consecutive-event-in-less-than-5-s-window/m-p/415982#M168574</guid>
      <dc:creator>DalJeanis</dc:creator>
      <dc:date>2018-07-03T17:38:16Z</dc:date>
    </item>
    <item>
      <title>Re: splunk query for consecutive event in less than 5 s window</title>
      <link>https://community.splunk.com/t5/Splunk-Search/splunk-query-for-consecutive-event-in-less-than-5-s-window/m-p/415983#M168575</link>
      <description>&lt;P&gt;Thank you for the answer. Can you please help me understand the second solution. &lt;/P&gt;</description>
      <pubDate>Thu, 05 Jul 2018 15:44:27 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/splunk-query-for-consecutive-event-in-less-than-5-s-window/m-p/415983#M168575</guid>
      <dc:creator>maniishpawar</dc:creator>
      <dc:date>2018-07-05T15:44:27Z</dc:date>
    </item>
    <item>
      <title>Re: splunk query for consecutive event in less than 5 s window</title>
      <link>https://community.splunk.com/t5/Splunk-Search/splunk-query-for-consecutive-event-in-less-than-5-s-window/m-p/415984#M168576</link>
      <description>&lt;P&gt;Like this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=AlwaysSpecifyAnIndex cloudServiceName="onref*cls*" "SourceName=Microsoft-Windows-IIS-IISReset"
| streamstasts count(eval(EventCode=="3202")) AS SessionID
| stats range(_time) AS sessionSeconds BY sessionID
| where sessionSeconds &amp;gt; 5
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 16 Jul 2018 00:49:09 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/splunk-query-for-consecutive-event-in-less-than-5-s-window/m-p/415984#M168576</guid>
      <dc:creator>woodcock</dc:creator>
      <dc:date>2018-07-16T00:49:09Z</dc:date>
    </item>
  </channel>
</rss>

