Getting Data In

Current date exclusion from search events

drewbfl
Path Finder

I have an event that contains the following date format/range text within it:

2011-10-07T00:00:00.000Z-2011-10-07T12:00:00.000Z

I would like to exclude any events whose second part of that range (in this case 2011-10-07T12:00:00.000Z) are within 24hrs of current time.

I have tried using now() with fields and reformatting, then using rex mode=sed to exclude now() but I am missing something.

Thanks.

1 Solution

hexx
Splunk Employee
Splunk Employee

1 - Extract the boundaries of your time range into their own fields. Let's say latest_time_boundary and earliest_time_boundary. You can use an inline rex to do this.

Quick and dirty example :

| rex (?<earliest_time_boundary>(\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{3}Z)-(?<latest_time_boundary>\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{3}Z)

2 - Use convert's mktime() function to convert the boundaries of your time range to epoch times. This would look like :

| convert timeformat=%Y-%m-%dT%H:%M:%S.%3NZ mktime(latest_time_boundary)

3 - Using eval, create a new field that shows the delta in seconds between the time at which the search ran (now()) and the upper boundary of the time range :

| eval elapsed_seconds=(now() - latest_time_boundary)

4 - Exclude any events for which that delta is less than 24 hours / 86,400 seconds :

| search elapsed_seconds>86400

View solution in original post

hexx
Splunk Employee
Splunk Employee

1 - Extract the boundaries of your time range into their own fields. Let's say latest_time_boundary and earliest_time_boundary. You can use an inline rex to do this.

Quick and dirty example :

| rex (?<earliest_time_boundary>(\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{3}Z)-(?<latest_time_boundary>\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{3}Z)

2 - Use convert's mktime() function to convert the boundaries of your time range to epoch times. This would look like :

| convert timeformat=%Y-%m-%dT%H:%M:%S.%3NZ mktime(latest_time_boundary)

3 - Using eval, create a new field that shows the delta in seconds between the time at which the search ran (now()) and the upper boundary of the time range :

| eval elapsed_seconds=(now() - latest_time_boundary)

4 - Exclude any events for which that delta is less than 24 hours / 86,400 seconds :

| search elapsed_seconds>86400

drewbfl
Path Finder

Thanks, worked perfect!

Get Updates on the Splunk Community!

Introducing the 2024 SplunkTrust!

Hello, Splunk Community! We are beyond thrilled to announce our newest group of SplunkTrust members!  The ...

Introducing the 2024 Splunk MVPs!

We are excited to announce the 2024 cohort of the Splunk MVP program. Splunk MVPs are passionate members of ...

Splunk Custom Visualizations App End of Life

The Splunk Custom Visualizations apps End of Life for SimpleXML will reach end of support on Dec 21, 2024, ...