rsyslog:如果日志文件中的事件包含关键字,如何将其拆分为单独的文件?

rsyslog:如果日志文件中的事件包含关键字,如何将其拆分为单独的文件?

我在 .log 文件中接收 syslog 数据。该文件包含两种类型的事件。一种事件仅包含 syslog 日期时间戳,另一种事件包含 syslog 日期时间戳和消息中的“timestamp=”字段。如何使用规则将任何包含“timestamp=”的事件拆分到单独的文件中?

答案1

rsyslog 过滤器文档说这$msg可以提供帮助:

Probably, “msg” is the most prominent use case of property based
filters. It is the actual message text. If you would like to filter
based on some message content (e.g. the presence of a specific code),
this can be done easily by:

    :msg, contains, "ID-4711"

This filter will match when the message contains the string “ID-4711”. 

*.* /var/log/file1 # the traditional way
if $msg contains 'error' then /var/log/errlog # the expression-based way

如果我正确理解了你的问题,你可以通过编辑配置文件来 $msg检查时间戳= 如果找到该值,请写入单独的文件。

这是 rsyslog 版本 8 的文档。我建议您根据找到的任何示例(在文档中或互联网上)检查您正在使用的 rsyslog 版本。

相关内容