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!

2024 Splunk Career Impact Survey | Earn a $20 gift card for participating!

Hear ye, hear ye! The time has come again for Splunk's annual Career Impact Survey!  We need your help by ...

Optimize Cloud Monitoring

  TECH TALKS Optimize Cloud Monitoring Tuesday, August 13, 2024  |  11:00AM–12:00PM PST   Register to ...

What's New in Splunk Cloud Platform 9.2.2403?

Hi Splunky people! We are excited to share the newest updates in Splunk Cloud Platform 9.2.2403! Analysts can ...