Nagios短信分组报警

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

一:编辑command.cfg文件,添加fetion发送短信命令
 
 
  1. [root@localhost ~]# vi /usr/local/nagios/etc/objects/commands.cfg  
  2. define command{ 
  3. command_name notify-service-by-linux 
  4. command_line /usr/local/fx/fetion --mobile=1383838438 --pwd=123 --to=1383838438 --msg-utf8="主机:IP地址$HOSTADDRESS$,服务器描述: $HOSTALIAS$/$SERVICEDESC$ 目前状 
  5.  
  6. 态:$SERVICESTATE$ 信息摘要: $SERVICEOUTPUT$" --msg-type=1 
  7.  
  8. define command{ 
  9. command_name notify-service-by-windows 
  10. command_line /usr/local/fx/fetion --mobile=1383838438 --pwd=123 --to=1333333333 --msg-utf8="主机:IP地址$HOSTADDRESS$,服务器描述: $HOSTALIAS$/$SERVICEDESC$ 目前状 
  11.  
  12. 态:$SERVICESTATE$ 信息摘要: $SERVICEOUTPUT$" --msg-type=1 
  13.  
  14. define command{ 
  15. command_name notify-host-by-sms 
  16. command_line  /bin/echo null 
二:编辑contacts.cfg文件,分别定义linux服务器的告警信息通过notify-service-by-linux发送,windows服务器的告警信息通过notify-service-by-windows,在本例中因为所有的服务器均禁止ping,所以所有的主机告警信息不发送!
 
  
  1. [root@localhost ~]# grep -v '^#'  /usr/local/nagios/etc/objects/contacts.cfg  
  2. define contact{                                  
  3.         contact_name                        linux  
  4.         use                                 linux-contact  
  5.         alias                               linux 
  6.         service_notification_period         24x7  
  7.         host_notification_period            24x7 
  8.         service_notification_options        w,u,c,r,f,s  
  9.         host_notification_options           d,u,r,f,s  
  10.         service_notification_commands       notify-service-by-linux                     
  11.         host_notification_commands          notify-host-by-sms 
  12.         } 
  13.  
  14. define contact{  
  15.         contact_name                       windows  
  16.         use                                windows-contact  
  17.         alias                              windows  
  18.         service_notification_period        24x7 
  19.         host_notification_period           24x7 
  20.         service_notification_options       w,u,c,r,f,s  
  21.         host_notification_options          d,u,r,f,s  
  22.         service_notification_commands      notify-service-by-windows  
  23.         host_notification_commands         notify-host-by-sms 
  24.         } 
  25.  
  26. define contactgroup{  
  27.         contactgroup_name           linux  
  28.         alias                       linux  
  29.         members                     linux 
  30.         } 
  31.  
  32. define contactgroup{  
  33.         contactgroup_name            windows 
  34.         alias                        windows 
  35.         members                      windows 
  36.         } 
三:编辑templates.cfg文件,在模板文件中分别定义linux服务器和windows服务器的各监控属性和通知类型(最重要的参数contact_groups),最后用于监控客户端配置文件上
 
 
  1. [root@localhost ~]# vi /usr/local/nagios/etc/objects/templates.cfg 
  2. define contact{ 
  3.         name                            linux-contact            
  4.         service_notification_period     24x7                     
  5.         host_notification_period        24x7                    
  6.         service_notification_options    w,u,c,r,f,s              
  7.         host_notification_options       d,u,r,f,s               
  8.         service_notification_commands   notify-service-by-linux 
  9.         host_notification_commands      notify-host-by-sms       
  10.         register                        0                       
  11.         } 
  12.  
  13. define contact{ 
  14.         name                            windows-contact          
  15.         service_notification_period     24x7                     
  16.         host_notification_period        24x7                     
  17.         service_notification_options    w,u,c,r,f,s              
  18.         host_notification_options       d,u,r,f,s               
  19.         service_notification_commands   notify-service-by-windows    
  20.         host_notification_commands      notify-host-by-sms      
  21.         register                        0                       
  22.         } 
  23.  
  24. define host{ 
  25.         name                            generic-host     
  26.         notifications_enabled           1               
  27.         event_handler_enabled           1                
  28.         flap_detection_enabled          1                
  29.         failure_prediction_enabled      1                
  30.         process_perf_data               1                
  31.         retain_status_information       1               
  32.         retain_nonstatus_information    1                
  33.         notification_period             24x7             
  34.         register                        0                
  35.         } 
  36.  
  37. define host{ 
  38.         name                            linux-server    
  39.         use                             generic-host    
  40.         check_period                    24x7            
  41.         check_interval                  5                
  42.         retry_interval                  1                
  43.         max_check_attempts              10              
  44.         check_command                   check-host-alive 
  45.         notification_period             24x7                                                       
  46.         notification_interval           120              
  47.         notification_options            d,u,r            
  48.         contact_groups                  linux            
  49.         register                        0                
  50.         } 
  51.  
  52. define host{ 
  53.         name                    windows-server  
  54.         use                     generic-host    
  55.         check_period            24x7             
  56.         check_interval          5                
  57.         retry_interval          1               
  58.         max_check_attempts      10              
  59.         check_command           check-host-alive         
  60.         #notification_period    24x7             
  61.         notification_interval   30              
  62.         notification_options    d,u,r            
  63.         contact_groups          windows         
  64.         register                0             
  65.         } 
  66.  
  67. define service{ 
  68.         name                            linux-service    
  69.         active_checks_enabled           1                       
  70.         passive_checks_enabled          1                        
  71.         parallelize_check               1                       problems) 
  72.         obsess_over_service             1                       
  73.         check_freshness                 0                       
  74.         notifications_enabled           1                      
  75.         event_handler_enabled           1                      
  76.         flap_detection_enabled          1                       
  77.         failure_prediction_enabled      1                        
  78.         process_perf_data               1                       
  79.         action_url                      /nagios/pnp/index.php?host=$HOSTNAME$&srv=$SERVICEDESC$ 
  80.         retain_status_information       1                        
  81.         retain_nonstatus_information    1                       
  82.         is_volatile                     0           
  83.         check_period                    24x7                   
  84.         max_check_attempts              3                        
  85.         normal_check_interval           1                       
  86.         retry_check_interval            2                       
  87.         contact_groups                  linux                    
  88.         notification_options            w,u,c,r                  
  89.         notification_interval           1440                     
  90.         notification_period             24x7                     
  91.          register                        0                      
  92.         } 
  93.  
  94. define service{ 
  95.         name                            windows-service          
  96.         active_checks_enabled           1                        
  97.         passive_checks_enabled          1                        
  98.         parallelize_check               1                                 
  99.         obsess_over_service             1                       
  100.         check_freshness                 0                        
  101.         notifications_enabled           1                        
  102.         event_handler_enabled           1                       
  103.         flap_detection_enabled          1                       
  104.         failure_prediction_enabled      1                       
  105.         process_perf_data               1                        
  106.         action_url                      /nagios/pnp/index.php?host=$HOSTNAME$&srv=$SERVICEDESC$ 
  107.         retain_status_information       1                        
  108.         retain_nonstatus_information    1                        
  109.         is_volatile                     0                        
  110.         check_period                    24x7                     
  111.         max_check_attempts              3                       
  112.         normal_check_interval           1                       
  113.         retry_check_interval            2                       
  114.         contact_groups                  windows                 
  115.         notification_options            w,u,c,r                  
  116.         notification_interval           1440                     
  117.         notification_period             24x7                   
  118.          register                        0                       
  119.         } 
 
四:linux客户端文件,host调用linux-server模板,service调用linux-service 
 
  
  1. [root@localhost ~]# grep -v '^#'  /usr/local/nagios/etc/objects/client/10.0.1.11.cfg   
  2. define host{ 
  3.         use                     linux-server            ; Name of host template to use 
  4.                                                         ; This host definition will inherit all variables that are defined 
  5.                                                         ; in (or inherited by) the linux-server host template definition. 
  6.         host_name               10.0.1.11 
  7.         alias                   10.0.1.11 
  8.         address                 10.0.1.11 
  9.         } 
  10.  
  11. define service{ 
  12.         use                             linux-service         ; Name of service template to use 
  13.         host_name                       10.0.1.11 
  14.         service_description             CPU Load  
  15.         check_command                   check_nrpe!check_load 
  16.         } 
五:windows客户端文件,host调用windows-server模板,service调用windows-service 
 
 
  1. [root@localhost ~]# grep -v '^#'  /usr/local/nagios/etc/objects/client/10.0.1.13.cfg  
  2. define host{ 
  3.         use             windows-server  ; Inherit default values from a template 
  4.         host_name       10.0.1.13       ; The name we're giving to this host 
  5.         alias           10.0.1.13       ; A longer name associated with the host 
  6.         address         10.0.1.13       ; IP address of the host 
  7.         } 
  8.  
  9. define service{ 
  10.         use                     windows-service 
  11.         host_name               10.0.1.13 
  12.         service_description     NSClient++ Version 
  13.         check_command           check_nt!CLIENTVERSION 
  14.         notifications_enabled           1 
  15.         } 
六:重启nagios服务,并验证结果
 
 
  1. [root@localhost ~]# service nagios reload 
  2. Running configuration check...done. 
  3. Reloading nagios configuration...done 

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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值