设为首页 收藏本站
查看: 876|回复: 0

Nagios短信分组报警

[复制链接]

尚未签到

发表于 2019-1-15 07:31:14 | 显示全部楼层 |阅读模式
  Nagios监控对于服务器运维来讲是非常好的工具,可以监控各种操作系统的服务器,windows,linux,aix等等,还可以对路由器和交换机,打印机等网络设备进行监控,再结合邮件,短信,MSN等报警方式为系统管理人员节省了许多巡检时间而且成效显著!在我的运维环境中,随着监控客户端的增多,报警的频率也随着提高,没日没夜的收短信,最终不得不把手机短信调成震动模式。在收到的报警短信中,大部分是windows客户端异常的短信,相对而言,在服务器领域linux系统比windows系统稳定可靠的多。于是想到取消集中报警的方式,将windows报警发送到windows sa的手机上,linux报警发到自己的手机上,也就是分组短信报警。下面就来介绍下配置过程!

一:编辑command.cfg文件,添加fetion发送短信命令


  • [root@localhost ~]# vi /usr/local/nagios/etc/objects/commands.cfg  
  • define command{
  • command_name notify-service-by-linux
  • command_line /usr/local/fx/fetion --mobile=1383838438 --pwd=123 --to=1383838438 --msg-utf8="主机:IP地址$HOSTADDRESS$,服务器描述: $HOSTALIAS$/$SERVICEDESC$ 目前状

  • 态:$SERVICESTATE$ 信息摘要: $SERVICEOUTPUT$" --msg-type=1
  • }

  • define command{
  • command_name notify-service-by-windows
  • command_line /usr/local/fx/fetion --mobile=1383838438 --pwd=123 --to=1333333333 --msg-utf8="主机:IP地址$HOSTADDRESS$,服务器描述: $HOSTALIAS$/$SERVICEDESC$ 目前状

  • 态:$SERVICESTATE$ 信息摘要: $SERVICEOUTPUT$" --msg-type=1
  • }

  • define command{
  • command_name notify-host-by-sms
  • command_line  /bin/echo null
  • }

二:编辑contacts.cfg文件,分别定义linux服务器的告警信息通过notify-service-by-linux发送,windows服务器的告警信息通过notify-service-by-windows,在本例中因为所有的服务器均禁止ping,所以所有的主机告警信息不发送!


  • [root@localhost ~]# grep -v '^#'  /usr/local/nagios/etc/objects/contacts.cfg  
  • define contact{                                 
  •         contact_name                        linux  
  •         use                                 linux-contact  
  •         alias                               linux
  •         service_notification_period         24x7  
  •         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-linux                     
  •         host_notification_commands          notify-host-by-sms
  •         }

  • define contact{  
  •         contact_name                       windows  
  •         use                                windows-contact  
  •         alias                              windows  
  •         service_notification_period        24x7
  •         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-windows  
  •         host_notification_commands         notify-host-by-sms
  •         }

  • define contactgroup{  
  •         contactgroup_name           linux  
  •         alias                       linux  
  •         members                     linux
  •         }

  • define contactgroup{  
  •         contactgroup_name            windows
  •         alias                        windows
  •         members                      windows
  •         }



