Rsyslog邮件模块不工作

我想从我的Debian Lenny FW发送snort警报。 系统日志从防火墙发送日志消息到一个中央rsyslog。

在我的中央rsyslog,我有这样的事情:

$ModLoad ommail $ActionMailSMTPServer server.company.local $ActionMailFrom [email protected] $ActionMailTo [email protected] $ActionExecOnlyOnceEveryInterval 1 $template mailSubject,"[SNORT] Alert from %hostname%" $template mailBody,"Snort message\r\nmsg='%msg%'" $ActionMailSubject mailSubject if $msg regexp 'snort\[[0-9]*\]: \[[0-9]*:[0-9]*:[0-9]*].*' then ommail:;mailBody 

但是我没有收到邮件,我甚至可以用ping -s 1400这样的东西来触发snort,它logging下来的东西,但仍然没有邮件!

 2010-01-08T09:25:58+00:00 Hostname snort[4429]: [1:499:4] ICMP Large ICMP Packet [Classification: Potentially Bad Traffic] [Priority: 2]: {ICMP} ip_dest -> ip_src 

您在ommail的前面缺less一个冒号。

if $msg regexp 'snort[[0-9]]: [[0-9]:[0-9]:[0-9]].*' then :ommail:;mailBody

我不能说你的正则expression式的准确性,但你可以尝试'包含'而不是'正则expression式',并尝试一个更简单的testing来缩小问题,如果它超出了上述语法。

我也build议在sorting之后增加$ ActionExecOnlyOnceEveryInterval。

我刚刚testing了rsyslog,并且遇到了一些bug。 我升级到backuports和万物现在工作。 你可以尝试,因为这是一个重大的升级。

我自己摔跤,可以确认rsyslog和语法的下列组合(我现在正在生产)。 我有Ubuntu的10.4.1与rsyslog 4.2出于一些奇怪的原因(这是非常古老)。 所以在删除它并安装4.6.4.1之后,我就开始运行了。

从Debian Squeeze repo获取rsyslog 4.6.4.1 这里 。 版本4.6.4(或一个或两个较早版本;现在不能记起)修复了被忽略的ActionExecOnlyOnceEveryInterval中的错误。

我使用Snort的以下语法,可以确认它确实工作:

 $IncludeConfig /etc/rsyslog.d/mail-settings.conf $template mailSubjectSnort,"Snort Alert" $template mailBodySnort,"this is the body, here's the host: %hostname%, here's the time it was reported: %timereported% and heres the message: %msg%" $ActionMailSubject mailSubjectSnort # make sure we receive an email only once per hour $ActionExecOnlyOnceEveryInterval 3600 :msg, contains, "some_string" :ommail:;mailBodySnort 

我把我的各种日志logging设备分成独立的日志文件和一个对应的.conf文件。 我还将邮件服务器指令设置在一个名为mail-settings.conf的文件中,该文件包含在每个conf的顶部。

我还在每个conf中为每个模板variables( mailBodySnortmailBodySquid等)使用一个唯一的名称,因为它好像是一个常量,每个后续包含的另一个.conf文件不会覆盖分配给之前.conf。

破解一个旧的,但因为问题仍然可以咬那些运行Debian Squeeze的,即使是来自backports的rsyslog(5.8.11-1〜bpo60 + 2目前),这可能是值得分享的,这要感谢@abeverley 在这里 ,我可以通过“在email-notify规则的末尾添加$ActionExecOnlyOnceEveryInterval 0 ”来解决这个问题。

例如,这里是我的/etc/rsyslog.d/bonding.conf

 $template bondingMailSubject,"%hostname%: bonding Event" $template bondingMailBody,"%msg%" $ActionMailSubject bondingMailSubject $ActionMailTo root $ActionExecOnlyOnceEveryInterval 300 if $programname == 'bonding' and ($msg contains 'WARNING' or $msg contains 'CRITICAL') then :ommail:;bondingMailBody $ActionExecOnlyOnceEveryInterval 0