<?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: Search query for consecutive events in Security</title>
    <link>https://community.splunk.com/t5/Security/Search-query-for-consecutive-events/m-p/696481#M18072</link>
    <description>&lt;P&gt;Thank you PickleRick, I already got streamstats in my search query but got more results not only consecutive and I want isolate 3 consecutive results (see end of queary):&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;| eval Description=case(RML&amp;lt;104.008, "0", RML&amp;gt;108.425, "1", RML&amp;gt;=104.008, "OK", RML&amp;lt;=108.425, "OK")
| eval Warning=case(Description==0, "LevelBreach", Description==1, "LevelBreach")
| table LWL UWL RML
| eval CR=if(RML&amp;lt;UWL,"0",if(RML&amp;gt;LWL,"1","0"))
| accum CR AS ACC | streamstats window=3 reset_after="count=3" count &lt;/LI-CODE&gt;</description>
    <pubDate>Fri, 16 Aug 2024 14:15:43 GMT</pubDate>
    <dc:creator>Stives</dc:creator>
    <dc:date>2024-08-16T14:15:43Z</dc:date>
    <item>
      <title>Search query for consecutive events</title>
      <link>https://community.splunk.com/t5/Security/Search-query-for-consecutive-events/m-p/696471#M18070</link>
      <description>&lt;P&gt;Dear Splunkers, I would like ask your advice in order to complete following search result. My table checks for consecutive level breaches events in window of 3 counts.&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD width="200"&gt;&lt;P&gt;ACC&lt;/P&gt;&lt;/TD&gt;&lt;TD width="200"&gt;&lt;P&gt;CR&lt;/P&gt;&lt;/TD&gt;&lt;TD width="200"&gt;&lt;P&gt;count&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD width="200"&gt;&lt;P&gt;0&lt;/P&gt;&lt;/TD&gt;&lt;TD width="200"&gt;&lt;P&gt;0&lt;/P&gt;&lt;/TD&gt;&lt;TD width="200"&gt;&lt;P&gt;1&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD width="200"&gt;&lt;P&gt;0&lt;/P&gt;&lt;/TD&gt;&lt;TD width="200"&gt;&lt;P&gt;0&lt;/P&gt;&lt;/TD&gt;&lt;TD width="200"&gt;&lt;P&gt;2&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD width="200"&gt;&lt;P&gt;0&lt;/P&gt;&lt;/TD&gt;&lt;TD width="200"&gt;&lt;P&gt;0&lt;/P&gt;&lt;/TD&gt;&lt;TD width="200"&gt;&lt;P&gt;3&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD width="200"&gt;&lt;P&gt;1&lt;/P&gt;&lt;/TD&gt;&lt;TD width="200"&gt;&lt;P&gt;1&lt;/P&gt;&lt;/TD&gt;&lt;TD width="200"&gt;&lt;P&gt;1&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD width="200"&gt;&lt;P&gt;1&lt;/P&gt;&lt;/TD&gt;&lt;TD width="200"&gt;&lt;P&gt;0&lt;/P&gt;&lt;/TD&gt;&lt;TD width="200"&gt;&lt;P&gt;2&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD width="200"&gt;&lt;P&gt;1&lt;/P&gt;&lt;/TD&gt;&lt;TD width="200"&gt;&lt;P&gt;0&lt;/P&gt;&lt;/TD&gt;&lt;TD width="200"&gt;&lt;P&gt;3&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD width="200"&gt;&lt;P&gt;&lt;STRONG&gt;2&lt;/STRONG&gt;&lt;/P&gt;&lt;/TD&gt;&lt;TD width="200"&gt;&lt;P&gt;&lt;STRONG&gt;1&lt;/STRONG&gt;&lt;/P&gt;&lt;/TD&gt;&lt;TD width="200"&gt;&lt;P&gt;&lt;STRONG&gt;1&lt;/STRONG&gt;&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD width="200"&gt;&lt;P&gt;&lt;STRONG&gt;3&lt;/STRONG&gt;&lt;/P&gt;&lt;/TD&gt;&lt;TD width="200"&gt;&lt;P&gt;&lt;STRONG&gt;1&lt;/STRONG&gt;&lt;/P&gt;&lt;/TD&gt;&lt;TD width="200"&gt;&lt;P&gt;&lt;STRONG&gt;2&lt;/STRONG&gt;&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD width="200"&gt;&lt;P&gt;&lt;STRONG&gt;4&lt;/STRONG&gt;&lt;/P&gt;&lt;/TD&gt;&lt;TD width="200"&gt;&lt;P&gt;&lt;STRONG&gt;1&lt;/STRONG&gt;&lt;/P&gt;&lt;/TD&gt;&lt;TD width="200"&gt;&lt;P&gt;&lt;STRONG&gt;3&lt;/STRONG&gt;&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD width="200"&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;/TD&gt;&lt;TD width="200"&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;/TD&gt;&lt;TD width="200"&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If there is a level breach CR column will change to 1 and the ACC column will change to upcoming number. Now I would like to create an alert if 3 consecutive levels breached as shown in bolded example in bold.&amp;nbsp;&lt;BR /&gt;Can you suggest how to complete the query and display only 3 consecutive results so that I can create an Alert?&lt;/P&gt;&lt;P&gt;Thank you&lt;/P&gt;</description>
      <pubDate>Fri, 16 Aug 2024 13:13:35 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Security/Search-query-for-consecutive-events/m-p/696471#M18070</guid>
      <dc:creator>Stives</dc:creator>
      <dc:date>2024-08-16T13:13:35Z</dc:date>
    </item>
    <item>
      <title>Re: Search query</title>
      <link>https://community.splunk.com/t5/Security/Search-query-for-consecutive-events/m-p/696476#M18071</link>
      <description>&lt;P&gt;Your explanation is a bit unclear but it looks like a job for the streamstats command with a window size of 3.&lt;/P&gt;</description>
      <pubDate>Fri, 16 Aug 2024 12:58:43 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Security/Search-query-for-consecutive-events/m-p/696476#M18071</guid>
      <dc:creator>PickleRick</dc:creator>
      <dc:date>2024-08-16T12:58:43Z</dc:date>
    </item>
    <item>
      <title>Re: Search query for consecutive events</title>
      <link>https://community.splunk.com/t5/Security/Search-query-for-consecutive-events/m-p/696481#M18072</link>
      <description>&lt;P&gt;Thank you PickleRick, I already got streamstats in my search query but got more results not only consecutive and I want isolate 3 consecutive results (see end of queary):&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;| eval Description=case(RML&amp;lt;104.008, "0", RML&amp;gt;108.425, "1", RML&amp;gt;=104.008, "OK", RML&amp;lt;=108.425, "OK")