三:编辑templates.cfg文件,在模板文件中分别定义linux服务器和windows服务器的各监控属性和通知类型(最重要的参数contact_groups),最后用于监控客户端配置文件上


  • [root@localhost ~]# vi /usr/local/nagios/etc/objects/templates.cfg
  • define contact{
  •         name                            linux-contact            
  •         service_notification_period     24x7                     
  •         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-linux
  •         host_notification_commands      notify-host-by-sms      
  •         register                        0                       
  •         }

  • define contact{
  •         name                            windows-contact         
  •         service_notification_period     24x7                     
  •         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-windows   
  •         host_notification_commands      notify-host-by-sms      
  •         register                        0                       
  •         }

  • define host{
  •         name                            generic-host     
  •         notifications_enabled           1               
  •         event_handler_enabled           1               
  •         flap_detection_enabled          1               
  •         failure_prediction_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               
  •         retry_interval                  1               
  •         max_check_attempts              10              
  •         check_command                   check-host-alive
  •         notification_period             24x7                                                      
  •         notification_interval           120              
  •         notification_options            d,u,r            
  •         contact_groups                  linux            
  •         register                        0               
  •         }

  • define host{
  •         name                    windows-server  
  •         use                     generic-host   
  •         check_period            24x7            
  •         check_interval          5               
  •         retry_interval          1               
  •         max_check_attempts      10              
  •         check_command           check-host-alive         
  •         #notification_period    24x7            
  •         notification_interval   30              
  •         notification_options    d,u,r            
  •         contact_groups          windows         
  •         register                0            
  •         }

  • define service{
  •         name                            linux-service   
  •         active_checks_enabled           1                       
  •         passive_checks_enabled          1                        
  •         parallelize_check               1                       problems)
  •         obsess_over_service             1                       
  •         check_freshness                 0                       
  •         notifications_enabled           1                     
  •         event_handler_enabled           1                     
  •         flap_detection_enabled          1                       
  •         failure_prediction_enabled      1                        
  •         process_perf_data               1                       
  •         action_url                      /nagios/pnp/index.php?host=$HOSTNAME$&srv=$SERVICEDESC$
  •         retain_status_information       1                        
  •         retain_nonstatus_information    1                       
  •         is_volatile                     0           
  •         check_period                    24x7                  
  •         max_check_attempts              3                        
  •         normal_check_interval           1                       
  •         retry_check_interval            2                       
  •         contact_groups                  linux                    
  •         notification_options            w,u,c,r                  
  •         notification_interval           1440                     
  •         notification_period             24x7                     
  •          register                        0                     
  •         }

  • define service{
  •         name                            windows-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                       
  •         failure_prediction_enabled      1                       
  •         process_perf_data               1                        
  •         action_url                      /nagios/pnp/index.php?host=$HOSTNAME$&srv=$SERVICEDESC$
  •         retain_status_information       1                        
  •         retain_nonstatus_information    1                        
  •         is_volatile                     0                        
  •         check_period                    24x7                     
  •         max_check_attempts              3                       
  •         normal_check_interval           1                       
  •         retry_check_interval            2                       
  •         contact_groups                  windows                 
  •         notification_options            w,u,c,r                  
  •         notification_interval           1440                     
  •         notification_period             24x7                  
  •          register                        0                       
  •         }



四:linux客户端文件,host调用linux-server模板,service调用linux-service


  • [root@localhost ~]# grep -v '^#'  /usr/local/nagios/etc/objects/client/10.0.1.11.cfg   
  • define host{
  •         use                     linux-server            ; Name of host template to use
  •                                                         ; This host definition will inherit all variables that are defined
  •                                                         ; in (or inherited by) the linux-server host template definition.
  •         host_name               10.0.1.11
  •         alias                   10.0.1.11
  •         address                 10.0.1.11
  •         }

  • define service{
  •         use                             linux-service         ; Name of service template to use
  •         host_name                       10.0.1.11
  •         service_description             CPU Load  
  •         check_command                   check_nrpe!check_load
  •         }



五:windows客户端文件,host调用windows-server模板,service调用windows-service


  • [root@localhost ~]# grep -v '^#'  /usr/local/nagios/etc/objects/client/10.0.1.13.cfg  
  • define host{
  •         use             windows-server  ; Inherit default values from a template
  •         host_name       10.0.1.13       ; The name we're giving to this host
  •         alias           10.0.1.13       ; A longer name associated with the host
  •         address         10.0.1.13       ; IP address of the host
  •         }

  • define service{
  •         use                     windows-service
  •         host_name               10.0.1.13
  •         service_description     NSClient++ Version
  •         check_command           check_nt!CLIENTVERSION
  •         notifications_enabled           1
  •         }

六:重启nagios服务,并验证结果


  • [root@localhost ~]# service nagios reload
  • Running configuration check...done.
  • Reloading nagios configuration...done




  后记:服务器报警信息固然重要,但如果报警信息泛滥,从应用或者资源上无法及时调整到位,运维人员难免会对报警短信产生厌烦情绪,进而可能会忽略重要的报警信息,对服务器运维造成负面的影响,也会让领导认为监控系统可有可无,其实还是可以从技术角度上解决一些问题的,例如工作时间短信发送到QQ邮箱,MSN上,非工作时间短信发送到运维人员手机或者值班手机上,就是一种不错的办法,但监控只是一种手段,服务器问题还是早预见早解决为妙!




运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-663356-1-1.html 上篇帖子: nagios 邮件通知内容 下篇帖子: Nagios(三)——监控外部信息(主机、服务)
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表