@saltyang
2017-05-26T11:01:58.000000Z
字数 4312
阅读 590
Nagios
SMS
cd /usr/local/nagios/etc/objects
vim contacts.cfg
to add the contact user who is notified
define contact{
contact_name opsuser
use generic-contact
alias opsuser
service_notification_period 24x7
host_notification_period 24x7
service_notification_options w,u,c,r
host_notification_options d,u
service_notification_commands notify-service-by-sms
host_notification_commands notify-host-by-sms
pager 13151572201
}
define contactgroup{
contactgroup_name ops
alias ops
members opsuser
}
cd /usr/local/nagios/etc/objects
vim commands.cfg
to add sms command
# 'notify-host-by-sms' command definition
define command{
command_name notify-host-by-sms
command_line /usr/local/bin/sendsms.pl $CONTACTPAGER$ "*** $NOTIFICATIONTYPE$ Host Alert: $HOSTNAME$ IP: $HOSTADDRESS$ is $HOSTSTATE$ ***"
}
# 'notify-service-by-sms' command definition
define command{
command_name notify-service-by-sms
command_line /usr/local/bin/sendsms.pl $CONTACTPAGER$ "*** $NOTIFICATIONTYPE$ Service Alert: $HOSTNAME$ IP: $HOSTADDRESS$ / $SERVICEDESC$ is $SERVICESTATE$ ***"
}
cd /usr/local/nagios/etc/objects
vim templates.cfg
define host{
name linux-server ; The name of this host template
use generic-host ; This template inherits other values from the generic-host template
check_period 24x7 ; By default, Linux hosts are checked round the clock
check_interval 5 ; Actively check the host every 5 minutes
retry_interval 1 ; Schedule host check retries at 1 minute intervals
max_check_attempts 10 ; Check each Linux host 10 times (max)
check_command check-host-alive ; Default command to check Linux hosts
notification_period 24x7
; Note that the notification_period variable is being overridden from
; the value that is inherited from the generic-host template!
notification_interval 15
notification_options d,u,r ; Only send notifications for specific host states
contact_groups ops
register 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 template
active_checks_enabled 1 ; Active service checks are enabled
passive_checks_enabled 1 ; Passive service checks are enabled/accepted
parallelize_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 enabled
event_handler_enabled 1 ; Service event handler is enabled
flap_detection_enabled 1 ; Flap detection is enabled
process_perf_data 1 ; Process performance data
retain_status_information 1 ; Retain status information across program restarts
retain_nonstatus_information 1 ; Retain non-status information across program restarts
is_volatile 0 ; The service is not volatile
check_period 24x7 ; The service can be checked at any time of the day
max_check_attempts 3 ; Re-check the service up to 3 times in order to determine its final (hard) state
check_interval 5 ; Check the service every 10 minutes under normal conditions
retry_interval 2 ; Re-check the service every two minutes until a hard state can be determined
contact_groups ops ; Notifications get sent out to everyone in the 'ops' group
notification_options w,u,c,r ; Send notifications about warning, unknown, critical, and recovery events
notification_interval 15 ; Re-notify about service problems every hour
notification_period 24x7 ; Notifications can be sent out at any time
register 0 ; DONT REGISTER THIS DEFINITION - ITS NOT A REAL SERVICE, JUST A TEMPLATE!
}
cd /usr/local/nagios/etc/objects
vim hosts.cfg
define host{
use linux-server
host_name linux-server-159
alias 192.168.1.159
address 192.168.1.159
contact_groups ops
}
#定义一个主机组
define hostgroup{
hostgroup_name monitor-servers
alias monitor servers
members linux-server-159
}
cd /usr/local/nagios/etc/objects
vim services.cfg
# Define a service to "check-host-alive" the local machine
define service{
use generic-service
host_name linux-server-159
service_description check-host-alive
check_command check-host-alive
}
# Define a service to "ping" the local machine
define service{
use generic-service
host_name linux-server-159
service_description PING
check_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 use
host_name linux-server-159
service_description Root Partition
check_command check_local_disk!20%!10%!/
}
/usr/local/nagios/bin/nagios checkconfig
- checkconfig no error, then
/usr/local/nagios/bin/nagios restart