[Nagios] 邮件告警

1server端安装sendEmail

# wget http://caspian.dotconf.net/menu/Software/SendEmail/sendEmail-v1.56.tar.gz

# tar -zxvf sendEmail-v1.56.tar.gz

# cd sendEmail-v1.56

# mv sendEmail /usr/local/bin/

# chmod 755 /usr/local/bin/sendEmail

# chown nagios.nagios /usr/local/bin/sendEmail

 

For Example:

/usr/local/bin/sendEmail -f [email protected] -t [email protected] \
    -s smtp.163.com -u
"我是邮件主题" -o message-content-type=html \
   
-o message-charset=utf8 -xu [email protected] -xp 123456 -m "我是邮件内容"

/usr/local/bin/sendEmail    命令主程序
-f
[email protected].com  发件人邮箱

- t   [email protected]   收件人邮箱,多个以逗号相连

-s smtp.163.com       发件人邮箱的smtp服务器
-u "我是邮件主题"     邮件的标题
-o message-content-type=html   邮件内容的格式,html表示它是html格式
-o message-charset=utf8        邮件内容编码
-xu [email protected].com          发件人邮箱的用户名
-xp 123456               发件人邮箱密码
-m "我是邮件内容"        邮件的具体内容

 

 

2、配置email

# cd /usr/local/nagios/etc/objects

# vi commands.cfg

define command {

                command_name                          notify-host-by-email

                command_line                          /usr/bin/printf "%b" "***** Nagios *****\n\nNotification Type:$NOTIFICATIONTYPE$\nHost: $HOSTNAME$\nState: $HOST

STATE$\nAddress: $HOSTADDRESS$\nInfo: $HOSTOUTPUT$\n\nDate/Time: $LONGDATETIME$\n" | /usr/local/bin/sendEmail -f [email protected] -t $CONTACTEMAIL$ -s smtp.qq.com -u "

** $HOSTNAME$ is $HOSTSTATE$ **" -xu [email protected] -xp 'password'

}

 

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 60259

[email protected] -t $CONTACTEMAIL$ -s smtp.qq.com -u "** $HOSTALIAS$/$SERVICEDESC$ is $SERVICESTATE$ **" -xu [email protected] -xp 'password'

}

 

 

# vi contacts.cfg

define contact{

        contact_name                    nagiosadmin             ; Short name of user

        use                             generic-contact         ; Inherit default values from generic-contact template (defined above)

        alias                           Nagios Admin            ; Full name of user

 

        email                           [email protected]     ; <<***** CHANGE THIS TO YOUR EMAIL ADDRESS ******

        host_notification_commands            notify-host-by-email

        service_notification_commands         notify-service-by-email

        }

 

define contactgroup{

        contactgroup_name       admins

        alias                   Nagios Administrators

        members                 nagiosadmin

        }

 

 

3、配置哪些主机发送邮件

# vi linux.cfg

define host{

        use                     linux-server            ; Name of host template to use

        host_name               zabbix_server

        alias                   zabbix_server

        address                 192.168.1.201

        contact_groups          +admins              ;发送至admins

        }

 

4、重启

# service nagios restart

 

5、测试

[Nagios] 邮件告警