Splunk Search

Get first and last event by ID

benhooper
Communicator

Is there an easy way to get the first and last event by a unique ID?

"transaction" seems to be the way to go but I haven't been able to figure out how to remove the in-between events / values then split them back out into individual events.

Labels (2)
0 Karma
1 Solution

benhooper
Communicator

I've achieved this with the following search:

<base search>
| dedup case_id, status
| reverse
| streamstats current=f last(status) as lastStatus by case_id
| eval firstEvent = if((status == "new" OR status == "in_progress") AND isnull(lastStatus), "True", "False")
| eval lastEvent = if(match(status, "resolved"), "True", "False")
| where firstEvent == "True" OR lastEvent  == "True"
| <other stuff>

View solution in original post

0 Karma

richgalloway
SplunkTrust
SplunkTrust

Have you tried stats?

... | stats earliest(_raw) as firstEvent, latest(_raw) as lastEvent by foo

 

---
If this reply helps you, Karma would be appreciated.
0 Karma

benhooper
Communicator

Thanks for that.

It does sort of work but there's a few issues:

  1. It splits the events into columns but I need to use things like "streamstats" on each of the events and I'm unsure whether that's possible with this.
  2. Sometimes each unique ID only has 1 event and this duplicates them.
0 Karma

benhooper
Communicator

I've achieved this with the following search:

<base search>
| dedup case_id, status
| reverse
| streamstats current=f last(status) as lastStatus by case_id
| eval firstEvent = if((status == "new" OR status == "in_progress") AND isnull(lastStatus), "True", "False")
| eval lastEvent = if(match(status, "resolved"), "True", "False")
| where firstEvent == "True" OR lastEvent  == "True"
| <other stuff>
0 Karma
Get Updates on the Splunk Community!

Index This | When is October more than just the tenth month?

October 2025 Edition  Hayyy Splunk Education Enthusiasts and the Eternally Curious!   We’re back with this ...

Observe and Secure All Apps with Splunk

  Join Us for Our Next Tech Talk: Observe and Secure All Apps with SplunkAs organizations continue to innovate ...

What’s New & Next in Splunk SOAR

 Security teams today are dealing with more alerts, more tools, and more pressure than ever.  Join us for an ...