Splunk Search

How to compare output of a search to a lookup file?

mkamal18
New Member

Hello,

I have a lookup filled with hostnames. I want to compare the hostnames with the host field in the index.

If the hostname has data in the index then the status will be OK if not KO.

Could you please help me ?

Tags (2)
0 Karma
1 Solution

gcusello
SplunkTrust
SplunkTrust

Hi mkamal18,
if in your lookup there's another field with values for each host (e.g. "description") try something like this

| metasearch index=my_index
| dedup host
| lookup mylookup.csv host OUTPUT description
| eval Status=if(description=*,""OK","KO")
| table host Status

if in your lookup there isn't any additional field, try something like this:

| metasearch index=my_index [ | inputlookup mylookup.csv | dedup host | fields host ]
| dedup host
| eval Status="OK"
| append [ 
   | metasearch index=my_index NOT [ | inputlookup mylookup.csv | dedup host | fields host ]
   | dedup host
   | eval Status="KO"
   ]
| table host Status

In both cases, beware to the case of the host.
Bye.
Giuseppe

View solution in original post

0 Karma

gcusello
SplunkTrust
SplunkTrust

Hi mkamal18,
if in your lookup there's another field with values for each host (e.g. "description") try something like this

| metasearch index=my_index
| dedup host
| lookup mylookup.csv host OUTPUT description
| eval Status=if(description=*,""OK","KO")
| table host Status

if in your lookup there isn't any additional field, try something like this:

| metasearch index=my_index [ | inputlookup mylookup.csv | dedup host | fields host ]
| dedup host
| eval Status="OK"
| append [ 
   | metasearch index=my_index NOT [ | inputlookup mylookup.csv | dedup host | fields host ]
   | dedup host
   | eval Status="KO"
   ]
| table host Status

In both cases, beware to the case of the host.
Bye.
Giuseppe

0 Karma

cboillot
Contributor

I know this was awhile ago, but how would one go about doing this to state if the host is just in the search results, only in the lookup, or in both?

0 Karma

mkamal18
New Member

Hello,

Thank you Giuseppe, It was really helpful. 🙂

0 Karma
Get Updates on the Splunk Community!

Splunk Observability for AI

Don’t miss out on an exciting Tech Talk on Splunk Observability for AI!Discover how Splunk’s agentic AI ...

Splunk Enterprise Security 8.x: The Essential Upgrade for Threat Detection, ...

Watch On Demand the Tech Talk on November 6 at 11AM PT, and empower your SOC to reach new heights! Duration: ...

Splunk Observability as Code: From Zero to Dashboard

For the details on what Self-Service Observability and Observability as Code is, we have some awesome content ...