Splunk Search

Regex help in Splunk

Shashank_87
Explorer

Hi, I have few events in splunk like these -
1. "GET /test/materials/components/fields HTTP/1.1"
2. "GET /test1 HTTP/1.1" OR "GET /test2 HTTP/1.1
Now what i want is just to see the events which are like in the 2nd point. My query should ignore the 1st one's. The 2nd type of URL has a pattern that it has only one word after "/".

Can some one help?

Tags (2)
0 Karma
1 Solution

ragedsparrow
Contributor

You can not exclude with a regex pattern in your base search. You have to put it through the regex transformation to exclude events in the search via regex pattern matching. Example:

base search | regex url="\w+\s\/\w+\s.*"

That would only match the 2nd example shown

If you don't need the events at all, you may want to consider routing them to the nullQueue: https://docs.splunk.com/Documentation/Splunk/7.2.5/Forwarding/Routeandfilterdatad

The 2nd option will allow you to send specific events that you do not want to the nullQueue and they are not indexed. If you want it all to be indexed and then filtered at search time, you will need to use the regex specific transformation commands to filter them out.

View solution in original post

0 Karma

ragedsparrow
Contributor

You can not exclude with a regex pattern in your base search. You have to put it through the regex transformation to exclude events in the search via regex pattern matching. Example:

base search | regex url="\w+\s\/\w+\s.*"

That would only match the 2nd example shown

If you don't need the events at all, you may want to consider routing them to the nullQueue: https://docs.splunk.com/Documentation/Splunk/7.2.5/Forwarding/Routeandfilterdatad

The 2nd option will allow you to send specific events that you do not want to the nullQueue and they are not indexed. If you want it all to be indexed and then filtered at search time, you will need to use the regex specific transformation commands to filter them out.

0 Karma

somesoni2
Revered Legend

This is the full raw data OR full value of field??

your base search | regex _raw=".+\"\w+\s+\/\S+\s+\w+\/\d+\.\d+\".+"

OR if the extracted field name is URL

your base search | regex URL="\w+\s+\/\S+\s+\w+\/\d+\.\d+"
0 Karma

Shashank_87
Explorer

Hi Somesoni2, The above 2 points which i mentioned are 2 different events in my index. What i want is to fetch only 2nd type of events and exclude the 1st one's.
What will be the query look like?

0 Karma

somesoni2
Revered Legend

My solution is considering type 2 events. Try the same.

0 Karma

ehowardl3
Path Finder

As far the regex goes, the following will only match the examples in point 2:

\w+\s\/\w+\s.*

-E

0 Karma

Shashank_87
Explorer

Hi ehoward, Thank you for the response. Is there a way to exclude this in the search itself? I mean within the search query can we exclude all the URL's apart from the one's who follow pattern as 2nd point. This way we reduce the overhead and number of events

0 Karma
Get Updates on the Splunk Community!

Announcing Scheduled Export GA for Dashboard Studio

We're excited to announce the general availability of Scheduled Export for Dashboard Studio. Starting in ...

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 GA in US-AWS!

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