使用 FluentD 删除密钥

Remove a key with FluentD

我有一个JSON文件,是用工具生成的。我想在转发之前删除一个属性。

<source>
  @type tail
  path /var/log/app/file.json
  pos_file /var/log/td-agent/file.pos # pos record
  tag file_json
  format json
</source>

<match file_json>
  @type exec
  tag_key file_filtered
  buffer_path /tmp/file_buffer.buf
  command jq 'del(.timestamp)'
  format json
</match>

<match file_filtered>
  @type file
  path /var/log/app/file_fwd.json
  # time_slice_format %Y%m%d
  # time_slice_wait 10m
  # time_format %Y%m%dT%H%M%S%z
  # compress gzip
  # utc
</match>

我不知道所有 JSON 属性,但我知道我不能拥有 timestamp 字段。我使用 jq 来删除这个模仿函数的属性:

tail file.json | jq 'del(.timestamp)'

FluentD 可以帮我做这个吗?我在这里描述的方式不会生成过滤文件,但配置会被接受。

官方文档中的record_transformer过滤

http://docs.fluentd.org/articles/filter_record_transformer#removekeys-optional-string-type