Splunk Search

How do I specify relative time ranges for an extracted field?

Callumfranks
Engager

Hello,

I am trying to specify a relative time range for a specific field in my search rather than the "_time" field (i.e finding the last 36 hour results on a field called "LogOut"). I cannot just do this "on _time" as I need to create a transaction on some fields, and when searched on _time, it brings results I do not want to see as I have keepevicted results on.

Thanks

0 Karma

kmaron
Motivator

What you need to do is determine the "start time" and "end time" values to compare them to your field for time. That can be done in various ways depending on how you're calculating.

I've done this in a dashboard comparing against a field called "activity_time" and using the earliest and latest time from the timepicker (token name TimeRange). This is how I did it but there may be a better/easier way.

| eval start_time=relative_time(now(),"$TimeRange.earliest$")
| eval start_time2="$TimeRange.earliest$"
| eval start_time=if(start_time>0,start_time,start_time2)
| eval end_time=relative_time(now(),"$TimeRange.latest$")
| eval end_time2="$TimeRange.latest$"
| eval end_time=if(end_time2="now",9999999999,end_time)
| eval end_time=if(end_time>0,end_time,end_time2)
| where activity_time>=start_time AND activity_time<=end_time

so for 'Yesterday' this turns into:

| eval start_time=relative_time(now(),"-1d@d")
| eval start_time2="-1d@d"
| eval start_time=if(start_time>0,start_time,start_time2)
| eval end_time=relative_time(now(),"@d")
| eval end_time2="@d"
| eval end_time=if(end_time2="now",9999999999,end_time)
| eval end_time=if(end_time>0,end_time,end_time2)
| where activity_time>=start_time AND activity_time<=end_time

Hopefully this helps.

0 Karma
Get Updates on the Splunk Community!

Stay Connected: Your Guide to May Tech Talks, Office Hours, and Webinars!

Take a look below to explore our upcoming Community Office Hours, Tech Talks, and Webinars this month. This ...

They're back! Join the SplunkTrust and MVP at .conf24

With our highly anticipated annual conference, .conf, comes the fez-wearers you can trust! The SplunkTrust, as ...

Enterprise Security Content Update (ESCU) | New Releases

Last month, the Splunk Threat Research Team had two releases of new security content via the Enterprise ...