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!

Stay Connected: Your Guide to May Tech Talks, Office Hours, and Webinars!

Take a look below to explore our upcoming Community Office Hours, Tech Talks, and Webinars this month. This ...

They're back! Join the SplunkTrust and MVP at .conf24

With our highly anticipated annual conference, .conf, comes the fez-wearers you can trust! The SplunkTrust, as ...

Enterprise Security Content Update (ESCU) | New Releases

Last month, the Splunk Threat Research Team had two releases of new security content via the Enterprise ...