繁体   English   中英

如何解析流利位 json $log。<field> 钥匙?</field>

[英]How to parse a fluent-bit json $log.<field> key?

我有以下日志要解析:

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

我在 output 中得到以下信息:

[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 object 而不是字符串。

我尝试使用解码器创建一些解析器,但我找不到在 json object 中转换event的方法。

我该怎么做?

我想出了如何解析。

我创建了一个新的解析:

[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

暂无
暂无

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

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