Rsyslog

rsyslog:丟棄多條消息

  • May 31, 2017

如何使用 rsyslog 一次丟棄多條消息?這不起作用,我找不到工作範例:

# Do not log any keepass and chmomium messages
if $programname == 'chromium.desktop'       then /dev/null
if $programname == 'keepass2.desktop'       then /dev/null

& stop

以下解決方案有效,但在檢查時顯示錯誤rsyslogd -N1 -f <config_file>

rsyslogd: version 8.4.2, config validation run (level 1), master config /etc/rsyslog.d/00-discard.conf
rsyslogd: CONFIG ERROR: there are no active actions configured. Inputs will run, but no output whatsoever is created. [try http://www.rsyslog.com/e/2103 ]
rsyslogd: run failed with error -2103 (see rsyslog.h or try http://www.rsyslog.com/e/2103 to learn what that number means)

該行的& stop意思是“重複前一個選擇器”,並執行“停止”動作,停止對所選消息的進一步處理。所以你需要把它放在每個if ...選擇行之後。但是,由於您的操作是寫入/dev/null,因此您不妨讓第一行做您想做的事情,即

if $programname == 'chromium.desktop'       then stop
if $programname == 'keepass2.desktop'       then stop

此處描述的還有另一種丟棄消息的方法:丟棄不需要的消息

無需像範例中那樣檢查“msg”屬性,只需檢查“programname”屬性即可。

:programname, contains, "chromium.desktop" ~

:programname, contains, "keepass2.desktop" ~

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