温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

关于nagios 邮件报警问题

发布时间:2020-10-08 18:49:20 来源:网络 阅读:317 作者:685436a 栏目:移动开发

使用邮件报警

1、我安装了sendemail,并测试发送邮件成功

2、修改command.cfg

# 'notify-host-by-email' command definition

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/bin/sendemail -f zx@zx.com -t $CONTACTEMAIL$ -s 192.168.1.88 -u "** $NOTIFICATIONTYPE$ Host Alert: $HOSTNAME$ is $HOSTSTATE$ **" -xu zx@zx.com -xp 123456

}

# 'notify-service-by-email' command definition

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/bin/sendemail -f zx@zx.com -t $CONTACTEMAIL$ -s 192.168.1.88 -u "** $NOTIFICATIONTYPE$ Service Alert: $HOSTALIAS$/$SERVICEDESC$ is $SERVICESTATE$ **" -xu zx@zx.com -xp 123456

 

3、templates.cfg模版我使用的通用服务的设置

define service{

        name                            generic-service  ; The 'name' of this service template

        active_checks_enabled           1        ; Active service checks are enabled

        passive_checks_enabled          1         ; Passive service checks are enabled/accepted

        parallelize_check               1        ; Active service checks should be parallelized (disabling this can lead to major performance problems)

        obsess_over_service             1        ; We should obsess over this service (if necessary)

        check_freshness                 0        ; Default is to NOT check service 'freshness'

        notifications_enabled           1        ; Service notifications are enabled

        event_handler_enabled           1        ; Service event handler is enabled

        flap_detection_enabled          0        ; Flap detection is enabled

        failure_prediction_enabled      1        ; Failure prediction is enabled

        process_perf_data               1        ; Process performance data

        retain_status_information       1        ; Retain status information across program restarts

        retain_nonstatus_information    1        ; Retain non-status information across program restarts

        is_volatile                     0        ; The service is not volatile

        check_period                    24x7 ; The service can be checked at any time of the day

        max_check_attempts              1 ; Re-check the service up to 3 times in order to determine its final (hard) state

        normal_check_interval           2 ; Check the service every 10 minutes under normal conditions

        retry_check_interval            2 ; Re-check the service every two minutes until a hard state can be determined

        contact_groups                  admins ; Notifications get sent out to everyone in the 'admins' group

notification_options w,u,c,r ; Send notifications about warning, unknown, critical, and recovery events

        notification_interval           10 ; Re-notify about service problems every hour

        notification_period             24x7 ; Notifications can be sent out at any time

         register                        0        ; DONT REGISTER THIS DEFINITION - ITS NOT A REAL SERVICE, JUST A TEMPLATE!

        }

 

4、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                           zqy@zx.com ; <<***** CHANGE THIS TO YOUR EMAIL ADDRESS ******

        }

###############################################################################

###############################################################################

#

# CONTACT GROUPS

#

###############################################################################

###############################################################################

# We only have one contact in this simple configuration file, so there is

# no need to create more than one contact group.

define contactgroup{

        contactgroup_name       admins

        alias                   Nagios Administrators

        members                 nagiosadmin

        }

 

5、nagios刚做好,把远程主机给关闭,发现服务全部都收到邮件报警,再开机,发现报OK的邮件(所有service加上一个主机都正常)

但是我想再关机进行测试的时候,就发现不报警了,只有一个service报警邮件。这到底是怎么回事呢,如果要是模版里面进行设置的,那我要修改什么才能达到每次开关都报警,不管频率有多频繁。

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI