当前位置: > Linux服务器 > 监控工具 >

nagios发送邮件异常的处理方法

时间:2014-10-26 01:22来源:linux.it.net.cn 作者:it

CentOS 6.3x86_64编译安装Nagios:
下载 nagios-3.4.3.tar.gz 与 nagios-plugins-1.4.15.tar.gz 并安装。
yum install -y mutt.x86_64

nagios 默认发邮件配置更改为
   

复制代码代码如下:
define command{
        command_name    notify-host-by-email
        command_line    /usr/bin/printf "%b" "***** Nagios *****\n\nNotification Type: $NOTIFICATIONTYPE$\nHost: $HOSTNAME$\nState: $HOSTSTATE$\nAddress: $HOSTADDRESS$\nInfo: $HOSTOUTPUT$\n\nDate/Time: $LONGDATETIME$\n" | /usr/bin/mutt -F "/usr/local/nagios/etc/objects/muttrc" -s "** $NOTIFICATIONTYPE$ Host Alert: $HOSTNAME$ is $HOSTSTATE$ **" $CONTACTEMAIL$
        }
    define command{
        command_name    notify-service-by-email
        command_line    /usr/bin/printf "%b" "***** Nagios *****\n\nNotification Type: $NOTIFICATIONTYPE$\n\nService: $SERVICEDESC$\nHost: $HOSTALIAS$\nAddress: $HOSTADDRESS$\nState: $SERVICESTATE$\n\nDate/Time: $LONGDATETIME$\n\nAdditional Info:\n\n$SERVICEOUTPUT$\n" | /usr/bin/mutt -F "/usr/local/nagios/etc/objects/muttrc" -s "** $NOTIFICATIONTYPE$ Service Alert: $HOSTALIAS$/$SERVICEDESC$ is $SERVICESTATE$ **" $CONTACTEMAIL$
        }

查看ngaios.log
    [1357436774] SERVICE NOTIFICATION: nagiosadmin;SH-Web-Tomcat05;HTTP;CRITICAL;notify-service-by-email;HTTP CRITICAL - No data received from host
    [1357437364] SERVICE NOTIFICATION: nagiosadmin;SH-Web-Tomcat01;HTTP;CRITICAL;notify-service-by-email;HTTP CRITICAL - No data received from host
    [1357437474] SERVICE NOTIFICATION: nagiosadmin;SH-Web-Tomcat01;SSH;CRITICAL;notify-service-by-email;拒绝连接


切换到nagios用户
 

复制代码代码如下:
echo "message" | mutt -F /usr/local/nagios/etc/objects/muttrc -s "Test abc $(data +%s)" admin@i-david.org

邮件发送正常。

备注:
最后是nagios调用mutt发送邮件时引用到了文件/root/sent 文件

/root
/root/sent

这两个目录都给nagios用户能读写权限即可
xtso520ok 22小时前
进一步确认

是nagios这个用户,后台执行mutt,发送邮件有问题

验证理由

在nagios用户下crontab -e

echo OK | mutt -s "Test" admin@i-david.org

未收到东西

定时任务已经执行,有log验证。

(责任编辑:IT)
------分隔线----------------------------