[关闭]
@saltyang 2017-05-26T11:01:58.000000Z 字数 4312 阅读 590

Nagios Notification for SMS

Nagios SMS


Add Contact

  1. define contact{
  2. contact_name opsuser
  3. use generic-contact
  4. alias opsuser
  5. service_notification_period 24x7
  6. host_notification_period 24x7
  7. service_notification_options w,u,c,r
  8. host_notification_options d,u
  9. service_notification_commands notify-service-by-sms
  10. host_notification_commands notify-host-by-sms
  11. pager 13151572201
  12. }
  13. define contactgroup{
  14. contactgroup_name ops
  15. alias ops
  16. members opsuser
  17. }

Add Sms command

  1. # 'notify-host-by-sms' command definition
  2. define command{
  3. command_name notify-host-by-sms
  4. command_line /usr/local/bin/sendsms.pl $CONTACTPAGER$ "*** $NOTIFICATIONTYPE$ Host Alert: $HOSTNAME$ IP: $HOSTADDRESS$ is $HOSTSTATE$ ***"
  5. }
  6. # 'notify-service-by-sms' command definition
  7. define command{
  8. command_name notify-service-by-sms
  9. command_line /usr/local/bin/sendsms.pl $CONTACTPAGER$ "*** $NOTIFICATIONTYPE$ Service Alert: $HOSTNAME$ IP: $HOSTADDRESS$ / $SERVICEDESC$ is $SERVICESTATE$ ***"
  10. }

Add Template host and service

  1. define host{
  2. name linux-server ; The name of this host template
  3. use generic-host ; This template inherits other values from the generic-host template
  4. check_period 24x7 ; By default, Linux hosts are checked round the clock
  5. check_interval 5 ; Actively check the host every 5 minutes
  6. retry_interval 1 ; Schedule host check retries at 1 minute intervals
  7. max_check_attempts 10 ; Check each Linux host 10 times (max)
  8. check_command check-host-alive ; Default command to check Linux hosts
  9. notification_period 24x7
  10. ; Note that the notification_period variable is being overridden from
  11. ; the value that is inherited from the generic-host template!
  12. notification_interval 15
  13. notification_options d,u,r ; Only send notifications for specific host states
  14. contact_groups ops
  15. register 0 ; DONT REGISTER THIS DEFINITION - ITS NOT A REAL HOST, JUST A TEMPLATE!
  16. }
  17. # Generic service definition template - This is NOT a real service, just a template!
  18. define service{
  19. name generic-service ; The 'name' of this service template
  20. active_checks_enabled 1 ; Active service checks are enabled
  21. passive_checks_enabled 1 ; Passive service checks are enabled/accepted
  22. parallelize_check 1 ; Active service checks should be parallelized (disabling this can lead to major performance problems)
  23. obsess_over_service 1 ; We should obsess over this service (if necessary)
  24. check_freshness 0 ; Default is to NOT check service 'freshness'
  25. notifications_enabled 1 ; Service notifications are enabled
  26. event_handler_enabled 1 ; Service event handler is enabled
  27. flap_detection_enabled 1 ; Flap detection is enabled
  28. process_perf_data 1 ; Process performance data
  29. retain_status_information 1 ; Retain status information across program restarts
  30. retain_nonstatus_information 1 ; Retain non-status information across program restarts
  31. is_volatile 0 ; The service is not volatile
  32. check_period 24x7 ; The service can be checked at any time of the day
  33. max_check_attempts 3 ; Re-check the service up to 3 times in order to determine its final (hard) state
  34. check_interval 5 ; Check the service every 10 minutes under normal conditions
  35. retry_interval 2 ; Re-check the service every two minutes until a hard state can be determined
  36. contact_groups ops ; Notifications get sent out to everyone in the 'ops' group
  37. notification_options w,u,c,r ; Send notifications about warning, unknown, critical, and recovery events
  38. notification_interval 15 ; Re-notify about service problems every hour
  39. notification_period 24x7 ; Notifications can be sent out at any time
  40. register 0 ; DONT REGISTER THIS DEFINITION - ITS NOT A REAL SERVICE, JUST A TEMPLATE!
  41. }

Add host

  • cd /usr/local/nagios/etc/objects
  • vim hosts.cfg
  1. define host{
  2. use linux-server
  3. host_name linux-server-159
  4. alias 192.168.1.159
  5. address 192.168.1.159
  6. contact_groups ops
  7. }
  8. #定义一个主机组
  9. define hostgroup{
  10. hostgroup_name monitor-servers
  11. alias monitor servers
  12. members linux-server-159
  13. }

Add Service

  • cd /usr/local/nagios/etc/objects
  • vim services.cfg
  1. # Define a service to "check-host-alive" the local machine
  2. define service{
  3. use generic-service
  4. host_name linux-server-159
  5. service_description check-host-alive
  6. check_command check-host-alive
  7. }
  8. # Define a service to "ping" the local machine
  9. define service{
  10. use generic-service
  11. host_name linux-server-159
  12. service_description PING
  13. check_command check_ping!100.0,20%!500.0,60%
  14. }
  15. # Define a service to check the disk space of the root partition
  16. # on the local machine. Warning if < 20% free, critical if
  17. # < 10% free space on partition.
  18. define service{
  19. use generic-service ; Name of service template to use
  20. host_name linux-server-159
  21. service_description Root Partition
  22. check_command check_local_disk!20%!10%!/
  23. }

Check and restart service

  • /usr/local/nagios/bin/nagios checkconfig
  • checkconfig no error, then /usr/local/nagios/bin/nagios restart
添加新批注
在作者公开此批注前,只有你和作者可见。
回复批注