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

发布时间:2019-10-28编辑:脚本学堂
CentOS 6.3x86_64编译安装Nagios:下载 nagios-3.4.3.tar.gz 与 nagios-plugins-1.4.15.tar.gz 并安装。

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 *****nnNotification Type: $NOTIFICATIONTYPE$nHost: $hostname$nState: $HOSTSTATE$nAddress: $HOSTADDRESS$nInfo: $HOSTOUTPUT$nnDate/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 *****nnNotification Type: $NOTIFICATIONTYPE$nnService: $SERVICEDESC$nHost: $HOSTalias$nAddress: $HOSTADDRESS$nState: $SERVICESTATE$nnDate/Time: $LONGDATETIME$nnAdditional Info:nn$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验证。