@saltyang
2017-05-26T03:01:58.000000Z
字数 4312
阅读 696
Nagios SMS
cd /usr/local/nagios/etc/objectsvim contacts.cfg to add the contact user who is notified
define contact{contact_name opsuseruse generic-contactalias opsuserservice_notification_period 24x7host_notification_period 24x7service_notification_options w,u,c,rhost_notification_options d,uservice_notification_commands notify-service-by-smshost_notification_commands notify-host-by-smspager 13151572201}define contactgroup{contactgroup_name opsalias opsmembers opsuser}
cd /usr/local/nagios/etc/objectsvim commands.cfg to add sms command
# 'notify-host-by-sms' command definitiondefine command{command_name notify-host-by-smscommand_line /usr/local/bin/sendsms.pl $CONTACTPAGER$ "*** $NOTIFICATIONTYPE$ Host Alert: $HOSTNAME$ IP: $HOSTADDRESS$ is $HOSTSTATE$ ***"}# 'notify-service-by-sms' command definitiondefine command{command_name notify-service-by-smscommand_line /usr/local/bin/sendsms.pl $CONTACTPAGER$ "*** $NOTIFICATIONTYPE$ Service Alert: $HOSTNAME$ IP: $HOSTADDRESS$ / $SERVICEDESC$ is $SERVICESTATE$ ***"}
cd /usr/local/nagios/etc/objectsvim templates.cfg
define host{name linux-server ; The name of this host templateuse generic-host ; This template inherits other values from the generic-host templatecheck_period 24x7 ; By default, Linux hosts are checked round the clockcheck_interval 5 ; Actively check the host every 5 minutesretry_interval 1 ; Schedule host check retries at 1 minute intervalsmax_check_attempts 10 ; Check each Linux host 10 times (max)check_command check-host-alive ; Default command to check Linux hostsnotification_period 24x7; Note that the notification_period variable is being overridden from; the value that is inherited from the generic-host template!notification_interval 15notification_options d,u,r ; Only send notifications for specific host statescontact_groups opsregister 0 ; DONT REGISTER THIS DEFINITION - ITS NOT A REAL HOST, JUST A TEMPLATE!}# Generic service definition template - This is NOT a real service, just a template!define service{name generic-service ; The 'name' of this service templateactive_checks_enabled 1 ; Active service checks are enabledpassive_checks_enabled 1 ; Passive service checks are enabled/acceptedparallelize_check 1 ; Active service checks should be parallelized (disabling this can lead to major performance problems)obsess_over_service 1 ; We should obsess over this service (if necessary)check_freshness 0 ; Default is to NOT check service 'freshness'notifications_enabled 1 ; Service notifications are enabledevent_handler_enabled 1 ; Service event handler is enabledflap_detection_enabled 1 ; Flap detection is enabledprocess_perf_data 1 ; Process performance dataretain_status_information 1 ; Retain status information across program restartsretain_nonstatus_information 1 ; Retain non-status information across program restartsis_volatile 0 ; The service is not volatilecheck_period 24x7 ; The service can be checked at any time of the daymax_check_attempts 3 ; Re-check the service up to 3 times in order to determine its final (hard) statecheck_interval 5 ; Check the service every 10 minutes under normal conditionsretry_interval 2 ; Re-check the service every two minutes until a hard state can be determinedcontact_groups ops ; Notifications get sent out to everyone in the 'ops' groupnotification_options w,u,c,r ; Send notifications about warning, unknown, critical, and recovery eventsnotification_interval 15 ; Re-notify about service problems every hournotification_period 24x7 ; Notifications can be sent out at any timeregister 0 ; DONT REGISTER THIS DEFINITION - ITS NOT A REAL SERVICE, JUST A TEMPLATE!}
cd /usr/local/nagios/etc/objectsvim hosts.cfg
define host{use linux-serverhost_name linux-server-159alias 192.168.1.159address 192.168.1.159contact_groups ops}#定义一个主机组define hostgroup{hostgroup_name monitor-serversalias monitor serversmembers linux-server-159}
cd /usr/local/nagios/etc/objectsvim services.cfg
# Define a service to "check-host-alive" the local machinedefine service{use generic-servicehost_name linux-server-159service_description check-host-alivecheck_command check-host-alive}# Define a service to "ping" the local machinedefine service{use generic-servicehost_name linux-server-159service_description PINGcheck_command check_ping!100.0,20%!500.0,60%}# Define a service to check the disk space of the root partition# on the local machine. Warning if < 20% free, critical if# < 10% free space on partition.define service{use generic-service ; Name of service template to usehost_name linux-server-159service_description Root Partitioncheck_command check_local_disk!20%!10%!/}
/usr/local/nagios/bin/nagios checkconfig- checkconfig no error, then
/usr/local/nagios/bin/nagios restart