Rhel

如何在攝取 syslog 事件時編輯我的配置文件以創建兩個日誌文件?

  • October 16, 2019

我正在通過 syslog 從同一伺服器 10.10.10.10 向我的 RHEL7 伺服器發送郵件消息日誌和放大器日誌。我正在執行 rsyslog 並具有以下配置文件:

mail_logs.conf

$template NetworkLog, "/var/log/mail_logs/mail_logs.log"
:fromhost-ip, isequal, "10.10.10.10" -?NetworkLog
& ~

我的mail_logs.log看起來像:

Oct 16 10:58:01 server.com mail_mess_logs: Info: Begin Logfile
Oct 16 10:58:01 server.com mail_mess_logs: Info: Version: 0.0.0 SN:...
Oct 16 10:58:01 server.com mail_mess_logs: Info: Time offset from UTC: -14400 seconds
Oct 16 10:58:02 server.com amp_logs: Info: Begin Logfile
Oct 16 10:58:02 server.com amp_logs: Info: Version: 0.0.0 SN:...
Oct 16 10:58:02 server.com amp_logs: Info: Time offset from UTC: -14400 seconds

我想把這些分解mail_mess_logsamp_logs所以我有兩個文件,比如:

mail_mess_logs.log

Oct 16 10:58:01 server.com mail_mess_logs: Info: Begin Logfile
Oct 16 10:58:01 server.com mail_mess_logs: Info: Version: 0.0.0 SN:...
Oct 16 10:58:01 server.com mail_mess_logs: Info: Time offset from UTC: -14400 seconds

amp_logs.log

Oct 16 10:58:02 server.com amp_logs: Info: Begin Logfile
Oct 16 10:58:02 server.com amp_logs: Info: Version: 0.0.0 SN:...
Oct 16 10:58:02 server.com amp_logs: Info: Time offset from UTC: -14400 seconds

我怎樣才能做到這一點?

您正在使用rsyslog 支持的較舊、更基本的過濾器樣式之一。稍微不那麼舊的樣式允許您使用包括 and運算符在內的表達式。該屬性 programname應保存"mail_mess_logs"字元串。所以你可以做

if $fromhost-ip=="10.10.10.10" and $programname=="mail_mess_logs" then -/var/log/mail_logs/mail_mess_logs.log
if $fromhost-ip=="10.10.10.10" and $programname=="amp_logs" then -/var/log/mail_logs/amp_logs.log

或者,還有一種更複雜的風格,稱為RainerScript

引用自:https://unix.stackexchange.com/questions/547103