最新消息:

nagios mail告警通知

监控 admin 3617浏览 0评论

nagios使用邮件来告警通知是很常见的一种方式。

1. 使用sendEmail来发送邮件

sendEmail工具非常好用。具体内容参见:

如何使用sendEmail发送邮件

2. 创建一个联系人

# vim /usr/local/nagios/etc/objects/contacts.cfg
define contact{
        contact_name                    mobei
        alias                           mobei
        service_notification_period     24x7
        host_notification_period        24x7
        service_notification_options    w,u,c
        host_notification_options       d,u
        service_notification_commands   notify-service-by-email
        host_notification_commands      notify-host-by-email
        email                           【You email address】
        }

3. 创建一个组

define contactgroup{
        contactgroup_name       ops
        alias                   ops
        members                 mobei
        }

4. 修改发送邮件命令

# vim /usr/local/nagios/etc/objects/commands.cfg
# 'notify-host-by-email' command definition
define command{
        command_name    notify-host-by-email
        command_line  /usr/local/bin/sendEmail -l /tmp/sendEmail.log -f jiank@126.com -t $CONTACTEMAIL$ -s smtp.126.com -u "$HOSTALIAS$/$SERVICEDESC$ is $SERVICESTATE$" -xu jiank@126.com -xp jiankong -m "Service: $SERVICEDESC$\nHost: $HOSTALIAS$\nAddress: $HOSTADDRESS$  State: $SERVICESTATE$\nDate/Time: $SHORTDATETIME$\nInfo:$SERVICEOUTPUT$"
        }

# 'notify-service-by-email' command definition
define command{
        command_name    notify-service-by-email
        command_line  /usr/local/bin/sendEmail -l /tmp/sendEmail.log -f jiank@126.com -t $CONTACTEMAIL$ -s smtp.126.com -u "$HOSTALIAS$/$SERVICEDESC$ is $SERVICESTATE$" -xu jiank@126.com -xp jiankong -m "Service: $SERVICEDESC$\nHost: $HOSTALIAS$\nAddress: $HOSTADDRESS$  State: $SERVICESTATE$\nDate/Time: $SHORTDATETIME$\nInfo:$SERVICEOUTPUT$"
        }

5. 指定监控项目。如:

define service {
    use                 generic-service
    hostgroup_name          Mongo Servers
    service_description     Mongo Mapped Memory Usage
    check_command           check_mongodb!10.0.0.160!12345!'ttlsa'!'www.ttlsa.com'!memory_mapped!20!28
    contact_groups          ops
}

转载请注明:爱开源 » nagios mail告警通知

您必须 登录 才能发表评论!