Splunk Search

Unable to mask data using Regex

bdalsania_splun
Splunk Employee
Splunk Employee

I'm testing the data-mask feature by anonymizing the numbers in the brackets: splunk[9085] but it's not working
Is my regex expression incorrect? (generated using an online tool - https://regex101.com/)
Guide: https://docs.splunk.com/Documentation/Splunk/6.1.4/Data/Anonymizedatausingconfigurationfiles

Sample Log:
Aug 12 09:22:00 forwarder splunk[9085]: #011Checking default conf files for edits...

Forwarder configurations:

props.conf:
[linux_logs]
TRANSFORMS-anonymize = dhclient-anonymizer

transforms.conf:
[dhclient-anonymizer]
REGEX = splunk\[(\d+)\]
FORMAT = $1splunk[####]$2
DEST_KEY = _raw

Tags (2)
0 Karma
1 Solution

dpeukert
Explorer

First of all you are using $1 and $2 in FORMAT. Every $n represents exactly one capture group in your REGEX. So in your FORMAT you use one capture group more than in your REGEX. That can't work obviously. You don't want to capture what you want to change. You want to capture what you want to keep. So what you probably want to do is using something like this.

REGEX = (.*splunk\[)\d+(\].*)
FORMAT = $1####$2

I tested it and it worked.

View solution in original post

0 Karma

dpeukert
Explorer

First of all you are using $1 and $2 in FORMAT. Every $n represents exactly one capture group in your REGEX. So in your FORMAT you use one capture group more than in your REGEX. That can't work obviously. You don't want to capture what you want to change. You want to capture what you want to keep. So what you probably want to do is using something like this.

REGEX = (.*splunk\[)\d+(\].*)
FORMAT = $1####$2

I tested it and it worked.

0 Karma
Get Updates on the Splunk Community!

.conf24 | Personalize your .conf experience with Learning Paths!

Personalize your .conf24 Experience Learning paths allow you to level up your skill sets and dive deeper ...

Threat Hunting Unlocked: How to Uplevel Your Threat Hunting With the PEAK Framework ...

WATCH NOWAs AI starts tackling low level alerts, it's more critical than ever to uplevel your threat hunting ...

Splunk APM: New Product Features + Community Office Hours Recap!

Howdy Splunk Community! Over the past few months, we’ve had a lot going on in the world of Splunk Application ...