使用邮件报警
为灵寿等地区用户提供了全套网页设计制作服务,及灵寿网站建设行业解决方案。主营业务为网站设计、做网站、灵寿网站设计,以传统方式定制建设网站,并提供域名空间备案等一条龙服务,秉承以专业、用心的态度为用户提供真诚的服务。我们深信只要达到每一位用户的要求,就会得到认可,从而选择与我们长期合作。这样,我们也可以走得更远!
1、我安装了sendemail,并测试发送邮件成功
2、修改command.cfg
# 'notify-host-by-email' command definition
define command{
command_namenotify-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_namenotify-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_optionsw,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
usegeneric-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报警邮件。这到底是怎么回事呢,如果要是模版里面进行设置的,那我要修改什么才能达到每次开关都报警,不管频率有多频繁。