We have a failsafe to mask credit card numbers just in case they appear in a log (they shouldn't but...). We have a Grok pattern for credit card numbers and want to replace any occurrences of that with 16 X's.
# Check for credit card numbers and then replace them with XXXX...
grok {
patterns_dir => "/etc/logstash/conf.d/patterns"
match => { "message" => "%{GREEDYDATA:ccPart1}%{CREDITCARDNUMBER:ccNumber}%{GREEDYDATA:ccPart2}" }
add_tag => [ "ccDetected" ]
tag_on_failure => []
}
if "ccDetected" in [tags] {
if ![ccPart1] { mutate { add_field => { "ccPart1" => "" } } }
mutate {
replace => [ "message", "%{ccPart1}XXXXXXXXXXXXXXXX%{ccPart2}" ]
remove_field => [ "ccPart1", "ccPart2", "ccNumber" ]
}
}
It seems like there should be a more efficient way of doing this (besides creating a custom plugin). We're still on Logstash 1.4.2.