Splunk Search

How to search across multiple lines

Mystere
New Member

I have a logfile that is not very orthogonal. It will include, for example, IP Address of an action one line, and then have another action without an IP (but with the username of the logged in user) on the next.

I would like to figure out a way to get Splunk to show me all instances of a certain IP address which are directly followed by a specific bit of text on the next line.

For example, it might look like this:

1/1/0001 00:00:00:01 192.168.0.1 User Login (Bubba)
1/1/0001 00:00:01:01 Bubba Viewed Reports

Now, I want to get Splunk to show me every instance where Bubba logs in from IP Addres 192.168.0.1, and then views reports as the first action after logging in.

Actually, more accurately, I want to see all users who logged in from 192.168.0.1 and then viewed reports as the first action, whether it be bubba or not. This helps me to track down when a single user is logging in with multiple accounts. (Yes, I know it's not 100% reliable, but for my purposes it is. I'm also aware of various problems with concurrency, but this is a start).

Can anyone help me to formulate query for this?

Tags (1)
0 Karma

Simeon
Splunk Employee
Splunk Employee

As Nick has suggested, the transaction command is the solution here:

http://docs.splunk.com/Documentation/Splunk/5.0/SearchReference/Transaction

You may want to use options of startswith and endswith to complete your search. Without a more complete picture of your logs, it is a bit difficult to give you an exact search (besides the above) which would get you the information you need.

0 Karma

sideview
SplunkTrust
SplunkTrust

Well if you can set up a field extraction that matches the login events, and extracts a field called 'username'.
Then you create two extracted fields that match on the second kind of event, creating a 'username' field and an 'action' field.

Once you set that up then it can be done with the transaction command without a lot of trouble. I think this would do the trick:

192.168.0.1 | transaction username maxevents=2 | search action='Viewed Reports' | top username

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!

Announcing Modern Navigation: A New Era of Splunk User Experience

We are excited to introduce the Modern Navigation feature in the Splunk Platform, available to both cloud and ...

Modernize your Splunk Apps – Introducing Python 3.13 in Splunk

We are excited to announce that the upcoming releases of Splunk Enterprise 10.2.x and Splunk Cloud Platform ...

Step into “Hunt the Insider: An Splunk ES Premier Mystery” to catch a cybercriminal ...

After a whole week of being on call, you fell asleep on your keyboard, and you hit a sequence of buttons that ...