Splunk Search

Setting up query running time

Kwip
Contributor

I am having a dashboard which comprises of several panels. It serves the monitoring of set of jobs.

Jobs cycle started at every day 7 AM and completes around next day 5 AM. Say Example 07/18/2017 7AM to 07/19/2017 5AM. So i want to set the earliest time at 7 am at any point time throughout the cycle.

I may run the dashboard at 07/18/2017 8AM 8.30AM 9AM and so on. It may continue till 07/19/2017 02AM, 02.30AM 3AM 3.30AM, 4.30AM and so on.

So whenever i am running my dashboard it should from 7AM whether on the same day or next day.

Please advice the feasibility on the same.

0 Karma
1 Solution

Kwip
Contributor

The below query serving my need.

your base search 
[| makeresults 
| eval earliest=if(now()<=relative_time(now(),"@d+5h"),"-1d@d+7h","@d+7h") 
| eval latest="now" | table earliest latest ]

View solution in original post

0 Karma

Kwip
Contributor

The below query serving my need.

your base search 
[| makeresults 
| eval earliest=if(now()<=relative_time(now(),"@d+5h"),"-1d@d+7h","@d+7h") 
| eval latest="now" | table earliest latest ]
0 Karma

adonio
Ultra Champion

maybe add this to all your searches?
earliest=@d+7h

0 Karma

Kwip
Contributor

This won't working when we cross the midnight

0 Karma

Kwip
Contributor

Thank you for your response

0 Karma

woodcock
Esteemed Legend

Use a subsearch, something like this:

index=YouShoulAlwaysSpecifyAnIndex sourcetype=AndAlsoAlwaysSpecifySourcetype [| makeresults 
| eval now=now() 
| eval earliest=relative_time(now, "@d+1d+7h") 
| eval earliest=if((earliest<now), earliest, relative_time(now, "@d+7h")) 
| eval search = "earliest=" . earliest
| table search]

You might have to fix the logic for "today's 7AM" vs "tomorrow's 7AM" but this will programatically set the start time of the search based on what time it is "now" (when the search is run).

0 Karma

Kwip
Contributor

@woodcock, Great! it is working fine. Thank you very much!!!

0 Karma

Kwip
Contributor

@woodcock,
Getting the below error, when it is crossing the midnight

Error in 'litsearch' command: Unable to parse the search: Invalid time bounds in search: start=1514379600 > end=1514357190.

0 Karma
Get Updates on the Splunk Community!

Unlock Database Monitoring with Splunk Observability Cloud

  In today’s fast-paced digital landscape, even minor database slowdowns can disrupt user experiences and ...

Purpose in Action: How Splunk Is Helping Power an Inclusive Future for All

At Cisco, purpose isn’t a tagline—it’s a commitment. Cisco’s FY25 Purpose Report outlines how the company is ...

[Upcoming Webinar] Demo Day: Transforming IT Operations with Splunk

Join us for a live Demo Day at the Cisco Store on January 21st 10:00am - 11:00am PST In the fast-paced world ...