Splunk Search

How to get events around identified event

jamesvz84
Communicator

Hello,

I have a dashboard that identifies Windows hard shut downs (event code=41). However, we want to see the windows events leading up to the hard shut down.

For example, my results table says I had a hard shut down on host .111 at 1:30PM. How can I pipe this to more logic that will show me windows events from 1:20PM to 1:30PM (in order to provide clues about what led up to the hard shut down)? I prefer not to do this manually but to actually have a query dynamically retrieve those "lead up" events.

Tags (2)

somesoni2
Revered Legend

YOu can try something like this

index=YourIndex sourcetype=YourSourcetype [ search index=YourIndex sourcetype=YourSourcetype event_code=41 | eval earliest=relative_time(_time,"-10m@m") | eval latest=_time | return earliest, latest] | rest of search

dijikul
Communicator

I like your answer because it clarifies something I struggled with in the MArtin's -- the map command in the quotes section - "search for lead-up events earliest=$starttime latest=$endtime$" was unclear to me, whereas your example demonstrates a standard spl search structure referencing an index and a sourcetype.

0 Karma

martin_mueller
SplunkTrust
SplunkTrust

You can use localize and map like this:

search for event code 41 | localize timebefore=10m | map search="search for lead-up events earliest=$starttime$ latest=$endtime$"

localize takes events from the first search and converts them into timeranges, going back 10 minutes. map takes these timeranges and runs new searches based on the ranges.

See these for reference:
http://docs.splunk.com/Documentation/Splunk/6.1.3/SearchReference/localize
http://docs.splunk.com/Documentation/Splunk/6.1.3/SearchReference/map

Career Survey
First 500 qualified respondents will receive a $20 gift card! Tell us about your professional Splunk journey.

Can’t make it to .conf25? Join us online!

Get Updates on the Splunk Community!

Leveraging Automated Threat Analysis Across the Splunk Ecosystem

Are you leveraging automation to its fullest potential in your threat detection strategy?Our upcoming Security ...

Can’t Make It to Boston? Stream .conf25 and Learn with Haya Husain

Boston may be buzzing this September with Splunk University and .conf25, but you don’t have to pack a bag to ...

Splunk Lantern’s Guide to The Most Popular .conf25 Sessions

Splunk Lantern is a Splunk customer success center that provides advice from Splunk experts on valuable data ...