Splunk Search

How to set earliest and latest time based on current time in savedSearch

Thulasinathan_M
Contributor

Hi Splunk Experts,

I've a scheduled savedSearch where it runs every 5 mins, with the Schedule window of 2 minutes. Instead of searching for last 5 mins, I want to achieve something like 00 to 05 mins, 05 to 10 mins, 10 to 15 mins and so on. Is it possible to achieve this in the search, could someone please shred some lights. Thanks in advance!!

| eval STime=now()-300, ETime=now()
| bin STime span=5m
| bin ETime span=5m

 

Tags (1)
0 Karma
1 Solution

ITWhisperer
SplunkTrust
SplunkTrust

Try adding this to your initial search

<your search>    [| makeresults
    | addinfo
    | eval latest=info_max_time-(info_max_time%300)
    | eval earliest=latest-300
    | fields earliest latest]

View solution in original post

ITWhisperer
SplunkTrust
SplunkTrust

I am not entirely sure I understand your requirement. However, if you want a scheduled report to run every 5 minutes at 2 minutes past, 7 minutes past, 12 minutes past, etc. with a search window of 0-5,  5-10, 10-12 etc., you would schedule the report with this cron expression

2-57/5 * * * *

and a timepicker setting like this

earliest=@m-7m
latest=@m-2m
0 Karma

Thulasinathan_M
Contributor

Hi @ITWhisperer 

Thanks for the assistance, let me try to break-down my requirement:

I scheduled a report to run */5 * * * * (Every 5 mins), with scheduler window of 2 mins (the scheduler can kick-off the report anytime within this 2 mins window). But irrespective of the time when it gets kicked-off I want to search the index for accurate 5 mins.
Lets say the scheduler started at 11:16:32.000 but I want to search in index within time of (earliest 11:10:00.000, latest 11:15:00.000).

0 Karma

ITWhisperer
SplunkTrust
SplunkTrust

Try adding this to your initial search

<your search>    [| makeresults
    | addinfo
    | eval latest=info_max_time-(info_max_time%300)
    | eval earliest=latest-300
    | fields earliest latest]

Thulasinathan_M
Contributor

Thanks @ITWhisperer. Working like a charm!! 🙂

0 Karma
Career Survey
First 500 qualified respondents will receive a $20 gift card! Tell us about your professional Splunk journey.

Can’t make it to .conf25? Join us online!

Get Updates on the Splunk Community!

Community Content Calendar, September edition

Welcome to another insightful post from our Community Content Calendar! We're thrilled to continue bringing ...

Splunkbase Unveils New App Listing Management Public Preview

Splunkbase Unveils New App Listing Management Public PreviewWe're thrilled to announce the public preview of ...

Leveraging Automated Threat Analysis Across the Splunk Ecosystem

Are you leveraging automation to its fullest potential in your threat detection strategy?Our upcoming Security ...