如何忽略rsyslog中的Smartd消息

有没有一种方法,Rsyslog服务器logging除smartd消息之外的所有消息。 我只想要“目前无法读取(待定)扇区”不logging。

就在这里。 logging这些消息的规则需要在一个filter中,像这样:(假设smartd消息logging在/var/log/smartd.log中)

 if ($programname == "smartd") then { if not ($msg contains "Currently unreadable (pending) sectors") then { *.* /var/log/smartd.log } stop } 

上面的代码将匹配所有来自smartd服务的消息。 如果消息没有那个string,它会在/var/log/smartd.log中logging所有消息,但是如果它包含那个string,它将不会logging。 所有通过此点的日志都将被停止规则删除。

你可以把这段代码放到/etc/rsyslog.d/文件中,以.conf结尾,就像01-smartd.conf一样。 由于rsyslog.conf加载以.conf结尾的此目录中的所有文件,因此将以49之前的00开头的文件将首先比默认文件50-default.conf读取。

请注意,通过代码中的停止规则,如果先读取,则消息将不会达到50-default.conf中的规则,因此不会存在重复的消息。