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!

Detecting Remote Code Executions With the Splunk Threat Research Team

REGISTER NOWRemote code execution (RCE) vulnerabilities pose a significant risk to organizations. If ...

Observability | Use Synthetic Monitoring for Website Metadata Verification

If you are on Splunk Observability Cloud, you may already have Synthetic Monitoringin your observability ...

More Ways To Control Your Costs With Archived Metrics | Register for Tech Talk

Tuesday, May 14, 2024  |  11AM PT / 2PM ET Register to Attend Join us for this Tech Talk and learn how to ...