<?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: Dedup consecutive values and count removed in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Dedup-consecutive-values-and-count-removed/m-p/211415#M61854</link>
    <description>&lt;P&gt;Problem solved !&lt;/P&gt;

&lt;P&gt;&lt;CODE&gt;| eval lastmc=MESSAGE_CLASS | streamstats current=f count last(MESSAGE_CLASS) as lastmc by Calling_Station_ID | eval consecutive=if(lastmc=MESSAGE_CLASS,1,0) | search consecutive=0 | stats first(MESSAGE_CLASS) AS prevmc first(count) AS count by Calling_Station_ID | search prevmc="Passed-Authentication"&lt;/CODE&gt;&lt;/P&gt;

&lt;P&gt;First eval is only here for the second eval, in other words: the first event is consecutive to himself.&lt;BR /&gt;
I compute a "consecutive" field as you've done, and then I only keep lines where &lt;CODE&gt;consecutive=0&lt;/CODE&gt;.&lt;BR /&gt;
After that, I use a &lt;CODE&gt;stats&lt;/CODE&gt; to select the first (newest) line and get the count of previous events.&lt;BR /&gt;
Finally, I keep lines where &lt;CODE&gt;prevmc="Passed-Authentication"&lt;/CODE&gt;, meaning previous events were "Failed-Attempt".&lt;/P&gt;

&lt;P&gt;Thank you guys for your help &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
    <pubDate>Thu, 31 Dec 2015 11:02:55 GMT</pubDate>
    <dc:creator>christophe_clem</dc:creator>
    <dc:date>2015-12-31T11:02:55Z</dc:date>
    <item>
      <title>Dedup consecutive values and count removed</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Dedup-consecutive-values-and-count-removed/m-p/211409#M61848</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;

&lt;P&gt;I want to count consecutive events that have common values of multiple fields.&lt;BR /&gt;
I can do partially the stuff with &lt;CODE&gt;dedup X Y consecutive=true&lt;/CODE&gt; but it does not count removed events.&lt;BR /&gt;
I can do the other part with &lt;CODE&gt;stats count by X Y&lt;/CODE&gt; but it does not take in account the "consecutive" part.&lt;/P&gt;

&lt;P&gt;In practice, my data is radius authentication logs, X is the authentication result and Y is the user.&lt;BR /&gt;
I need to count for each user the number of failed authentications without success authentication after.&lt;/P&gt;

&lt;P&gt;I thought I could do this with a subsearch which give the &lt;CODE&gt;_time&lt;/CODE&gt; of the latest success authentication for each user and then count the failed authentications that follow. But I can't find how to make a subsearch that produce a query like ( ( user="bob" AND _time&amp;gt;xxx ) OR ( user="alice" AND _time&amp;gt;yyy) )&lt;/P&gt;</description>
      <pubDate>Wed, 30 Dec 2015 14:50:04 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Dedup-consecutive-values-and-count-removed/m-p/211409#M61848</guid>
      <dc:creator>christophe_clem</dc:creator>
      <dc:date>2015-12-30T14:50:04Z</dc:date>
    </item>
    <item>
      <title>Re: Dedup consecutive values and count removed</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Dedup-consecutive-values-and-count-removed/m-p/211410#M61849</link>
      <description>&lt;P&gt;This might work... or it might need an eval in each search to extract a new field of X after the transaction commands.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;|transaction Y maxsplan=5m 
| search "Successful Authentication"  NOT "Failed Authentication"
| stats dc(Y) AS "Successes" by Y 
| appendcols [ 
 |transaction Y maxspan=5m 
 | search "Failed Authentication" NOT "Successful Authentication"
 | stats dc(Y) AS "Failures" by Y
 ] 
|table Successes, Failures, Y
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 30 Dec 2015 15:26:58 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Dedup-consecutive-values-and-count-removed/m-p/211410#M61849</guid>
      <dc:creator>jkat54</dc:creator>
      <dc:date>2015-12-30T15:26:58Z</dc:date>
    </item>
    <item>
      <title>Re: Dedup consecutive values and count removed</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Dedup-consecutive-values-and-count-removed/m-p/211411#M61850</link>
      <description>&lt;P&gt;I can't use a transaction because events can be separated by a long time.&lt;/P&gt;

