Splunk Search

How to search for events before a given time if the event time is dynamically generated?

Kanesol
Explorer

I have a search that finds bad events and I want to use the results to look back in time (a day for example) and see if any of those events exist in the past but are not logged as "bad".

For example:
Proxy blacklists a hostname based on an external feed and now I would like to go back from this event and investigate if there was activity before this time.

My attempts have followed the bellow:

index="proxy" proxyblock=false  [search index="the proxy" "badness" earliest=-1d | dedup hostname | return 1000 hostname]

The problem with this is that it will return events after as well as before (I am not so interested in events after the time of the first badness being detected because a) they were blocked b) I have other searches for that c) the feed is dynamic so something might be listed as bad for 2hrs and then get cleaned and then be listed as ok and I don't want to waste time on "good" events)

Thanks in advance

Tags (3)
0 Karma
1 Solution

martin_mueller
SplunkTrust
SplunkTrust

Try this:

  index="the proxy" "badness" earliest=-1d | dedup hostname | eval start = relative_time(_time, "-d")
| map maxsearches=42 search="search earliest=$start$ latest=$_time$ index=proxy proxyblock=false hostname=$hostname$"

That'll kick off a search for each returned hostname, using that event as the (non-inclusive) end of the one-day timerange.

View solution in original post

martin_mueller
SplunkTrust
SplunkTrust

Try this:

  index="the proxy" "badness" earliest=-1d | dedup hostname | eval start = relative_time(_time, "-d")
| map maxsearches=42 search="search earliest=$start$ latest=$_time$ index=proxy proxyblock=false hostname=$hostname$"

That'll kick off a search for each returned hostname, using that event as the (non-inclusive) end of the one-day timerange.

HeinzWaescher
Motivator

What about an approach like this:

 index="proxy" proxyblock=false  [search index="the proxy" "badness" earliest=-1d | dedup hostname | return 1000 hostname]
| stats earliest(_time) AS earliest_time, earliest(eval(if(flag="badness", _time, null()))) AS earliest_badness_time BY hostname
| where earliest_time<earliest_badness_time

The results should only show hostnames with activitiy before flagged as "bad"

0 Karma
Get Updates on the Splunk Community!

More Ways To Control Your Costs With Archived Metrics | Register for Tech Talk

Tuesday, May 14, 2024  |  11AM PT / 2PM ET Register to Attend Join us for this Tech Talk and learn how to ...

.conf24 | Personalize your .conf experience with Learning Paths!

Personalize your .conf24 Experience Learning paths allow you to level up your skill sets and dive deeper ...

Threat Hunting Unlocked: How to Uplevel Your Threat Hunting With the PEAK Framework ...

WATCH NOWAs AI starts tackling low level alerts, it's more critical than ever to uplevel your threat hunting ...