Getting Data In

How to configure props.conf to remove any line NOT containing a certain string?

essklau
Path Finder

Hi.

All I want is the props.conf equivalent of this delete action from sed:

'/pattern/!d' 

That is it... just delete ANY line NOT containing "pattern".

Any takers?

Tags (1)
1 Solution

aweitzman
Motivator

You can't use ^ as negation here. It's not a character class.

It might be easier to write two transforms, one that discards everything and one that keeps the ones you want:

props.conf
[your sourcetype]
TRANSFORMS-separate = discardall, keepsome

Order is important here. discardall comes first because all are applied in order, last one wins.

transforms.conf
[discardall]
REGEX=.*
DEST_KEY=queue
FORMAT=nullQueue

[keepsome]
REGEX=StringPattern
DEST_KEY=queue
FORMAT=indexQueue

View solution in original post

aweitzman
Motivator

You can't use ^ as negation here. It's not a character class.

It might be easier to write two transforms, one that discards everything and one that keeps the ones you want:

props.conf
[your sourcetype]
TRANSFORMS-separate = discardall, keepsome

Order is important here. discardall comes first because all are applied in order, last one wins.

transforms.conf
[discardall]
REGEX=.*
DEST_KEY=queue
FORMAT=nullQueue

[keepsome]
REGEX=StringPattern
DEST_KEY=queue
FORMAT=indexQueue

aweitzman
Motivator

Based on your comment, I promoted my comment so you could mark it as your answer.

0 Karma

essklau
Path Finder

settled to:

[setnull]
REGEX = .
DEST_KEY = queue
FORMAT = nullQueue

[setparsing]
REGEX = pattern
DEST_KEY = queue
FORMAT = indexQueue

pretty much weitzman's answer. Thanks!

strive
Influencer

transforms.conf

[strip_pattern_lines]
REGEX = StringPattern
DEST_KEY = queue
FORMAT = nullQueue

props.conf

[your sourcetype]
TRANSFORMS-tonullqueue = strip_pattern_lines

Dont forget to restart the splunk after making above changes.

Update:

transforms.conf

[strip_pattern_lines]
REGEX = ^(?:[^ ]* ){4}(?!(PATTERN))
DEST_KEY = queue
FORMAT = nullQueue

props.conf

[your_sourcetype]
TRANSFORMS-tonullqueue = strip_pattern_lines

strive
Influencer

I have edited my answer. Test regex once. I am not good at regex.

0 Karma

essklau
Path Finder

Sure:

2014-08-27 veryseriousinfo {zippity:boop.bop} hola23: PATTERN: Welcome to the jungle
2014-08-27 abunchofsilliness {bangarang:yes:arang} flip11: The news in Uganda is grim
2014-08-27 happygoluckyfool {drinkyourovaltine} lamp34: thisdoesnotmatter

I only want to index the lines containing "PATTERN"

0 Karma

strive
Influencer

Agree. Thats why i have asked for sample log lines, so that we can suggest right configurations

0 Karma

aweitzman
Motivator

(Just an FYI - This probably won't work on multiline events either, as @bmacias84 points out.)

0 Karma

strive
Influencer

Can you post your sample log lines which you want to send to null Queue

0 Karma

essklau
Path Finder

I tried

[strip_pattern_lines]
REGEX = ^StringPattern
DEST_KEY = queue
FORMAT = nullQueue

with no success yet.

0 Karma

bmacias84
Champion

I don't believe that this works on multiline events.

0 Karma

strive
Influencer

When you say delete, you do not want to index such lines. Is that right?

For this you need transforms.conf and props.conf

0 Karma
Career Survey
First 500 qualified respondents will receive a $20 gift card! Tell us about your professional Splunk journey.

Can’t make it to .conf25? Join us online!

Get Updates on the Splunk Community!

What Is Splunk? Here’s What You Can Do with Splunk

Hey Splunk Community, we know you know Splunk. You likely leverage its unparalleled ability to ingest, index, ...

Level Up Your .conf25: Splunk Arcade Comes to Boston

With .conf25 right around the corner in Boston, there’s a lot to look forward to — inspiring keynotes, ...

Manual Instrumentation with Splunk Observability Cloud: How to Instrument Frontend ...

Although it might seem daunting, as we’ve seen in this series, manual instrumentation can be straightforward ...