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!

Extending Observability Content to Splunk Cloud

Watch Now!   In this Extending Observability Content to Splunk Cloud Tech Talk, you'll see how to leverage ...

More Control Over Your Monitoring Costs with Archived Metrics!

What if there was a way you could keep all the metrics data you need while saving on storage costs?This is now ...

New in Observability Cloud - Explicit Bucket Histograms

Splunk introduces native support for histograms as a metric data type within Observability Cloud with Explicit ...