xsmscb 发表于 2019-1-16 09:15:11

nagios设置邮件告警

  搭建nagios的目的就是为了他的报警系统,nagios据我所了解可以有三种报警:
  一、声音报警
  二、电子邮件报警
  三、手机短讯报警
  四、传真告警
  下面是我的邮件报警的配置过程:
  1、开启系统自带的sendmail邮件系统
  service sendmail start
  如果没有安装,可以yum一下
  yum install -y sendmail*
  service sendmail restart
  测试发送邮件:
  echo "test" | mail 88fly@163.com
  注:iptables和selinux设置
  2、配置nagios中报警邮箱
  vi /usr/local/nagios/etc/objects/contacts.cfg
  define contact{
  contact_name                  mail                  ; Short name of user
  alias                           null             ; Full name of user
  service_notification_period   24x7 (和如下时间模版(timeperiod)保持一致)
  host_notification_period      24x7
  service_notification_options    w,u,c,r
  host_notification_options       d,u,r
  service_notification_commands   notify-service-by-email
  host_notification_commands      notify-host-by-email
  email                           88fly@163.com
  }
  在email那里加上自己的邮箱,如果有多个可以用逗号隔开
  3、设置报警方式:
  define timeperiod{
  timeperiod_name 24x7
  alias         24 Hours A Day, 7 Days A Week
  sunday          00:00-24:00
  monday          00:00-24:00
  tuesday         00:00-24:00
  wednesday       00:00-24:00
  thursday      00:00-24:00
  friday          00:00-24:00
  saturday      00:00-24:00
  }
  这两个notify-service-by-email 和notify-host-by-email    是在command.cfg那里定义的,看看是怎么定义的:# 'notify-service-by-email' command definition
  define command{
  command_name    notify-service-by-email
  command_line      echo " ** $NOTIFICATIONTYPE$ Service Alert: $HOSTNAME$/$HOSTADDRESS$ $SERVICEDESC$ is $SERVICESTATE$\n\nDate/Time: $LONGDATETIME$ Additional Info:$SERVICEOUTPUT$ "| formail -I "Subject: $HOSTADDRESS$*$SERVICEOUTPUT$*$LONGDATETIME$"| sendmail -oi $CONTACTEMAIL$
  }
  # '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" | /bin/mail -s "** $NOTIFICATIONTYPE$ Host Alert: $HOSTNAME$ is $HOSTSTATE$ **" $CONTACTEMAIL$
  }
  这里已经默认配置好,我们不用修改直接调用就是了
  最后重启服务:
  service nagios retart
  进行破环性测试!

页: [1]
查看完整版本: nagios设置邮件告警