Splunk Search

How to achieve using Eval equals to a field from lookup?

solaced
Explorer

Need some help. I can't wrap my head around this.

Need to lookup a csv which contains clientip, and compare against my results with IP also in field clientip to show in a new column as matching or not matching 

| index=foo  ....

[|inputlookup IPlist.csv | fields clientip | rename clientip AS knownIP]
| eval isMatching = if(clientip == knownIP, "matching", "notmatch")
| table clientip, field x, field y, field z, isMatching

Am I way off base here? Should I be looking at other commands? I get zero results with this. Without it, my main search runs fine and many events with IPs show.

Much appreciated

Labels (2)
0 Karma
1 Solution

ITWhisperer
SplunkTrust
SplunkTrust

I am not entirely sure what you are trying to do here

Assuming index foo has a field called clientip and the csv file also has a field called clientip, you can filter your search so that only events from foo with matching ips are kept

index=foo  ... [|inputlookup IPlist.csv | fields clientip]
| table clientip, field x, field y, field z

If you want to keep all events from foo but mark those event with matching client ip, you need to have a field from your csv which is not present in foo, or create one - try something like this

index=foo  ...
| lookup IPlist.csv OUTPUT clientip AS knownIP
| eval isMatching = if(isnotnul(knownIP), "matching", "notmatch")
| table clientip, field x, field y, field z, isMatching

 

View solution in original post

solaced
Explorer

Thank you for your help.  Makes sense and should've been easy enough looking now at the answer. But spent hours myself. Much appreciated!

0 Karma

ITWhisperer
SplunkTrust
SplunkTrust

I am not entirely sure what you are trying to do here

Assuming index foo has a field called clientip and the csv file also has a field called clientip, you can filter your search so that only events from foo with matching ips are kept

index=foo  ... [|inputlookup IPlist.csv | fields clientip]
| table clientip, field x, field y, field z

If you want to keep all events from foo but mark those event with matching client ip, you need to have a field from your csv which is not present in foo, or create one - try something like this

index=foo  ...
| lookup IPlist.csv OUTPUT clientip AS knownIP
| eval isMatching = if(isnotnul(knownIP), "matching", "notmatch")
| table clientip, field x, field y, field z, isMatching

 

Career Survey
First 500 qualified respondents will receive a $20 gift card! Tell us about your professional Splunk journey.

Can’t make it to .conf25? Join us online!

Get Updates on the Splunk Community!

Take Action Automatically on Splunk Alerts with Red Hat Ansible Automation Platform

 Are you ready to revolutionize your IT operations? As digital transformation accelerates, the demand for ...

Calling All Security Pros: Ready to Race Through Boston?

Hey Splunkers, .conf25 is heading to Boston and we’re kicking things off with something bold, competitive, and ...

Beyond Detection: How Splunk and Cisco Integrated Security Platforms Transform ...

Financial services organizations face an impossible equation: maintain 99.9% uptime for mission-critical ...