Splunk Search

How to search for an event that happened within 5 minutes of its previous occurrence and display both events in the results?

NimrodSky
Explorer

I'm using this search to find an event that happened within 5 minutes of its previous occurrence:

 ... | reverse | streamstats current=f last(_time) AS prevTime | eval span=_time - prevTime | where span < 300

I get the event as a result, but I also want to show in the results the event I was comparing it to. How can I do that?

0 Karma
1 Solution

woodcock
Esteemed Legend

Either like this:

... | reverse | streamstats current=f last(_time) AS prevTime last(_raw) AS prevEvent | eval span = _time - prevTime | where span < 300

Or like ths:

... | streamstats current=f last(_time) AS nextTime | reverse | streamstats current=f last(_time) AS prevTime | eval forespan = nextTime - _time | eval backspan= _time - prevTime | where backspan < 300 OR forespan < 300

View solution in original post

0 Karma

woodcock
Esteemed Legend

Either like this:

... | reverse | streamstats current=f last(_time) AS prevTime last(_raw) AS prevEvent | eval span = _time - prevTime | where span < 300

Or like ths:

... | streamstats current=f last(_time) AS nextTime | reverse | streamstats current=f last(_time) AS prevTime | eval forespan = nextTime - _time | eval backspan= _time - prevTime | where backspan < 300 OR forespan < 300
0 Karma

NimrodSky
Explorer

Thanks 🙂

What I did was to keep the relevant field from the previous message using the streamstats current=f last command, and then showing them in the query result (using table xxx).

0 Karma
Get Updates on the Splunk Community!

Join Us for Splunk University and Get Your Bootcamp Game On!

If you know, you know! Splunk University is the vibe this summer so register today for bootcamps galore ...

.conf24 | Learning Tracks for Security, Observability, Platform, and Developers!

.conf24 is taking place at The Venetian in Las Vegas from June 11 - 14. Continue reading to learn about the ...

Announcing Scheduled Export GA for Dashboard Studio

We're excited to announce the general availability of Scheduled Export for Dashboard Studio. Starting in ...