Splunk Search

how to reduce multiple results into one based on the earliest time

djoobbani
Path Finder

Hi there:

I have the following query:

source=accountCalc type=acct.change msg="consumed" event_id="*" process_id="*" posted_ timestamp =”*” msg_ timestamp =”*”
| eval e1_t=strptime(posted_ timestamp, "%FT%T")

| eval e2_t=strptime(msg_ timestamp, "%FT%T")

| eval lag_in_seconds=e1_t-e2_t

| eval r2_posted_timestamp=posted_time

| table event_id process_id msg_timestamp r2_posted_timestamp lag_in_seconds

The above query can return multiple events with the same event_id & process_id with different posted_ timestamp

I need to only return the one with the earliest/oldest posted_time(one of the fields in the event).
How can i change the above query to accomplish this?

Thanks!

Labels (3)
0 Karma
1 Solution

ITWhisperer
SplunkTrust
SplunkTrust

Try something like this

source=accountCalc type=acct.change msg="consumed" event_id="*" process_id="*" posted_ timestamp =”*” msg_ timestamp =”*”
| eval e1_t=strptime(posted_ timestamp, "%FT%T")
| eval e2_t=strptime(msg_ timestamp, "%FT%T")
| eval lag_in_seconds=e1_t-e2_t
| eval r2_posted_timestamp=posted_time
| table event_id process_id msg_timestamp r2_posted_timestamp lag_in_seconds e1_t
| sort 0 e1_t
| dedup event_id process_id

View solution in original post

ITWhisperer
SplunkTrust
SplunkTrust

Try something like this

source=accountCalc type=acct.change msg="consumed" event_id="*" process_id="*" posted_ timestamp =”*” msg_ timestamp =”*”
| eval e1_t=strptime(posted_ timestamp, "%FT%T")
| eval e2_t=strptime(msg_ timestamp, "%FT%T")
| eval lag_in_seconds=e1_t-e2_t
| eval r2_posted_timestamp=posted_time
| table event_id process_id msg_timestamp r2_posted_timestamp lag_in_seconds e1_t
| sort 0 e1_t
| dedup event_id process_id

inventsekar
SplunkTrust
SplunkTrust

Hi @djoobbani .. please check this SPL.. thanks. 

source=accountCalc type=acct.change msg="consumed" event_id="*" process_id="*" posted_ timestamp =”*” msg_ timestamp =”*”
| eval e1_t=strptime(posted_ timestamp, "%FT%T")
| eval e2_t=strptime(msg_ timestamp, "%FT%T")
| eval lag_in_seconds=e1_t-e2_t
| eval r2_posted_timestamp=posted_time
| stats earliest(r2_posted_timestamp) AS Earliest_r2_posted_timestamp, latest(r2_posted_timestamp) AS Latest_r2_posted_timestamp  
| table event_id process_id msg_timestamp r2_posted_timestamp lag_in_seconds Earliest_r2_posted_timestamp Latest_r2_posted_timestamp 

 

thanks and best regards,
Sekar

PS - If this or any post helped you in any way, pls consider upvoting, thanks for reading !

djoobbani
Path Finder

This query does show the earliest posted_timestamp. However, all the other fields are blank for the table command for fields (event_id, process_id, msg_timestamp, lag_in_seconds)

Thanks!

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!

Can’t Make It to Boston? Stream .conf25 and Learn with Haya Husain

Boston may be buzzing this September with Splunk University and .conf25, but you don’t have to pack a bag to ...

Splunk Lantern’s Guide to The Most Popular .conf25 Sessions

Splunk Lantern is a Splunk customer success center that provides advice from Splunk experts on valuable data ...

Unlock What’s Next: The Splunk Cloud Platform at .conf25

In just a few days, Boston will be buzzing as the Splunk team and thousands of community members come together ...