【问题标题】:How to parse a fluent-bit json $log.<field> key?如何解析流利的 json $log.<field> 键?
【发布时间】:2021-08-20 00:08:17
【问题描述】:

我有以下日志要解析:

TID: [-1234] [] [2021-05-31 09:53:26,680] - Unique ID: Evento_Teste, Event: {"event":{"metaData":"blue"}}

在我为处理它而创建的配置文件下方。

#td-agent-bit.conf
[SERVICE]
    log_level info
    parsers_file parsers.conf

[INPUT]
    Name tail
    Path /opt/wso2am/repository/logs/xtest-td.log
    Tag wso2.trace

[FILTER]
    name   parser
    match  wso2.*
    Key_Name log
    Parser wso2_trace

[OUTPUT]
    Name  stdout
    match *
    Format json_lines
# parsers.conf
[PARSER]
    Name   wso2_trace
    Format regex
    Regex  ^TID: \[(?<TID>[-\d]+)\] \[\] \[(?<time>[^\]]*)\].* Unique ID: (?<unique_id>[_\w\d]+), Event: (?<event>.*)$
    Time_Key time
    Time_Format %Y-%m-%d %H:%M:%S

我在输出中得到以下内容:

[2021/06/01 16:09:15] [ info] [input:tail:tail.0] inotify_fs_add(): inode=34902473 watch_fd=1 name=/opt/wso2am/repository/logs/xtest-td.log
{"date":1622454806.0,"TID":"-1234","unique_id":"Evento_Teste","event":"{\"event\":{\"metaData\":\"blue\"}}"}

这个日志将被发送到一个ES实例,我需要将event键的值转换成一个json对象而不是一个字符串。

我尝试使用解码器创建一些解析器,但找不到将 event 转换为 json 对象的方法。

我该怎么做?

【问题讨论】:

    标签: elasticsearch fluentd fluent-bit efk


    【解决方案1】:

    我想出了如何解析。

    我创建了一个新的解析:

    [PARSER]
        Name         json_field
        Format       json
        # Command       | Decoder      | Field    | Optional Action   |
        # ==============|==============|==========|===================|
        Decode_Field_As   escaped_utf8   log        do_next
        Decode_Field_As   json           log
    

    我将它包含在管道中:

    [SERVICE]
        log_level info
        parsers_file parsers.conf
    
    [INPUT]
        Name tail
        Path /opt/wso2am/repository/logs/xtest-td.log
        Tag wso2.trace
    
    [FILTER]
        name   parser
        match  wso2.*
        Key_Name log
        Parser wso2_trace
    
    [FILTER]
        name   parser
        match  wso2.*
        Key_Name event
        Parser json_field
        Reserve_Data True
    
    [OUTPUT]
        Name  stdout
        match *
        Format json_lines
    

    【讨论】:

      猜你喜欢
      • 2019-09-26
      • 1970-01-01
      • 1970-01-01
      • 2019-09-06
      • 2011-09-24
      • 2012-06-11
      • 2020-09-16
      • 1970-01-01
      • 2019-03-21
      相关资源
      最近更新 更多