gpt4 book ai didi

regex - Fluentd 过滤器以排除具有空值的键

转载 作者:行者123 更新时间:2023-12-04 00:05:47 25 4
gpt4 key购买 nike

我想排除 serive_name 为空的行 "service_name":"" .
这是我流利的 ​​conf

## match tag=debug.** and dump to console
<match debug.**>
@type stdout
</match>
<source>
@type tail
path /opt/wso2esb-4.9.0-wkr-1/repository/logs/wso2carbon.log
pos_file /var/log/td-agent/tmp/wso2carbon.log.pos
tag debug.wso2.esb
format /^([TID:]* [^ ]* [^ ]* \[(?<time>[^\]]*)\]) ([^ ]* (?<level>[^ ]*))([^***]*[^=]*[^ ]*(?<service_name>[^,]*)[^=]*[^ ]*(?<step>[^,]*)[^ ]*[^=]*[^ ]*(?<message_id>[^,]*))/
time_format %Y-%m-%d %H:%M:%S
# keep_time_key true
</source>

这是日志输出
2017-08-21 09:57:10 +0700 debug.wso2.esb: {"level":"INFO","service_name":" SA_VasGWLogSeq","step":" before vasgwInsertlog","message_id":" urn:uuid:2046f0ed-690d-47b1-aa86-d4a71c021a74"}
2017-08-21 09:57:10 +0700 debug.wso2.esb: {"level":"INFO","service_name":"","step":"","message_id":""}
2017-08-21 09:57:10 +0700 debug.wso2.esb: {"level":"INFO","service_name":" SA_VasGWLogSeq","step":" after vasgwInsertlog","message_id":" urn:uuid:2046f0ed-690d-47b1-aa86-d4a71c021a74"}
2017-08-21 10:16:10 +0700 debug.wso2.esb: {"level":"INFO","service_name":" SERVICE_NAME","step":" Before - SA_ServiceApiDSEp","message_id":" urn:uuid:39e0ecc1-dda5-4cd9-91fc-90e7ed4f5233"}

我想排除下面的行。怎么做?
{"level":"INFO","service_name":"","step":"","message_id":""}

第二个问题是为什么我在值 "service_name":" SERVICE_NAME" 之前有一个空格, 当我试穿时 Fluentular I get a nice output without space .

我已经通过向正则表达式添加一个空格解决了第二个任务。例如改变
[^=]*[^ ]*(?<service_name>[^,]*)[^=]*[^ ]* (?<service_name>[^,]*) .

但我不知道 如何编写过滤器以通过 key_name 排除具有空值的记录,例如 "service_name":"" .

最佳答案

这似乎是 grep 的一个相当微不足道的用法。过滤器插件的 exclude 指示。

匹配一条空消息并使用“开始”( ^ )排除它,然后是空消息和结束( $ )可以通过以下方式完成。

<filter **>
@type grep
<exclude>
key service_name
pattern /^$/
# or, to exclude all messages that are empty or include only white-space:
# pattern /^\s*$/
</exclude>
</filter>

请注意,0.12 和 1.x 之间的正则表达式符号发生了变化(现在使用前导和尾随斜杠)。

关于regex - Fluentd 过滤器以排除具有空值的键,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45788881/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com