rsyslog如何自定义模板

在rsyslog配置文件中定义模板
/etc/rsyslog.conf

1.添加模板
以下内容是自定义的模板

$template templateName, “%$Year% %timestamp:1:10:date-rfc3339% UserDefineTAG %MSG% %structured-date% n\%

参数解释

templateName 模板名

%$Year% System Properties,参考https://www.rsyslog.com/doc/v7-stable/configuration/properties.html
$符号不可省略

%timestamp:1:10:date-rfc3339% Message Properties,参考https://www.rsyslog.com/doc/v7-stable/configuration/properties.html
1表示从第一个字符开始,10表示到第10个字符结束。即仅截取timestamp的1到10个字符
Date-rfc3339 属性选项,参考https://www.rsyslog.com/doc/v7-stable/configuration/property_replacer.html

UserDefineTAG 可以直接追加字符,在每一行log中显示
%MSG% 默认syslog协议的消息内容
%structured-data% 有些log的内容使用方括号括上的 例如checkpoint 防火墙的log,[action:denny ……],这些属于structured-data,单独使用MSG是无法显示的。

2.如何使用模板
在LOG文件之后加 ;模板名 即可使用模板
例1. Local0.* /home/log/archive.log;templateName

例2. If $fromhost-ip = ‘xxx.xxx.xxx.xxx’ then /home/log/archive.log;templateName

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章