&lt;P&gt;Here is an example of data :&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;_time                   MESSAGE_CLASS       Calling_Station_ID
2015-12-30 16:38:44.948     Failed-Attempt      00-11-22-33-44-55
2015-12-30 16:38:44.920     Failed-Attempt      00-11-22-33-44-55
2015-12-30 16:18:49.794     Passed-Authentication   00-11-22-33-44-55
2015-12-30 16:18:44.715     Failed-Attempt      00-11-22-33-44-55
2015-12-30 16:18:44.686     Failed-Attempt      00-11-22-33-44-55
2015-12-30 15:58:49.494     Failed-Attempt      66-77-88-99-AA-BB
2015-12-30 15:58:44.458     Passed-Authentication   66-77-88-99-AA-BB
2015-12-30 15:58:44.430     Failed-Attempt      66-77-88-99-AA-BB
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;And what I want in output :&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;Calling_Station_ID  Last Failures
00-11-22-33-44-55   2
66-77-88-99-AA-BB   1
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 30 Dec 2015 16:03:44 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Dedup-consecutive-values-and-count-removed/m-p/211411#M61850</guid>
      <dc:creator>christophe_clem</dc:creator>
      <dc:date>2015-12-30T16:03:44Z</dc:date>
    </item>
    <item>
      <title>Re: Dedup consecutive values and count removed</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Dedup-consecutive-values-and-count-removed/m-p/211412#M61851</link>
      <description>&lt;P&gt;For the sample provided, this will do it&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt; ... | streamstats window=2 current=f last(MESSAGE_CLASS) as l first(MESSAGE_CLASS) as f by Calling_Station_ID | eval c=if(l=f, 1, 0) | stats sum(c) as c by Calling_Station_ID
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 30 Dec 2015 17:04:41 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Dedup-consecutive-values-and-count-removed/m-p/211412#M61851</guid>
      <dc:creator>sundareshr</dc:creator>
      <dc:date>2015-12-30T17:04:41Z</dc:date>
    </item>
    <item>
      <title>Re: Dedup consecutive values and count removed</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Dedup-consecutive-values-and-count-removed/m-p/211413#M61852</link>
      <description>&lt;P&gt;That would pick up the opposite case as well though? ie if there are a series of successful authentications that follow a failure&lt;/P&gt;</description>
      <pubDate>Wed, 30 Dec 2015 17:22:52 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Dedup-consecutive-values-and-count-removed/m-p/211413#M61852</guid>
      <dc:creator>jplumsdaine22</dc:creator>
      <dc:date>2015-12-30T17:22:52Z</dc:date>
    </item>
    <item>
      <title>Re: Dedup consecutive values and count removed</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Dedup-consecutive-values-and-count-removed/m-p/211414#M61853</link>
      <description>&lt;P&gt;What have I done...&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;&amp;lt;your search&amp;gt; | sort _time |  eval series=0 |streamstats current=f window=1 last(MESSAGE_CLASS) as lastmc last(Calling_Station_ID) as lastcs | eval consec=if(lastcs=Calling_Station_ID,1,0) | eval series=if(((MESSAGE_CLASS="Passed-Authenticion") OR (lastmc="Passed-Authenticion" AND consec=1)),1,0) | streamstats current=f window=1 last(series) as lastseries |  eval series=if((lastseries=1 AND consec=1),1,0) | stats sum(series) by Calling_Station_ID
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Will give you &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;Calling_Station_ID     Last Failures
 00-11-22-33-44-55     2
 66-77-88-99-AA-BB     1
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Check the spellings here - I've copied the spelling from your sample data, but it doesn't look correct. If you want to see what's going on here replace the final stats command with &lt;CODE&gt;| table _time Calling_Station_ID  MESSAGE_CLASS lastmc lastcs lastseries consec series&lt;/CODE&gt;.  &lt;/P&gt;

