【问题标题】:How to filter Remote Syslog messages on Red Hat?如何过滤 Red Hat 上的远程系统日志消息?
【发布时间】:2015-06-16 18:41:07
【问题描述】:

我在运行 Red Hat 6 的服务器上使用统一日志,接收来自其他服务器的定向日志消息并使用 RSyslog 管理它们。到现在为止,/etc/rsyslog.conf都有这条规则:

if $fromhost-ip startswith '172.20.' then /var/log/mylog.log

但我不想记录包含“kernel”和“dnat”的消息,所以我想过滤所有消息,增强规则。

我该怎么做?

【问题讨论】:

    标签: linux filter redhat rsyslog


    【解决方案1】:

    这似乎是一个更适合Unix & Linux 的问题。在适当地通知这不是正确的地方之后,无论如何我都会去打破规则回答它。

    根据您使用的 Red Hat 版本,您可以使用 rsyslogd 的 conditional filtersRainerScript 以各种方式表达多个逻辑规则的组合。在 Red Hat 6 上,您可以这样说来使用条件过滤器完成您想要的:

    if ( $fromhost-ip startswith '172.20.' and \
         $syslog-facility-text != 'kern' ) then /var/log/mylog.log
    

    您可以从Rsyslog v5 manual 中找到更多示例。

    【讨论】:

    • 我成功了!就是这样:if ( $fromhost-ip startswith '172.20.' and not $msg contains 'kernel' ) then /var/log/mylog.log
    猜你喜欢
    • 2018-12-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-02-18
    • 2012-11-03
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多