Alerting

how to build a search excluding the result of another line

yohan_ch
New Member

let say here is my log:
id 123456789 appear here
id 123456789 something bad want to exclude
id 111111111 appear here

how to build a search so that it will only pickup id with "appear here" but not "something bad want to exclude"? in this case the desired result is the 111111111

Tags (1)
0 Karma

whrg
Motivator

I presume you have the "id" field available for searching. If not, create a field extraction for it.

Use a subsearch to exclude specific events from a base search:

index=... NOT [search index=... "something bad want to exclude" | table id]
0 Karma

amiftah_splunk
Splunk Employee
Splunk Employee

Following your example, the result should look like:
123456789
111111111
Because both events have appear here.

If the "appear here" pattern doesn't change you can add it to your search, E.g.:
index=test "appear here" | rex "id\s+(?<id>[0-9]{9})" |table id

Otherwise, you can exclude what you don't want:
index=test NOT "something bad want to exclude" | rex "id\s+(?<id>[0-9]{9})" |table id

Hope it helps.

0 Karma
Get Updates on the Splunk Community!

Stay Connected: Your Guide to May Tech Talks, Office Hours, and Webinars!

Take a look below to explore our upcoming Community Office Hours, Tech Talks, and Webinars this month. This ...

They're back! Join the SplunkTrust and MVP at .conf24

With our highly anticipated annual conference, .conf, comes the fez-wearers you can trust! The SplunkTrust, as ...

Enterprise Security Content Update (ESCU) | New Releases

Last month, the Splunk Threat Research Team had two releases of new security content via the Enterprise ...