【问题标题】:change msg property to new value with rsyslog使用 rsyslog 将 msg 属性更改为新值
【发布时间】:2013-01-14 11:26:05
【问题描述】:

我有这个 rsyslog 配置:

    $template f_x,"/path/%programname%.%$YEAR%%$MONTH%%$DAY%%$HOUR%.log"

    if $programname == 'xyz' and $msg contains 'Hello World' or $msg contains 'FATAL'         
    then $msg = 'Starting xyz' ?f_x
    & ~

如何在此配置中将接收 $msg 属性从 'Hello World' 更改为 $msg = 'BlaBlaBla' 并写入文件 (%programname%.%$YEAR%%$MONTH%%$DAY%%$ HOUR%.log) 最后的 $msg 值

提前致谢

【问题讨论】:

    标签: configuration replace rsyslog msg


    【解决方案1】:

    您不能覆盖 msg 属性。

    从 rsyslog 7 开始,您可以通过使用 CEE/lumberjack 属性和自定义模板来实现这一目标。这是一个例子:

    # Notice the use of $!msg in template string
    template(name="logline" type="string"
             string="%TIMESTAMP:::date-rfc3339% %HOSTNAME% %syslogtag%%$!msg:::sp-if-no-1st-sp%%msg:::drop-last-lf%\n")
    
    # If the message matches your conditions, set $!msg to your custom string
    if ($programname == 'xyz' and $msg contains 'Hello World' or $msg contains 'FATAL') then set $!msg = "Starting xyz";
    # Otherwise, use the msg property value
    else set $!msg = $msg;
    
    # Finally, use the custom template
    action(type="omfile" file="/tmp/logfile" template="logline")
    

    有关 rsyslog 中 CEE/lumberjack 属性的更多信息,请参阅http://www.rsyslog.com/how-to-set-variables-in-rsyslog-v7/

    【讨论】:

      猜你喜欢
      • 2018-12-28
      • 1970-01-01
      • 1970-01-01
      • 2017-01-13
      • 2011-12-07
      • 1970-01-01
      • 1970-01-01
      • 2015-04-23
      • 1970-01-01
      相关资源
      最近更新 更多