Splunk Search

Extracting information from data points directly before/after specific data points

tanyongjin
Explorer

I have a whole list of logs that records information about a user's access to different services in the network. I want to know what services the user has accessed before and after an access towards a particular service.

Example: A user has accessed services
in this order -> A B C D E C A B

Here, I am just interested in the
services that this particular has
accessed just directly before and
after a particular defined service (Example: C).

So what I want to know here is that the
user has accessed service B 1 time
before and E 1 time before. D 1 time after and A 1 time after.

Since the user has accessed service C 2 times.

How can I extract such information from the logs using Splunk Search?

Thank you.

Tags (1)
0 Karma

DalJeanis
Legend

Here's what to do...

your search that extracts all relevant events with _time, user, event
| streamstats current=f last(event) as nextevent by user
| reverse
| streamstats current=f last(event) as priorevent by user
| table _time user event nextevent priorevent
| fillnull value="((none))" nextevent priorevent
| where event="C"

If you are wondering about choice of the names nextevent and priorevent, remember that splunk natively will pull events in reverse time order, so the first streamstats will be seeing the future and copying it to the past, while the streamstats after the reverse will be seeing the past and copying it to the future. If your search changes this native order, then you will need to change the names, but nothing else.

0 Karma

tanyongjin
Explorer

Bump

10 char

0 Karma
Got questions? Get answers!

Join the Splunk Community Slack to learn, troubleshoot, and make connections with fellow Splunk practitioners in real time!

Meet up IRL or virtually!

Join Splunk User Groups to connect and learn in-person by region or remotely by topic or industry.

Get Updates on the Splunk Community!

Why Splunk Customers Should Attend Cisco Live 2026 Las Vegas

Why Splunk Customers Should Attend Cisco Live 2026 Las Vegas     Cisco Live 2026 is almost here, and this ...

What Is the Name of the USB Key Inserted by Bob Smith? (BOTS Hint, Not the Answer)

Hello Splunkers,   So you searched, “what is the name of the usb key inserted by bob smith?”  Not gonna lie… ...

Automating Threat Operations and Threat Hunting with Recorded Future

    Automating Threat Operations and Threat Hunting with Recorded Future June 29, 2026 | Register   Is your ...