Splunk Search

How to exclude certain wildcard matches from the search

franjo
Explorer

I need to search for *exception in our logs (e.g. "NullPointerException") but want to exclude certain matches (e.g. "DefaultException"). If my search is

*exception NOT DefaultException

then it works fine, except for the cases where I have both "NullPointerException" and "DefaultException" values in the text.
How do I create a search that will ignore records with "DefaultException" only, but not ignore them if there are other "*exception" present?

Here is an example: I want to ignore line1, but get (in search results) lines 2 and 3. With my search above I'm only getting line3:

1. line1: some DefaultException happened
2. line2: some NullPointerException happened together with DefaultException
3. line3: another NullPointerException happened

Thanks!
Franjo.

Tags (3)
0 Karma
1 Solution

morethanyell
Builder

Say you have these raw logs (as you mentioned above)

| makeresults
| eval sample_raw = "some DefaultException happened,some NullPointerException happened together with DefaultException,another NullPointerException happened"
| makemv delim="," sample_raw
| mvexpand sample_raw

alt text

The important thing to consider here is to count the occurence of "Exception" in your raw log. In order to do that, we need to capture the exceptions as multivalue field like this (or by adding this line of rex)

| rex field=sample_raw max_match=0 "(?<exception_type>[\w]+)Exception"

As a result, it will create an MV field containing all the Exceptions like this:
alt text

From here, you can just easily filter out the ones you don't like using the | where command:

| where mvcount(exception_type) > 1 OR exception_type != "Default"

I think this is just one approach. There might be better ways to do it.

View solution in original post

morethanyell
Builder

Say you have these raw logs (as you mentioned above)

| makeresults
| eval sample_raw = "some DefaultException happened,some NullPointerException happened together with DefaultException,another NullPointerException happened"
| makemv delim="," sample_raw
| mvexpand sample_raw

alt text

The important thing to consider here is to count the occurence of "Exception" in your raw log. In order to do that, we need to capture the exceptions as multivalue field like this (or by adding this line of rex)

| rex field=sample_raw max_match=0 "(?<exception_type>[\w]+)Exception"

As a result, it will create an MV field containing all the Exceptions like this:
alt text

From here, you can just easily filter out the ones you don't like using the | where command:

| where mvcount(exception_type) > 1 OR exception_type != "Default"

I think this is just one approach. There might be better ways to do it.

franjo
Explorer

mvCount > 1 was not always good, but if I use this then I get what I want:

where mvcount(mvfilter(exception_type != "Default")) > 0

morethanyell
Builder

That is a lot better

0 Karma

adonio
Ultra Champion

your search .... NOT "DefaultException" ....

0 Karma

franjo
Explorer

how is this different from " *exception NOT DefaultException " that I already mentioned in the question?

0 Karma

adonio
Ultra Champion

looks like i misunderstood your question, can you elaborate on the requirement: "How do I create a search that will ignore records with "DefaultException" only, but not ignore them if there are other "*exception" present?"
can you provide some sample data?

0 Karma

franjo
Explorer

Sure, here are 3 examples. I want to ignore line1, but get (in search results) lines 2 and 3. With my initial query (and your proposal) I'm only getting line3:

  1. line1: some DefaultException happened
  2. line2: some NullPointerException happened together with DefaultException
  3. line3: another NullPointerException happened
0 Karma

adonio
Ultra Champion

can you provide a larger masked data set? also can you provide the final result you are interested in with the format? chart / table / etc ...

0 Karma

rupesh26
Path Finder

do you want to ignore events where both "NullPointerException" and "DefaultException" values present as well ?

0 Karma

franjo
Explorer

No, I want to always see (get in results) my "NullPointerException". I just don't want to see the entries where only "DefaultExceptions" is present (and no other one).

0 Karma

rupesh26
Path Finder

when you do a wildcard search you are searching the entire event, so it will ignore even this event

some NullPointerException happened together with DefaultException

The best way to do is use field extraction and extract NullPointerException to a field and add that field to your search

0 Karma
Get Updates on the Splunk Community!

Introducing the 2024 SplunkTrust!

Hello, Splunk Community! We are beyond thrilled to announce our newest group of SplunkTrust members!  The ...

Introducing the 2024 Splunk MVPs!

We are excited to announce the 2024 cohort of the Splunk MVP program. Splunk MVPs are passionate members of ...

Splunk Custom Visualizations App End of Life

The Splunk Custom Visualizations apps End of Life for SimpleXML will reach end of support on Dec 21, 2024, ...