手机版
你好,游客 登录 注册
背景:
阅读新闻

Nagios短信分组报警

[日期:2013-05-25] 来源:Linux社区  作者:ylw6006 [字体:大 中 小]

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. 态:$SERVICESTATE$ 信息摘要: $SERVICEOUTPUT$" --msg-type=1
  6. }
  7. define command{
  8. command_name notify-service-by-windows
  9. command_line /usr/local/fx/fetion --mobile=1383838438--pwd=123--to=1333333333--msg-utf8="主机:IP地址$HOSTADDRESS$,服务器描述: $HOSTALIAS$/$SERVICEDESC$ 目前状
  10. 态:$SERVICESTATE$ 信息摘要: $SERVICEOUTPUT$" --msg-type=1
  11. }
  12. define command{
  13. command_name notify-host-by-sms
  14. command_line /bin/echo null
  15. }
二:编辑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. define contact{
  14. contact_name windows
  15. use windows-contact
  16. alias windows
  17. service_notification_period 24x7
  18. host_notification_period 24x7
  19. service_notification_options w,u,c,r,f,s
  20. host_notification_options d,u,r,f,s
  21. service_notification_commands notify-service-by-windows
  22. host_notification_commands notify-host-by-sms
  23. }
  24. define contactgroup{
  25. contactgroup_name linux
  26. alias linux
  27. members linux
  28. }
  29. define contactgroup{
  30. contactgroup_name windows
  31. alias windows
  32. members windows
  33. }
三:编辑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. define contact{
  13. name windows-contact
  14. service_notification_period 24x7
  15. host_notification_period 24x7
  16. service_notification_options w,u,c,r,f,s
  17. host_notification_options d,u,r,f,s
  18. service_notification_commands notify-service-by-windows
  19. host_notification_commands notify-host-by-sms
  20. register 0
  21. }
  22. define host{
  23. name generic-host
  24. notifications_enabled 1
  25. event_handler_enabled 1
  26. flap_detection_enabled 1
  27. failure_prediction_enabled 1
  28. process_perf_data 1
  29. retain_status_information 1
  30. retain_nonstatus_information 1
  31. notification_period 24x7
  32. register 0
  33. }
  34. define host{
  35. name linux-server
  36. use generic-host
  37. check_period 24x7
  38. check_interval 5
  39. retry_interval 1
  40. max_check_attempts 10
  41. check_command check-host-alive
  42. notification_period 24x7
  43. notification_interval 120
  44. notification_options d,u,r
  45. contact_groups linux
  46. register 0
  47. }
  48. define host{
  49. name windows-server
  50. use generic-host
  51. check_period 24x7
  52. check_interval 5
  53. retry_interval 1
  54. max_check_attempts 10
  55. check_command check-host-alive
  56. #notification_period 24x7
  57. notification_interval 30
  58. notification_options d,u,r
  59. contact_groups windows
  60. register 0
  61. }
  62. define service{
  63. name linux-service
  64. active_checks_enabled 1
  65. passive_checks_enabled 1
  66. parallelize_check 1 problems)
  67. obsess_over_service 1
  68. check_freshness 0
  69. notifications_enabled 1
  70. event_handler_enabled 1
  71. flap_detection_enabled 1
  72. failure_prediction_enabled 1
  73. process_perf_data 1
  74. action_url /nagios/pnp/index.php?host=$HOSTNAME$&srv=$SERVICEDESC$
  75. retain_status_information 1
  76. retain_nonstatus_information 1
  77. is_volatile 0
  78. check_period 24x7
  79. max_check_attempts 3
  80. normal_check_interval 1
  81. retry_check_interval 2
  82. contact_groups linux
  83. notification_options w,u,c,r
  84. notification_interval 1440
  85. notification_period 24x7
  86. register 0
  87. }
  88. define service{
  89. name windows-service
  90. active_checks_enabled 1
  91. passive_checks_enabled 1
  92. parallelize_check 1
  93. obsess_over_service 1
  94. check_freshness 0
  95. notifications_enabled 1
  96. event_handler_enabled 1
  97. flap_detection_enabled 1
  98. failure_prediction_enabled 1
  99. process_perf_data 1
  100. action_url /nagios/pnp/index.php?host=$HOSTNAME$&srv=$SERVICEDESC$
  101. retain_status_information 1
  102. retain_nonstatus_information 1
  103. is_volatile 0
  104. check_period 24x7
  105. max_check_attempts 3
  106. normal_check_interval 1
  107. retry_check_interval 2
  108. contact_groups windows
  109. notification_options w,u,c,r
  110. notification_interval 1440
  111. notification_period 24x7
  112. register 0
  113. }
linux
本文评论   查看全部评论 (0)
表情: 表情 姓名: 字数

       

评论声明
  • 尊重网上道德,遵守中华人民共和国的各项有关法律法规
  • 承担一切因您的行为而直接或间接导致的民事或刑事法律责任
  • 本站管理人员有权保留或删除其管辖留言中的任意内容
  • 本站有权在网站内转载或引用您的评论
  • 参与本评论即表明您已经阅读并接受上述条款