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