网创优客建站品牌官网
为成都网站建设公司企业提供高品质网站建设
热线:028-86922220
成都专业网站建设公司

定制建站费用3500元

符合中小企业对网站设计、功能常规化式的企业展示型网站建设

成都品牌网站建设

品牌网站建设费用6000元

本套餐主要针对企业品牌型网站、中高端设计、前端互动体验...

成都商城网站建设

商城网站建设费用8000元

商城网站建设因基本功能的需求不同费用上面也有很大的差别...

成都微信网站建设

手机微信网站建站3000元

手机微信网站开发、微信官网、微信商城网站...

建站知识

当前位置:首页 > 建站知识

nagios使用sendEmail邮件报警-创新互联

1.下载安装sendEmail工具

成都创新互联公司从2013年成立,是专业互联网技术服务公司,拥有项目网站建设、成都网站设计网站策划,项目实施与项目整合能力。我们以让每一个梦想脱颖而出为使命,1280元武清做网站,已为上家服务,为武清各地企业和个人服务,联系电话:18982081108

[root@db02 ~]# wget http://caspian.dotconf.net/menu/Software/SendEmail/sendEmail-v1.56.tar.gz
[root@db02 ~]# tar xvf sendEmail-v1.56.tar.gz
[root@db02 ~]# mv sendEmail-v1.56/sendEmail /usr/local/bin/sendEmail2
[root@db02 ~]# chmod 755 /usr/local/bin/sendEmail2
[root@db02 ~]# /usr/local/bin/sendEmail2 -f z597011036@126.com -t dick@tingyun.tech -s smtp.126.com -u "**$NOTIFICATIONTYPE$ alert - $HOSTALIAS$/$SERVICEDESC$ is$SERVICESTATE$ **" -xu z597011036@126.com -xp z597011036zzz -m test
Jun 01 16:59:03 db02 sendEmail2[27006]: Email was sent successfully! #测试邮件发送成功
[root@db02 ~]#

2.在nagios中定义联系人和联系组

[root@db02 ~]# cd /usr/local/nagios-4.1.1/etc/objects/
[root@db02 objects]# vim contacts.cfg
define contact{
 contact_name      dick   #联系人姓名
 use     generic-contact     #使用联系人模板
 alias    dick          #别名
 email  dick@tingyun.tech #联系人邮箱
       }
define contact{
  contact_name rayc
  use  generic-contact
  alias rayc
  email  rayc@tingyun.tech
       }
define contact{
  contact_name   tong
  use       generic-contact
  alias      tong
  email    z597011036@qq.com
       }
define contactgroup{
  contactgroup_name  tingyun  #定义联系人组
  alias   tingyun
   members   dick,rayc    #组中的成员
  }

3.报警时间,级别设置

[root@db02 objects]# vim templates.cfg   #报警参数设置
define contact{
  name   generic-contact        #定义报警联系人模板
  service_notification_period    24x7 #服务报警的时间(24小时,7天)
  host_notification_period       24x7  #主机报警的时间
  service_notification_options   w,u,c,r,f,s #服务报警级别
  host_notification_options      d,u,r,f,s  #主机报警级别

  service_notification_commands  notify-service-by-email #服务报警的命令(在command.cfg文件中)

  host_notification_commands    notify-host-by-email
  register     0     #是否可以继承
       }
define host{
  name  generic-host
  notifications_enabled     1   #是否启用主机报警
  event_handler_enabled   1   #启用主机事件程序
  flap_detection_enabled   1
  process_perf_data           1    #性能数据
  retain_status_information  1   #程序启动保留状态信息
  retain_nonstatus_information   1    #程序启动保留非状态信息

  notification_period            24x7   #报警时间
  register   0     #是否继承
   }
define host{
  name    linux-server   #自定义模板
  use    generic-host    #继承哪个模板
  check_period  24x7    #被选中的时钟
  check_interval   5        #主机每5分钟检查一次
  retry_interval     1        #每隔1分钟重试检查一次
   max_check_attempts   10   #检查每个主机10次
   check_command      check-host-alive  #默认命令检查主机
   notification_period   workhours  #只通知白天
   notification_interval   120    #每两个小时发送通知
   notification_options   d,u,r  #只发送特定主机的通知
   contact_groups    tingyun   #发送哪个组
   register   0   #是否被继承
    }
