zoukankan      html  css  js  c++  java
  • 解决rsyslog日志分发过滤问题

    问题描述:

    服务器B从远端接收来自服务器A的消息网关日志,按照配置要求,需要将这些日志按照消息标签分类写入不同的文件中。

    例如有这样一条日志:

    Sep 12 08:00:03 192.100.6.3 Monster-CMPP20MO[37518]: 20180912080002SMS0000999L00100000000cc515275,0,00,,,09120800018510260295,,,,xxxxxxxxxxx,,,1,xxxxxxxxxx,,,,,,,,,,,,0,6,DM302J,

    我们希望可以按照“Monster-CMPP20MO”这样的消息标签来写入到monster-cmppmo.log文件中。

    但是,按照以前的配置无法实现日志过滤的效果,服务器B会将接收到的所有日志全部写到每一个文件中。根本没有做分类处理。

    解决办法:

    首先加入模板

    $template TraditionalFormat, "%timegenerated% %HOSTNAME% %syslogtag%%msg:::drop-last-lf%
    "
    
    ps:drop-last-lf 表示写入所有日志

    添加完模板后,需要配置一下将模板利用起来

    if ($syslogtag startswith 'Monster-CMPP20MT')
    then {
    *.=info  /xxx/xxx/monster-cmppmt.log;TraditionalFormat
    }
    if ($syslogtag startswith 'Monster-MM7MT')
    then {
    *.=info  /xxx/xxx/monster-mm7mt.log;TraditionalFormat
    }
    ......

    重启rsyslog,解决。

  • 相关阅读:
    CF 142B Tprimes
    CF 231A Team
    poj 2001 Shortest Prefixes ——字典树入门
    hdu 1039 Easier Done Than Said?
    poj 2528 Mayor's posters
    hdu 1061 Rightmost Digit
    poj 2503 Babelfish
    CF271 A. Beautiful Year
    poj 2752
    CF271 B. Prime Matrix
  • 原文地址:https://www.cnblogs.com/l5623064/p/9760369.html
Copyright © 2011-2022 走看看