&lt;P&gt;My previous answer is still valid if you're not concerned that a series starts with an "authentication success"message. &lt;/P&gt;

&lt;P&gt;That is, use streamstats to flag each event as being part of a series.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt; ...| streamstats current=f window=1 count as consecutive by X,Y | stats count(consecutive) by X,Y
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Note that  this will drop any values that do not have any consecutive sequences. Try running just &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| streamstats current=f window=1 count as consecutive by X,Y |table X Y consecutive 
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;to see what I mean &lt;/P&gt;

&lt;P&gt;See: &lt;A href="http://docs.splunk.com/Documentation/Splunk/latest/SearchReference/streamstats"&gt;http://docs.splunk.com/Documentation/Splunk/latest/SearchReference/streamstats&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 30 Dec 2015 18:07:00 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Dedup-consecutive-values-and-count-removed/m-p/211414#M61853</guid>
      <dc:creator>jplumsdaine22</dc:creator>
      <dc:date>2015-12-30T18:07:00Z</dc:date>
    </item>
    <item>
      <title>Re: Dedup consecutive values and count removed</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Dedup-consecutive-values-and-count-removed/m-p/211415#M61854</link>
      <description>&lt;P&gt;Problem solved !&lt;/P&gt;

&lt;P&gt;&lt;CODE&gt;| eval lastmc=MESSAGE_CLASS | streamstats current=f count last(MESSAGE_CLASS) as lastmc by Calling_Station_ID | eval consecutive=if(lastmc=MESSAGE_CLASS,1,0) | search consecutive=0 | stats first(MESSAGE_CLASS) AS prevmc first(count) AS count by Calling_Station_ID | search prevmc="Passed-Authentication"&lt;/CODE&gt;&lt;/P&gt;

&lt;P&gt;First eval is only here for the second eval, in other words: the first event is consecutive to himself.&lt;BR /&gt;
I compute a "consecutive" field as you've done, and then I only keep lines where &lt;CODE&gt;consecutive=0&lt;/CODE&gt;.&lt;BR /&gt;
After that, I use a &lt;CODE&gt;stats&lt;/CODE&gt; to select the first (newest) line and get the count of previous events.&lt;BR /&gt;
Finally, I keep lines where &lt;CODE&gt;prevmc="Passed-Authentication"&lt;/CODE&gt;, meaning previous events were "Failed-Attempt".&lt;/P&gt;

&lt;P&gt;Thank you guys for your help &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 31 Dec 2015 11:02:55 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Dedup-consecutive-values-and-count-removed/m-p/211415#M61854</guid>
      <dc:creator>christophe_clem</dc:creator>
      <dc:date>2015-12-31T11:02:55Z</dc:date>
    </item>
    <item>
      <title>Re: Dedup consecutive values and count removed</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Dedup-consecutive-values-and-count-removed/m-p/211416#M61855</link>
      <description>&lt;P&gt;Click "Accept" on your answer.&lt;/P&gt;</description>
      <pubDate>Thu, 31 Dec 2015 23:14:38 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Dedup-consecutive-values-and-count-removed/m-p/211416#M61855</guid>
      <dc:creator>woodcock</dc:creator>
      <dc:date>2015-12-31T23:14:38Z</dc:date>
    </item>
    <item>
      <title>Re: Dedup consecutive values and count removed</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Dedup-consecutive-values-and-count-removed/m-p/211417#M61856</link>
      <description>&lt;P&gt;Change the maxspan to equal whatever amount of time you desire... 1d,... 1mon... etc.  I gave you example with 5minutes.&lt;/P&gt;</description>
      <pubDate>Mon, 04 Jan 2016 17:14:59 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Dedup-consecutive-values-and-count-removed/m-p/211417#M61856</guid>
      <dc:creator>jkat54</dc:creator>
      <dc:date>2016-01-04T17:14:59Z</dc:date>
    </item>
  </channel>
</rss>

