flume1.9.0 查找-替换拦截器

案例

数据如下:

lucy,220881198211300935,f,1.70

flume 将 18 位身份证号 替换为 xxxx,并将信息打印到控制台中

编写配置文件

登录 hadoop1,

cd /program/flume-1.9.0/conf
vim test_replace_filter.conf

内容如下:

# 定义agent名字为a1,相当于变量名,可任意起
# 设置 sources、sinks、channels的名字
a1.sources = r1
a1.sinks = k1
a1.channels = c1
# 配置source类型为taildir
a1.sources.r1.type = TAILDIR
a1.sources.r1.filegroups = f1


# 定义拦截器 replace_filter
a1.sources.r1.interceptors=replace_filter
# 定义拦截器filter
a1.sources.r1.interceptors.replace_filter.type=search_replace
# 定义要搜索的字段
a1.sources.r1.interceptors.replace_filter.searchPattern=([0-9]{17})([0-9]|X|x)
# 定义要替换的字段
a1.sources.r1.interceptors.replace_filter.replaceString= xxxx


# 监控该文件
a1.sources.r1.filegroups.f1 = /test_flume/test_replace.log
# 配置 sink 为打印到控制台中
a1.sinks.k1.type = logger
# 配置 channel 类型为内存
a1.channels.c1.type = memory
# 内存队列最大为1000,可以存储1000个event
a1.channels.c1.capacity = 1000
# 一个事务中从source接收的events数量或发送给sink的events数量最大为100
a1.channels.c1.transactionCapacity = 100
# 将source 和 sink 绑定到channel上
a1.sources.r1.channels = c1
a1.sinks.k1.channel = c1

启动

进入 flume 根目录:

cd /program/flume-1.9.0/

执行下面命令(必须在上面目录中才能执行):

bin/flume-ng agent -n a1 -c conf -f conf/test_replace_filter.conf -Dflume.root.logger=INFO,console

解释:
https://www.malaoshi.top/show_1IX258AKgb2F.html

测试

在 test_flume 目录下,执行下面命令

echo lucy,220881198211300935,f,1.70  >> test_replace.log

控制台显示如下:

Event: { headers:{} body: 6C 75 63 79 2C 78 78 78 78 2C 66 2C 31 2E 37 30 lucy,xxxx,f,1.70 }

将lucy身份证号替换为 xxxx

参考:
https://www.cnblogs.com/liuxinrong/articles/12597304.html
https://blog.csdn.net/weixin_45764675/article/details/106465142


原文出处:/show_1IX2KMN9JTaO.html