0987 发表于 2014-9-30 08:33:04

nagios邮件报警设置

                      1、下载 sendEmail
   wget http://caspian.dotconf.net/menu/Software/SendEmail/sendEmail-v1.56.tar.gz
2、配置 sendEmail
   tar zxvf sendEmail-v1.56.tar.gz
   cd sendEmail-v1.56
   cp sendEmail /usr/local/bin
   chmod 777 /usr/local/bin/sendEmail
   发送测试邮件
   /usr/local/bin/sendEmail -f test@126.com -t test@qq.com -s smtp.126.com -xu test@126.com -xp password -u "nagios" -m "tets"
解释:
-f表示发送者的邮箱
-t表示接收者的邮箱
-s表示SMTP服务器的域名或者ip
-u表示邮件的主题
-xu表示SMTP验证的用户名
-xp表示SMTP验证的密码
-m表示邮件的内容
3、配置contacts.cfg
vi /usr/local/nagios/etc/objects/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                           test@test.com   ; <<***** CHANGE THIS TO YOUR EMAIL ADDRESS ******
      }
4、配置commands.cfg
vi /usr/local/nagios/etc/objects/commands.cfg
注解# 'notify-host-by-email' command definition 与# 'notify-service-by-email' command definition下所有的设置
重新输入以下内容

# 'notify-host-by-email' command definition
define command{
       command_name    notify-host-by-email
       command_line    /usr/bin/printf "%b" "***** Nagios *****\nNotification Type: $NOTIFICATIONTYPE$\nHost: $HOSTNAME$\nState: $HOSTSTATE$\nAddress: $HOSTADDRESS$\nInfo: $HOSTOUTPUT$\n\nDate/Time: $LONGDATETIME$\n" | /usr/local/bin/sendEmail -f test@126.com -t $CONTACTEMAIL$ -s smtp.126.com -u "**$HOSTALIAS$ is $HOSTSTATE$**"-xu test@126.com -xp password -o message-charset=utf8
       }
# 'notify-service-by-email' command definition
define command{
       command_name    notify-service-by-email
           command_line    /usr/bin/printf "%b" "***** Nagios *****\nNotification Type: $NOTIFICATIONTYPE$\nService: $SERVICEDESC$\nHost: $HOSTALIAS$\nAddress: $HOSTADDRESS$\nState: $SERVICESTATE$\n\nDate/Time: $LONGDATETIME$\n\nAdditional Info:\n$SERVICEOUTPUT$\n" | /usr/local/bin/sendEmail -f test@126.com -t $CONTACTEMAIL$ -s smtp.126.com -u "**$HOSTALIAS$/$SERVICEDESC$ is $SERVICESTATE$**" -xu test@126.com -xp password -o message-charset=utf8
       }
5、重启服务
                   

页: [1]
查看完整版本: nagios邮件报警设置