nagios mail告警通知

涼城涼心涼憶悲發表於2020-12-01

nagios使用郵件來告警通知是很常見的一種方式。

1. 使用sendEmail來傳送郵件

sendEmail工具非常好用。具體內容參見:

如何使用sendEmail傳送郵件

2. 建立一個聯絡人

 

1

2

3

4

5

6

7

8

9

10

11

12

# 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. 建立一個組

 

1

2

3

4

5

define contactgroup{

        contactgroup_name       ops

        alias                   ops

        members                 mobei

        }

4. 修改傳送郵件命令

 

1

2

3

4

5

6

7

8

9

10

11

12

# 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. 指定監控專案。如:

 

1

2

3

4

5

6

7

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

}

 

相關文章