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!

Splunk Observability Cloud's AI Assistant in Action Series: Auditing Compliance and ...

This is the third post in the Splunk Observability Cloud’s AI Assistant in Action series that digs into how to ...

Splunk Community Badges!

  Hey everyone! Ready to earn some serious bragging rights in the community? Along with our existing badges ...

What You Read The Most: Splunk Lantern’s Most Popular Articles!

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