Splunk Search

How to combine two lookups?

POR160893
Builder

On Splunk, I have the following 2 searches:

1)

`ABC_logs(traffic)` user != "unknown" src_ip IN (*) dest_ip IN (*)
| stats values(src_ip) values(src_zone) values(dest_ip) values(dest_port) values(app) values(transport) values(session_end_reason) values(user) by host rule action | rename values(*) as *
| dedup src_ip, dest_ip
| rename src_ip as device_ip_address
| fields device_ip_address, dest_ip, user, host [search index=DEF sourcetype = asset_registry_2
| dedup device_ip_address | fields device_ip_address, host ]

AND

2)

| inputlookup laso_lab_networks.csv
| join type=inner LAB_ID
[| inputlookup laso_lab_firewalls.csv
| eval Firewall = split(Firewall, ",")
| mvexpand Firewall]
| dedup Firewall
| eval Firewall = mvindex(split(Firewall, "."), 0)
| fields LAB_ID, Lab_Mgr, Firewall

I need to write a single query that would LINK both these queries such that the field "Firewall" from search 1 is joined to the field "host" from search 2. 

I appreciate any help you can offer

Labels (5)
0 Karma

yuanliu
SplunkTrust
SplunkTrust

Both searches are very confusing, and seem overly complicated.  I took the liberty to simplify. (With the susbsearch in the main search, the first search should also be more efficient.) But really if a good use of the lookup laso_lab_firewalls.csv is to match host name, I wonder if it is much more efficient to actually produce the lookup with host as one of keys.  Lookup is a binary tree, whereas inputlookup forces you to use other, less efficient commands.

Anyway, the main idea is to stitch the two together, then do values operation on non-overlapping fields.

 

`ABC_logs(traffic)` user != "unknown" 
    [search index=DEF sourcetype = asset_registry_2
    | dedup device_ip_address | fields device_ip_address, host 
    | rename device_as src_ip]
| stats values(src_ip) values(src_zone) values(dest_ip) values(dest_port) values(app) values(transport) values(session_end_reason) values(user) by host rule action
| rename values(*) as *
| rename src_ip as device_ip_address
| fields device_ip_address, dest_ip, user, host
| append
    [| inputlookup laso_lab_firewalls.csv
    | eval Firewall = split(Firewall, ",")
    | mvexpand Firewall
    | dedup Firewall
    | eval host = mvindex(split(Firewall, "."), 0)
    | fields LAB_ID, Lab_Mgr, host]
| stats values(device_ip_address) as device_ip_address values(dest_ip) as dest_ip values(user) as user values(LAB_ID) as LAB_ID values(Lab_Mgr) as Lab_Mgr by host

 

 

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!

How much can you really learn in 3 minutes?

Observability can certainly be hard to understand – there's a lot of jargon and buzzwords and it seems to ...

Event Series: The Agentic SOC: Trust Before Autonomy

AI is fundamentally changing security operations, but true progress requires more than just automation—it ...

Free Professional Services for .conf26 Attendees

This year at .conf26, we are doing something a little different. We are bringing the best minds from ...