注:试过用QQ邮件报警,发送不了

1.安装sendMail

   yum install -y sendmail*

2.测试sendmail 发送邮件

/usr/local/bin/sendEmail –f [email protected] –t [email protected] –s smtp.163.com –u “from nagios” –xu nagios –xp ****** –m happy

解释:

-f 表示发送者的邮箱

-t 表示接收者的邮箱

-s 表示SMTP服务器的域名或者ip

-u 表示邮件的主题

-xu 表示SMTP验证的用户名

-xp 表示SMTP验证的密码

-m 表示邮件的内容

3.修改配置文件command.cfg 和 contacts.cfg

vi /etc/nagiosql/commands.cfg

define command{

       command_name    notify-host-by-email

       command_line    /usr/bin/printf "%b" "***** Nagios-BJ *****\n\nNotification Type: $NOTIFICATIONTYPE$\nHost: $HOSTNAME$\nState: $HOSTSTATE$\nAddress: $HOSTADDRESS$\nInfo: $HOSTOUTPUT$\n\nDate/Time: $LONGDATETIME$\n" | /usr/local/bin/sendEmail -f [email protected] -t $CONTACTEMAIL$ -s smtp.163.com -u "** $NOTIFICATIONTYPE$ Host Alert: $HOSTNAME$ is $HOSTSTATE$ **" -xu nagios88 -xp ******* -l /var/log/sendEmail.log

       }


define command{

       command_name    notify-service-by-email

       command_line    /usr/bin/printf "%b" "***** Nagios-BJ *****\n\nNotification Type: $NOTIFICATIONTYPE$\n\nService: $SERVICEDESC$\nHost: $HOSTNAME$\nAddress: $HOSTADDRESS$\nState: $SERVICESTATE$\n\nDate/Time: $LONGDATETIME$\n\nAdditional Info:\n\n$SERVICEOUTPUT$\n" | /usr/local/bin/sendEmail -f [email protected] -t $CONTACTEMAIL$ -s smtp.163.com -u  "** $NOTIFICATIONTYPE$ Service Alert: $HOSTNAME$/$SERVICEDESC$ is $SERVICESTATE$ **" -xu nagios88 -xp ***** -l /var/log/sendEmail.log

       }


vi /etc/nagiosql/contacts.cfg

把email改为你自己的邮箱地址


测试把被监控机httpd关闭

接收到邮件

nagios 163邮件报警_第1张图片

完成