Splunk Search

return a result from fields based on 2 queries

gregwilliams
Path Finder

I'm trying to return a field based upon a search and within that search extract a variable to search for in another search. For example, I would like to get the username of the person who is authenticated on a computer in which an alert was triggered. The IDS events come in, which display a destination IP address then I want to search for that IP address in the authentication logs, then return the username within the authentication log. Any ideas?

Tags (1)
0 Karma
1 Solution

tysonstewart
Path Finder

Seems like a subsearch case.

logger=Authentication [search IDS | fields IP]

Or something similar. You can use the format command to determine how you want the subsearch to concatenate its results for the main search.

Update, using a map command:

first search | map search="search \"User Authentication\" IP=$dest_IP$" | fields username

View solution in original post

tysonstewart
Path Finder

Seems like a subsearch case.

logger=Authentication [search IDS | fields IP]

Or something similar. You can use the format command to determine how you want the subsearch to concatenate its results for the main search.

Update, using a map command:

first search | map search="search \"User Authentication\" IP=$dest_IP$" | fields username

tysonstewart
Path Finder

Yeah, I noticed that the splunkbase comment stripped the backslashes off those inner quotation marks. I'll update the original answer. Glad you got it working. 🙂

Oh, if you schedule that search, you'll need to save the map's search off as its own saved search (see http://splunk-base.splunk.com/answers/27658/map-command-breaks-when-scheduled).

0 Karma

gregwilliams
Path Finder

Works with a little tweaking. I couldn't include the quotes into the mapped search, but I substituted that with the event ID of the authenticaiton string. Works great!

"first search string" | map search="search xxxxxx IP=$dest_ip$" | fields username

0 Karma

tysonstewart
Path Finder

Oh, nice. You might be able to use a transaction to do that, depending on how many other events you expect to have with that IP.

I'm going to guess you'll want to do this for more than one IP address, so it's probably better to go the map route:

| map search="\"User Authentication\" IP=$dest_IP$" | fields username

You can replace that "User Authentication" bit with whatever search will identify those types of events. The magic in map is the $variable$ part.

Let me know if this works and I'll update the answer.

0 Karma

gregwilliams
Path Finder

I get a "Encoutered an enexpected error while parsing intentions." error. Here are the 2 logs I want to correlate:

mm/dd-xx:xx:xx.xxxxx ET TROJAN From CnC [**] [Classification: A Network Trojan was detected] [Priority: 1] {TCP} xx.xx.xx.xx:xxxxx -> yy.yy.yy.yy:yyyy

yy.yy.yy.yy is recognized as the dest_ip as a field

and I want to correlate with this log:

User Authentication Successful: username=zzzzzzz IP=yy.yy.yy.yy

I want to correlate dest_ip and IP and return the username

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!

Index This | What travels the world but is also stuck in place?

April 2026 Edition  Hayyy Splunk Education Enthusiasts and the Eternally Curious!   We’re back with this ...

Discover New Use Cases: Unlock Greater Value from Your Existing Splunk Data

Realizing the full potential of your Splunk investment requires more than just understanding current usage; it ...

Continue Your Journey: Join Session 2 of the Data Management and Federation Bootcamp ...

As data volumes continue to grow and environments become more distributed, managing and optimizing data ...