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

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