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!

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, ...