Getting Data In

how to search events within few minutes of given date time

arusoft
Path Finder

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
Path Finder

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
Path Finder

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
Path Finder

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
Path Finder

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!

Maximize the Value from Microsoft Defender with Splunk

 Watch NowJoin Splunk and Sens Consulting for this Security Edition Tech TalkWho should attend:  Security ...

This Week's Community Digest - Splunk Community Happenings [6.27.22]

Get the latest news and updates from the Splunk Community here! News From Splunk Answers ✍️ Splunk Answers is ...

Reminder! Splunk Love Promo: $25 Visa Gift Card for Your Honest SOAR Review With ...

We recently launched our first Splunk Love Special, and it's gone phenomenally well, so we're doing it again, ...