Splunk Search

Matching events by pair

timbCFCA
Path Finder

I'm attempting to map when the count of two event IDs - 4634 and 4624 is different over a time period. These events correlate to logon (4624) and logoff (4634) events.

host=myhost* ( evtid=4634 OR evtid=4624 ) | counttable evtuser, evtid

This works perfectly if the start time does not site between when user logs on and logs off.

I would like to exclude any logoffs which occur prior to the first logon event. I have no idea of the syntax required to do so however.

I was also thinking of a slightly more sophisticated method. I have an additional field - LogonID which uniquely correlates these events in a 1:1 mapping. I'm thinking that it should be possible to exclude the last first logoff event if the first logon event does not have the same LogonID value. My guess is that is more work than is necessary however.

Tags (2)
0 Karma
1 Solution

Drainy
Champion

Well I have just quickly thrown together a transaction on my system to see if it would work. I think it does what you are after..

event_id=4634 OR event_id=4624 | transaction Account_Name ComputerName startswith="EventCode=4634" endswith="EventCode=4624"  keepevicted=true | search  closed_txn=0 | stats count

Obviously you could modify this to meet your exact needs but this will transaction events based on them starting with a logon and ending with a logoff. I choose to keep the events that don't fit in the transaction and then only display them, I can then count them. You could here count by event id or user name etc. If the logonID is in each event you could also transaction based on that.

View solution in original post

Drainy
Champion

Well I have just quickly thrown together a transaction on my system to see if it would work. I think it does what you are after..

event_id=4634 OR event_id=4624 | transaction Account_Name ComputerName startswith="EventCode=4634" endswith="EventCode=4624"  keepevicted=true | search  closed_txn=0 | stats count

Obviously you could modify this to meet your exact needs but this will transaction events based on them starting with a logon and ending with a logoff. I choose to keep the events that don't fit in the transaction and then only display them, I can then count them. You could here count by event id or user name etc. If the logonID is in each event you could also transaction based on that.

timbCFCA
Path Finder

On first glance that definitely looks like what I need. Many thanks.

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 ...