cxin 发表于 2019-1-15 06:38:00

关于nagios 邮件报警问题

  使用邮件报警
  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 ;
页: [1]
查看完整版本: 关于nagios 邮件报警问题