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!

Announcing Scheduled Export GA for Dashboard Studio

We're excited to announce the general availability of Scheduled Export for Dashboard Studio. Starting in ...

Extending Observability Content to Splunk Cloud

Watch Now!   In this Extending Observability Content to Splunk Cloud Tech Talk, you'll see how to leverage ...

More Control Over Your Monitoring Costs with Archived Metrics GA in US-AWS!

What if there was a way you could keep all the metrics data you need while saving on storage costs?This is now ...