| eval Warning=case(Description==0, "LevelBreach", Description==1, "LevelBreach")
| table LWL UWL RML
| eval CR=if(RML&amp;lt;UWL,"0",if(RML&amp;gt;LWL,"1","0"))
| accum CR AS ACC | streamstats window=3 reset_after="count=3" count &lt;/LI-CODE&gt;</description>
      <pubDate>Fri, 16 Aug 2024 14:15:43 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Security/Search-query-for-consecutive-events/m-p/696481#M18072</guid>
      <dc:creator>Stives</dc:creator>
      <dc:date>2024-08-16T14:15:43Z</dc:date>
    </item>
    <item>
      <title>Re: Search query for consecutive events</title>
      <link>https://community.splunk.com/t5/Security/Search-query-for-consecutive-events/m-p/696530#M18073</link>
      <description>&lt;P&gt;You're getting close.&lt;/P&gt;&lt;P&gt;One streamstats is not enough because you can't "pull" events you already passed while processing the stream.&lt;/P&gt;&lt;P&gt;Assuming you want to find when you have at least three consecutive ACC=1, you can do it like this&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| eval Description=case(RML&amp;lt;104.008, "0", RML&amp;gt;108.425, "1", RML&amp;gt;=104.008, "OK", RML&amp;lt;=108.425, "OK")
| eval Warning=case(Description==0, "LevelBreach", Description==1, "LevelBreach")
| table LWL UWL RML
| eval CR=if(RML&amp;lt;UWL,"0",if(RML&amp;gt;LWL,"1","0"))
| streamstats window=3 sum(ACC) as running_count&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This will mark the last of three consecutive ACC=1 with running_count=3.&lt;/P&gt;&lt;P&gt;So we're on the right track so far we've found where our streak ends. Now we have to do a little trick since we can't pull events "from behind", we need to&lt;/P&gt;&lt;PRE&gt;| reverse&lt;/PRE&gt;&lt;P&gt;So that we're looking at our events in the other order. Now we know that event with running_count=3 will be starting our 3-event streak. So now we have to mark our 3 events looking forward&lt;/P&gt;&lt;PRE&gt;| streamstats current=t window=3 max(running_count) as mark_count&lt;/PRE&gt;&lt;P&gt;This will give us a value of markcount=3 for all events for which any of the last three events had&amp;nbsp; running_count of 3 (which means that we're no further than 3 events from the _last_ event of our 3 event streak).&amp;nbsp; Now all we have to do is find all those events we marked&lt;/P&gt;&lt;PRE&gt;| where mark_count=3&lt;/PRE&gt;&lt;P&gt;And now we can just tidy up after ourseves&lt;/P&gt;&lt;PRE&gt;| fields - running_count markcount&lt;BR /&gt;| reverse&lt;/PRE&gt;&lt;P&gt;And there you have it.&lt;/P&gt;&lt;P&gt;Unfortunately since it uses the &lt;EM&gt;reverse&lt;/EM&gt; command it can be quite memory consuming (and might even have some limits I'm not aware of at this time).&lt;/P&gt;</description>
      <pubDate>Fri, 16 Aug 2024 18:43:36 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Security/Search-query-for-consecutive-events/m-p/696530#M18073</guid>
      <dc:creator>PickleRick</dc:creator>
      <dc:date>2024-08-16T18:43:36Z</dc:date>
    </item>
    <item>
      <title>Re: Search query for consecutive events</title>
      <link>https://community.splunk.com/t5/Security/Search-query-for-consecutive-events/m-p/696669#M18076</link>
      <description>&lt;P&gt;Thank you so much PickleRick. It works for me well. I was able isolate 3 consecutive results. I appreciate&lt;/P&gt;</description>
      <pubDate>Mon, 19 Aug 2024 06:40:11 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Security/Search-query-for-consecutive-events/m-p/696669#M18076</guid>
      <dc:creator>Stives</dc:creator>
      <dc:date>2024-08-19T06:40:11Z</dc:date>
    </item>
  </channel>
</rss>

