在logstash中屏蔽信用卡号的中间6位数字 [英] Mask middle 6 digits of credit card number in logstash

查看:186
本文介绍了在logstash中屏蔽信用卡号的中间6位数字的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

要求以logstash显示开头的6位数字和结尾的4位数字,并掩盖信用卡的剩余数字.我应用了gsub/mutate过滤器,但替换字符串不允许使用正则表达式.还有其他方法可以在logstash中完成吗?

The requirement is to show the start 6 digits and last 4 digits and mask the remaining numbers of credit card in logstash. I applied gsub/mutate filter but the replacement string doesn't allow regex. Any other way this can be done in logstash?

if [message] =~ '\d{16}' {
    mutate {
        gsub => ["message", "\d{6}\d{4}\d{4}", "\d{6}######\d{4}"]
        add_tag => "Masked CardNo"
    }
}

此代码将信用卡3456902345871092屏蔽为\ d {6} ###### \ d {4},但应将其屏蔽为345690 ###### 1092.

This code masks the credit card 3456902345871092 to \d{6}######\d{4} but it should be masked as 345690######1092.

或者,如果可能的话,即使仅显示卡的前6位或后4位也是有帮助的.

As an alternative, if possible even displaying only the first 6 digits or the last 4 digits of the card would be helpful.

推荐答案

您可以在正则表达式中使用捕获组,并在替换部分中使用这些组:此正则表达式(\d{6})(\d{6})(\d{4})在匹配时会创建三个组(请参见此处).该组可以在替换字符串中使用:\1######\3此字符串将使用第一个和第三个替换组.

You can use capturing groups in the regex and use those group in the replacement part: this regex (\d{6})(\d{6})(\d{4}), when matched, creates three groups (see here). This groups can be used in the replacement string: \1######\3 this string will use the first and third replacement groups.

因此,在您的情况下,您的配置应如下所示:

So in your case, your configuration should look like this:

mutate {
    gsub => ["message", "(\d{6})(\d{6})(\d{4})", "\1######\3"]
    add_tag => "Masked CardNo"
}

此外,您的正则表达式\d{6}\d{4}\d{4}不能匹配16号信用卡号,第二个\d需要抓取6个字符.

Also, your regex \d{6}\d{4}\d{4} is wrong to match a 16-number credit card number, the second \d needs to grab 6 characters.

这篇关于在logstash中屏蔽信用卡号的中间6位数字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