Splunk Search

streamstats | reset_after condition not applied within the scope of each user (field)

ralam
Explorer

Hi Team,

What I'm trying to achieve: Find the consecutive failure events followed by a success event.

 

| makeresults | eval _raw="username,result
user1,fail
user2,success
user3,success
user1,fail
user1,fail
user1,success
user2,fail
user3,success
user2,fail
user1,fail"
| multikv forceheader=1
| streamstats count(eval(result="fail")) as fail_counter by username,result reset_after="("result==\"success\"")"
| table  username,result,fail_counter

 


Outcome: The counter (fail_counter) gets reset for a user (say user1) if the next event is a success event for a different user (say, user2).

usernameresultfail_counter 
user1fail1 
user2success0 
user3success0 
user1fail1<- counter reset for user1. It should be 2.
user1fail2It should be 3.
user1success0 
user2fail1 
user3success0 
user2fail1 
user1fail1 


Expected: The counter should not reset if the success event for user2 follows the failure event for user1.


I would appreciate any help on this. Not sure what I'm missing here.

Labels (1)
Tags (1)
0 Karma
1 Solution

ITWhisperer
SplunkTrust
SplunkTrust

You could try sorting by username before the streamstats

View solution in original post

PickleRick
SplunkTrust
SplunkTrust

The docs on the streamstats command say that "all accumulated statistics" are reset on reset_* options. That would imply that the reset is global, not on a per "by-field(s)" basis.

It could call for docs feedback to make it more explicitly stated.

The practical solution to this you already got from @ITWhisperer 🙂

ITWhisperer
SplunkTrust
SplunkTrust

You could try sorting by username before the streamstats

Got questions? Get answers!

Join the Splunk Community Slack to learn, troubleshoot, and make connections with fellow Splunk practitioners in real time!

Meet up IRL or virtually!

Join Splunk User Groups to connect and learn in-person by region or remotely by topic or industry.

Get Updates on the Splunk Community!

Why Splunk Customers Should Attend Cisco Live 2026 Las Vegas

Why Splunk Customers Should Attend Cisco Live 2026 Las Vegas     Cisco Live 2026 is almost here, and this ...

What Is the Name of the USB Key Inserted by Bob Smith? (BOTS Hint, Not the Answer)

Hello Splunkers,   So you searched, “what is the name of the usb key inserted by bob smith?”  Not gonna lie… ...

Automating Threat Operations and Threat Hunting with Recorded Future

    Automating Threat Operations and Threat Hunting with Recorded Future June 29, 2026 | Register   Is your ...