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 | Registration Open!

Hello, hello! I come bearing good news: Registration for .conf24 is now open!   conf is Splunk’s rad annual ...

ICYMI - Check out the latest releases of Splunk Edge Processor

Splunk is pleased to announce the latest enhancements to Splunk Edge Processor.  HEC Receiver authorization ...

Introducing the 2024 SplunkTrust!

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