Getting Data In

how to search events within few minutes of given date time

arusoft
Communicator

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

0 Karma
1 Solution

arusoft
Communicator

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>

View solution in original post

0 Karma

arusoft
Communicator

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>
0 Karma

arusoft
Communicator

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>
0 Karma

arusoft
Communicator

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.

0 Karma
Get Updates on the Splunk Community!

Stay Connected: Your Guide to May Tech Talks, Office Hours, and Webinars!

Take a look below to explore our upcoming Community Office Hours, Tech Talks, and Webinars this month. This ...

They're back! Join the SplunkTrust and MVP at .conf24

With our highly anticipated annual conference, .conf, comes the fez-wearers you can trust! The SplunkTrust, as ...

Enterprise Security Content Update (ESCU) | New Releases

Last month, the Splunk Threat Research Team had two releases of new security content via the Enterprise ...