define service{
   name  generic-service     #定义模板
   active_checks_enabled  1  #启动服务检查
   passive_checks_enabled  1   #启动被动检查
   parallelize_check  1       #主动服务检查(禁用会出现严重问题)
   obsess_over_service 1
   check_freshness     0   #不检查服务新鲜度
   notifications_enabled  1   #启动服务通知
   event_handler_enabled  1   #启用服务事件
   flap_detection_enabled  1
   process_perf_data           1
   retain_status_information    1
   retain_nonstatus_information   1
   is_volatile    0   #服务不稳定
   check_period   24x7     #检查服务时间
   max_check_attempts  3     #重新检查服务3次
   normal_check_interval 10    #每10分钟检查一个服务
   retry_check_interval  2         #每2分钟再检查一次
   contact_groups   tingyun     #邮件通知联系组
   notification_options   w,u,c,r     #发送报警级别
   notification_interval   1              #每1小时重新通知服务
   notification_period       24x7      #通知时间
    register    0    #是否继承
       }
define service{
   name   local-service      #定义模板
   use   generic-service     #继承模板
   max_check_attempts   4   #最多检查服务4次
   normal_check_interval 5   #正常情况下每5分钟检查一下服务
   retry_check_interval   1    #重新检查该服务需要1分钟
   register     0     #这只是个模板
   notifications_enabled  1    #启用报警
   contact_groups    tingyun  #发送联系组
  }

4.报警脚本编写

[root@db02 objects]# vim commands.cfg
define command {
    command_name notify-service1-by-email
    command_line /usr/bin/printf "%b" "$LASTSERVICECHECK$\t$HOSTNAME$\t$SERVICEDESC$\t$SERVICESTATE$\t$SERVICEATTEMPT$\t$SERVICESTATETYPE$\t$SERVICEEXECUTIONTIME$\t$SERVICELATENCY$\t$SERVICEOUTPUT$\t$SERVICEPERFDATA$\n" | /usr/local/bin/sendEmail2 -f t 发件人邮箱 -t $CONTACTEMAIL$ -s smtp.139.com -u "**$NOTIFICATIONTYPE$ alert - $HOSTALIAS$/$SERVICEDESC$ is$SERVICESTATE$ **" -xu 发件人邮箱用户名 -xp 发件邮箱密码
}
define command {
    command_name notify-host1-by-email
    command_line /usr/bin/printf "%b" "$LASTSERVICECHECK$\t$HOSTNAME$\t$SERVICEDESC$\t$SERVICESTATE$\t$SERVICEATTEMPT$\t$SERVICESTATETYPE$\t$SERVICEEXECUTIONTIME$\t$SERVICELATENCY$\t$SERVICEOUTPUT$\t$SERVICEPERFDATA$\n" | /usr/local/bin/sendEmail2 -f 发件人邮箱 -t $CONTACTEMAIL$ -s smtp.139.com -u "**$NOTIFICATIONTYPE$ alert - $HOSTALIAS$/$SERVICEDESC$ is$SERVICESTATE$ **" -xu 发件人邮箱用户名 -xp 发件邮箱密码

}

[root@db02 objects]# /etc/init.d/nagios restart
Running configuration check...
Stopping nagios:. done.
Starting nagios: done.
[root@db02 objects]#
nagios使用sendEmail邮件报警

另外有需要云服务器可以了解下创新互联scvps.cn,海内外云服务器15元起步,三天无理由+7*72小时售后在线,公司持有idc许可证,提供“云服务器、裸金属服务器、高防服务器、香港服务器、美国服务器、虚拟主机、免备案服务器”等云主机租用服务以及企业上云的综合解决方案,具有“安全稳定、简单易用、服务可用性高、性价比高”等特点与优势,专为企业上云打造定制,能够满足用户丰富、多元化的应用场景需求。


名称栏目:nagios使用sendEmail邮件报警-创新互联
浏览地址:http://bjjierui.cn/article/cdejig.html

其他资讯