简体   繁体   English

用Fluentd处理嵌套的JSON

[英]Process nested JSON with Fluentd

Using Fluentd log pipeline, with input of: 使用Fluentd日志管道,输入以下内容:

{"event" : {"name" : "toto", "date" : 14....11}}

How can I transform the field event.date to a valid Date? 如何将字段event.date转换为有效的Date?

I tried: 我试过了:

<filter *.*> @type record_transformer <record> event.date ${Time.at(event.date).strftime('%Y-%m-%dT%H:%M:%S')} </record> </filter>

But this adds a field "event.date" :/ 但这会添加一个字段“ event.date”:/

It`s been a while, but I come here with a slight idea of how to do this. 已经有一段时间了,但是我来到这里只是对如何做到这一点有了一点想法。 It seems that in newer versions, some JSON processing has become part of the core of fluentd, and according to the docs: 根据文档,似乎在较新版本中,某些JSON处理已成为fluentd核心的一部分。

https://docs.fluentd.org/v1.0/articles/filter_parser https://docs.fluentd.org/v1.0/articles/filter_parser

this here: 这里:

<filter foo.bar>
  @type parser
  key_name log
  reserve_data true
  remove_key_name_field true
  <parse>
    @type json
  </parse>
</filter>

should do the trick. 应该可以。

we have: 我们有:

  • key_name - the name of the field in which to look key_name-要查找的字段的名称
  • reserve_data - wether or not to keep the fields from the outer JSON reserve_data-是否保留外部JSON中的字段
  • remove_key_name_field - wether or not to remove the field containing the nested JSON. remove_key_name_field-是否删除包含嵌套JSON的字段。

You must enable rubby : 您必须启用rubby:

<filter **>
  @type record_transformer
  enable_ruby
  <record>
    event_date ${time.strftime('%Y-%m-%dT%H:%M:%S')}

  </record>

</filter>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM