I have been looking all over and still not able to get this working. I saw few links here and still none helps.
Lets say I have a date time of "07/17/2019:15:01:45".
so i want to search all events few seconds before above date time and few minutes after above date time.
In a dashboard, I am basically trying to control sub panel search date time based on another panel date time.
Thank You
This helped me
https://answers.splunk.com/answers/216158/how-can-i-modify-earliest-time-and-latest-time-bef.html
finally this is how my query looks like and it works. I the below example 600 is in seconds. So in this example basically i am looking events that happend 10 minutes before or after around my desired time"07/17/2019:15:01:45"
[search
<Any dummy search from your index that returns at least one record>
| head 1
| eval earliest="07/17/2019:15:01:45"
| eval earliest=strptime(earliest, "%m/%d/%Y:%H:%M:%S")
| eval latest=earliest+600
| eval earliest=earliest-600
| table earliest,latest
]
< Your actual search go here>
you can also use inputlook for ever faster results like this. Here make sure you have a dummy file DummyFileWithOneRecord.csv with atleast one record
[
| inputlookup DummyFileWithOneRecord.csv
| head 1
| eval earliest="07/17/2019:15:01:45"
| eval earliest=strptime(earliest, "%m/%d/%Y:%H:%M:%S")
| eval latest=earliest+600
| eval earliest=earliest-600
| table earliest,latest
]
< Your actual search go here>
This helped me
https://answers.splunk.com/answers/216158/how-can-i-modify-earliest-time-and-latest-time-bef.html
finally this is how my query looks like and it works. I the below example 600 is in seconds. So in this example basically i am looking events that happend 10 minutes before or after around my desired time"07/17/2019:15:01:45"
[search
<Any dummy search from your index that returns at least one record>
| head 1
| eval earliest="07/17/2019:15:01:45"
| eval earliest=strptime(earliest, "%m/%d/%Y:%H:%M:%S")
| eval latest=earliest+600
| eval earliest=earliest-600
| table earliest,latest
]
< Your actual search go here>
you can also use inputlook for ever faster results like this. Here make sure you have a dummy file DummyFileWithOneRecord.csv with atleast one record
[
| inputlookup DummyFileWithOneRecord.csv
| head 1
| eval earliest="07/17/2019:15:01:45"
| eval earliest=strptime(earliest, "%m/%d/%Y:%H:%M:%S")
| eval latest=earliest+600
| eval earliest=earliest-600
| table earliest,latest
]
< Your actual search go here>
Wanted to update that for no reason next day my code didn't worked. I was getting some error message that I didn't saved to mention here. After searching online I added | format "(" "(" "" ")" "OR" ")"
at the end of sub search and then it worked. And today its working with or without this additional line of code. So if your code too doesn't work then add this line as shown below.
[
| inputlookup DummyFileWithOneRecord.csv
| head 1
| eval earliest="07/17/2019:15:01:45"
| eval earliest=strptime(earliest, "%m/%d/%Y:%H:%M:%S")
| eval latest=earliest+600
| eval earliest=earliest-600
| table earliest,latest
| format "(" "(" "" ")" "OR" ")"
]
< Your actual search go here>
I tried earliest= "07/17/2019:15:01:45" latest="07/18/2019:15:01:45"
.. this works. But i don't want to hard code like this. I want to add or subtract minutes or hours or days.