Splunk Search

How to combine a search that relies on latest(_time) for two different fields

ebs
Communicator

Hi,

I want to create a search that is able to grab both the start and end times of a specific action, but to create the fields they both use latest(_time). Here are the two searches I want to combine:

Start:

index=index_name act="LDAP Synchronization start" | stats latest(_time) as start | eval "LDAP Sync Start"=strftime(start,"%d/%m/%Y %H:%M:%S")

End:

index=index_name act="LDAP Synchronization end" | stats latest(_time) as end | eval "LDAP Sync End"=strftime(end,"%d/%m/%Y %H:%M:%S")

How can I combine these two searches into one search, especially since I rely on the same stats command to create the field?

0 Karma
1 Solution

bowesmana
SplunkTrust
SplunkTrust

Like this

index=index_name act="LDAP Synchronization start" OR act="LDAP Synchronization end"
| stats max(eval(if(act="LDAP Synchronization start", _time, 0))) as start max(eval(if(act="LDAP Synchronization end", _time, 0))) as end
| eval "LDAP Sync Start"=strftime(start,"%d/%m/%Y %H:%M:%S"), "LDAP Sync End"=strftime(end,"%d/%m/%Y %H:%M:%S")

i.e. use an eval in the stats so that the max _time (i.e. latest) of start and end time is evaluated during aggregation.

 

View solution in original post

bowesmana
SplunkTrust
SplunkTrust

Like this

index=index_name act="LDAP Synchronization start" OR act="LDAP Synchronization end"
| stats max(eval(if(act="LDAP Synchronization start", _time, 0))) as start max(eval(if(act="LDAP Synchronization end", _time, 0))) as end
| eval "LDAP Sync Start"=strftime(start,"%d/%m/%Y %H:%M:%S"), "LDAP Sync End"=strftime(end,"%d/%m/%Y %H:%M:%S")

i.e. use an eval in the stats so that the max _time (i.e. latest) of start and end time is evaluated during aggregation.

 

Get Updates on the Splunk Community!

Upcoming Webinar: Unmasking Insider Threats with Slunk Enterprise Security’s UEBA

Join us on Wed, Dec 10. at 10AM PST / 1PM EST for a live webinar and demo with Splunk experts! Discover how ...

.conf25 technical session recap of Observability for Gen AI: Monitoring LLM ...

If you’re unfamiliar, .conf is Splunk’s premier event where the Splunk community, customers, partners, and ...

A Season of Skills: New Splunk Courses to Light Up Your Learning Journey

There’s something special about this time of year—maybe it’s the glow of the holidays, maybe it’s the ...