Splunk Search

How to find events that haven't happened in a given amount of time?

atebysandwich
Path Finder

I'm looking over vulnerability scan data and have the _time field formatted as 

 

| eval Last_Scanned = strftime(time, "%F")

 

How can I created a search to show hosts(events) that have not been scanned within two weeks of the current date?

Labels (3)
0 Karma
1 Solution

rut
Path Finder

Grouping by host and then filtering using relative_time should work. This only leaves you the date and host though, so maybe you'll want to add some fields to the stats command.

| stats max(_time) as Last_Scanned by host
| where Last_Scanned<relative_time(now(), "-2w")

 

View solution in original post

0 Karma

PickleRick
SplunkTrust
SplunkTrust

It depends whether you can find those hosts by expanding your time range. If you can, just find max(_time) by host and check if it falls within needed range. If you can't, you must have a static list of hosts to compare events in your index with. You can't find something if it's not there.

0 Karma

rut
Path Finder

Grouping by host and then filtering using relative_time should work. This only leaves you the date and host though, so maybe you'll want to add some fields to the stats command.

| stats max(_time) as Last_Scanned by host
| where Last_Scanned<relative_time(now(), "-2w")

 

0 Karma

atebysandwich
Path Finder

I ad to do some tweaking to make some of it work. when I did

| stats max(Last_Scanned) by IP

I got all the IPs and their last scan time. However, when I did the second line, no results were found. 

It should be noted that earlier in the search _time was specified as time 

Tags (1)
0 Karma

PickleRick
SplunkTrust
SplunkTrust

You can't do max() on non-numerical field. When you did your strftime() you lost the ability to calculate/compare timestamps.

0 Karma

rut
Path Finder

OK, so are you adding the lines on _time or your formatted time? In your original question you added the following line:

 

| eval Last_Scanned = strftime(time, "%F")

 

%F = Equivalent to %Y-%m-%d (the ISO 8601 date format).

The command max and the comparison with relative_time are expecting a timestamp, not formatted time. So you can either use the original timestamp or use strptime to transform it back.

See the following docs for more information.

strptime:

https://docs.splunk.com/Documentation/Splunk/latest/SearchReference/DateandTimeFunctions#strptime.28...

relative_time:

https://docs.splunk.com/Documentation/Splunk/latest/SearchReference/DateandTimeFunctions#relative_ti...

Formats:

https://docs.splunk.com/Documentation/Splunk/9.0.4/SearchReference/Commontimeformatvariables#Time_va...

0 Karma

atebysandwich
Path Finder

I removed strftime and moved a lookup after the searches you mentioned and it worked. 

0 Karma
Get Updates on the Splunk Community!

Prove Your Splunk Prowess at .conf25—No Prereqs Required!

Your Next Big Security Credential: No Prerequisites Needed We know you’ve got the skills, and now, earning the ...

Splunk Observability Cloud's AI Assistant in Action Series: Observability as Code

This is the sixth post in the Splunk Observability Cloud’s AI Assistant in Action series that digs into how to ...

Splunk Answers Content Calendar, July Edition I

Hello Community! Welcome to another month of Community Content Calendar series! For the month of July, we will ...