1. 开通139邮箱
略
2. 更改报警命令
- vi /usr/local/nagios/etc/linuxjcq/commands.cfg
- 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/local/bin/sendEmail -f -t $CONTACTEMAIL$ -s smtp.qq.com -u "** $NOTIFICATIONTYPE$ Host Alert: $HOSTNAME$ is $HOSTSTATE$ **" -xu qq号 -xp qq邮箱密码
- }
- 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/local/bin/sendEmail -f -t $CONTACTEMAIL$ -s smtp.qq.com -u "** $NOTIFICATIONTYPE$ Service Alert: $HOSTALIAS$/$SERVICEDESC$ is $SERVICESTATE$ **" -xu qq号码 -xp qq密码
- }
一个是主机报警,一个是服务报警
默认使用的是mail发送邮件,更改为使用sendEmail发送邮件,sendEmail安装配置见:
这边使用QQ的邮箱来发送邮件
3. 设置收件邮箱
- vi /usr/local/nagios/etc/linuxjcq/contacts.cfg
- define contact{
- contact_name 用户的名字
- use generic-contact
- email 手机号@139.com
- }
- ......
- define contactgroup{
- contactgroup_name admins
- alias Nagios Administrators
- members 用户的名字,......
- }
4. 重启nagios
- service nagios restart
之后如果报警,就会往你的手机上发送短信