Splunk Search

How do you exclude an item from a lookup table and an additional condition?

yemyslf
Path Finder

I have a lookup table that I'm using to exclude some devices from search results.

index = my_index  
    | lookup my_table local=true device_id OUTPUT device_id as ignore  
    | where isnull(ignore)

This works great, but I need to add an additional condition to only exclude devices if they are in the lookup table and the value of the field "code" = 0001. So an event shouldn't be excluded even if it is in the lookup table unless code=0001 and events with code=0001 should be included if they are not in the lookup table.

I've tried the following but this also removes all items where

 code=0001
index = my_index  
    | lookup my_table local=true device_id OUTPUT device_id as ignore  
    | where (isnull(ignore) AND code!=0001)

I assume this is a dumb mistake in my logic but can't figure out what I'm doing wrong?

0 Karma

integratorz
Path Finder

If you are looking to filter out events where ignore is null you can actually do this as well: ignore="*"

This essentially means ignore needs to have a value.

Also, to do the second filter I would do it this way:

index=my_index 
| lookup my_table local=true device_id OUTPUT device_id as ignore 
| search ignore="*" code!=0001

In the last line, anything after the search command implies AND

0 Karma

yemyslf
Path Finder

Thanks for the response. I'm actually trying to exclude events where the device_id is in my lookup table. So doing | search ignore="*" retrieves events that I want to exclude. Because "ignore" isn't a field on the other events, I can't do ignore !="*". I was using isnull(ignore) because that returns events where there is no ignore field.

0 Karma
Get Updates on the Splunk Community!

Built-in Service Level Objectives Management to Bridge the Gap Between Service & ...

Wednesday, May 29, 2024  |  11AM PST / 2PM ESTRegister now and join us to learn more about how you can ...

Get Your Exclusive Splunk Certified Cybersecurity Defense Engineer at Splunk .conf24 ...

We’re excited to announce a new Splunk certification exam being released at .conf24! If you’re headed to Vegas ...

Share Your Ideas & Meet the Lantern team at .Conf! Plus All of This Month’s New ...

Splunk Lantern is Splunk’s customer success center that provides advice from Splunk experts on valuable data ...