首页 > 解决方案 > 如何在fluentd中用特定字符串替换键值字符串

问题描述

我是 fluentd 的新手,当键值中出现特定字符串时,我想使用 record_modifier 替换字符串。

例子

1)输入:

{"message":"how are you"}

输出 :

{"message":"who are you"}

当输入具有“how”的键值时,我想用“who”替换该字符串

2)输入:

{"message":"he is a bad boy"}

输出 :

{"message":"he is a good boy"}

当输入键值具有“坏”时,我想用“好”替换该字符串

@type record_modifier #auto_typecast true enter code here 关键信息表达式 ????? 代替 ?????

提前致谢。

标签: replacefluentd

解决方案


您可以在record_transformer中使用gsub

<filter yourTag>
  @type record_transformer
  enable_ruby
  <record>
    log ${record["log"].gsub('how', 'who')}   
  </record>
</filter>

推荐阅读