使用rsyslog将msg属性更改为新值

时间:2013-01-30 15:26:42

标签: configuration replace rsyslog msg

我有这个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
    & ~

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

提前致谢

1 个答案:

答案 0 :(得分:4)

您无法覆盖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/