Splunk Search

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

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

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
Don’t Miss Global Splunk
User Groups Week!

Free LIVE events worldwide 2/8-2/12
Connect, learn, and collect rad prizes
and swag!