You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何通过Fluentd现有插件替换日志中的ID、密码参数值?

Masking Sensitive URL Parameters in Fluentd with filter_record_transformer

Absolutely, you can use Fluentd's filter_record_transformer plugin to mask those sensitive URL parameters—no custom plugin required! The gsub functionality works perfectly here, and it’s exactly the right tool for this job. Let me break down how to set it up.

First, forget about the grep plugin—it’s meant for filtering records (keeping or discarding them based on patterns), not modifying content. The filter_record_transformer is what you need here.

Here’s a sample configuration that handles both the id and pw/pass parameters:

<filter your_input_tag>
  @type record_transformer
  enable_ruby true  # Required to use Ruby string methods like gsub
  
  <record>
    # Chain two gsub operations to mask both id and pw/pass parameters
    url ${record['url'].gsub(/id=[^&]+/, 'id=*').gsub(/(pw|pass)=[^&]+/, '\1=****')}
  </record>
</filter>

Let’s explain what each part does:

  • enable_ruby true: This allows us to use Ruby’s built-in string manipulation methods directly in the transformation.
  • First gsub call: The regex /id=[^&]+/ matches "id=" followed by any characters that aren’t an ampersand (so it stops at the next parameter or the end of the URL). We replace this with id=*.
  • Second gsub call: The regex /(pw|pass)=[^&]+/ uses a capture group to match either "pw=" or "pass=". The \1 in the replacement string preserves the original parameter name, while we replace the value with ****.

If your URL field isn’t at the top level of the record (e.g., it’s nested under request), just adjust the path:

url ${record['request']['url'].gsub(/id=[^&]+/, 'id=*').gsub(/(pw|pass)=[^&]+/, '\1=****')}

To answer your direct question: Yes, you can use filter_record_transformer’s gsub functionality—this is a textbook use case for it. The key is enabling Ruby evaluation so you can leverage the gsub method to modify the URL string.

内容的提问来源于stack exchange,提问作者monouser

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.26 08:42:01