1. 开通139邮箱

2. 更改报警命令

 
  1. vi /usr/local/nagios/etc/linuxjcq/commands.cfg  
  2. define command{  
  3.     command_name    notify-host-by-email  
  4.     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/local/bin/sendEmail -f  -t $CONTACTEMAIL$ -s smtp.qq.com -u "** $NOTIFICATIONTYPE$ Host Alert: $HOSTNAME$ is $HOSTSTATE$ **" -xu qq号 -xp qq邮箱密码  
  5.     }     
  6.  
  7. define command{  
  8.     command_name    notify-service-by-email  
  9.     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/local/bin/sendEmail -f  -t $CONTACTEMAIL$ -s smtp.qq.com -u "** $NOTIFICATIONTYPE$ Service Alert: $HOSTALIAS$/$SERVICEDESC$ is $SERVICESTATE$ **" -xu qq号码 -xp qq密码  
  10.     } 

一个是主机报警,一个是服务报警

默认使用的是mail发送邮件,更改为使用sendEmail发送邮件,sendEmail安装配置见:

这边使用QQ的邮箱来发送邮件

3. 设置收件邮箱

 
  1. vi /usr/local/nagios/etc/linuxjcq/contacts.cfg  
  2. define contact{  
  3.         contact_name                    用户的名字  
  4.         use                             generic-contact  
  5.         email                           手机号@139.com  
  6.         }  
  7. ......  
  8. define contactgroup{  
  9.         contactgroup_name       admins  
  10.         alias                   Nagios Administrators  
  11.         members                 用户的名字,......  
  12.         } 

4. 重启nagios

 
  1. service nagios restart 

之后如果报警,就会往你的手机上发送短信