Splunk Search

lookup a csv if a field has certain value

mpasha
Path Finder

Good day,

I have a lookup file "Mainlookup.csv" that contains an IP address, Mac address and Host name of Clients machines that receive their IP address through DHCP. However, we have servers that are assigned static IP addresses and reside in a different subnet. I have collected IP address, host name and Mac addresses of these servers through Nmap and saved them in another CSV "Serverlookup.csv".

I have configured the Mainlookup as such so if it can not find a value for a field, it will return "No Match Found".

I was wondering if there is a way to use a condition that, if the field value is "No match found" from the first lookup, then the "serverlookup" is used to find the relevant info?

Thanks

0 Karma
1 Solution

mpasha
Path Finder

found my answer. a similar question was asked before and "elliotproebstel" answered it perfectly.
here is the answer:
base search:

index=security AND EventID=4768 
| lookup Ops_DHCP_IP2MAC Client_IP as Client_IP 

then when the results shows up and if there are Client_Name field with "NO Match Found!!" as their value we can use the following section to replace them with values coming from the second lookup

|eval Client_NMF=if (Client_Name=="No Match Found!!",Client_IP,NULL)
| lookup Ops_Servers Client_IP as Client_NMF output Client_Name,MAC_Address

View solution in original post

0 Karma

mpasha
Path Finder

found my answer. a similar question was asked before and "elliotproebstel" answered it perfectly.
here is the answer:
base search:

index=security AND EventID=4768 
| lookup Ops_DHCP_IP2MAC Client_IP as Client_IP 

then when the results shows up and if there are Client_Name field with "NO Match Found!!" as their value we can use the following section to replace them with values coming from the second lookup

|eval Client_NMF=if (Client_Name=="No Match Found!!",Client_IP,NULL)
| lookup Ops_Servers Client_IP as Client_NMF output Client_Name,MAC_Address
0 Karma

chrisyounger
SplunkTrust
SplunkTrust

Hi @mpasha

Yes you can do this. The best way is to make it so your first lookup does not actually set the "no match found" when it doesn't have a match. Just leave the default behaviour which will leave the output field as a null value. This way you can just have a second lookup table that will fill out the output field if it doesn't already have it. You can set the second lookup to set "no match found" if you want.

To get the lookups to run sequentially in the correct order, make sure the "name" of the automatic lookup definitions is in correct lexicographical (alphabetical) order.

All the best.

0 Karma
Get Updates on the Splunk Community!

Splunk MCP & Agentic AI: Machine Data Without Limits

  Discover how the Splunk Model Context Protocol (MCP) Server can revolutionize the way your organization ...

Finding Based Detections General Availability

Overview  We’ve come a long way, folks, but here in Enterprise Security 8.4 I’m happy to announce Finding ...

Get Your Hands Dirty (and Your Shoes Comfy): The Splunk Experience

Hands-On Learning and Technical Seminars  Sometimes, you just need to see the code. For those looking for a ...