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
Career Survey
First 500 qualified respondents will receive a $20 gift card! Tell us about your professional Splunk journey.

Can’t make it to .conf25? Join us online!

Get Updates on the Splunk Community!

Community Content Calendar, September edition

Welcome to another insightful post from our Community Content Calendar! We're thrilled to continue bringing ...

Splunkbase Unveils New App Listing Management Public Preview

Splunkbase Unveils New App Listing Management Public PreviewWe're thrilled to announce the public preview of ...

Leveraging Automated Threat Analysis Across the Splunk Ecosystem

Are you leveraging automation to its fullest potential in your threat detection strategy?Our upcoming Security ...