Nagios — это приложение, предназначенное для выполнения мониторинга систем и сетей. Оно следит за назначенными приложениями и службами и генерирует оповещения в зависимости от поведения наблюдаемых служб. До какого-то времени проект был известен как NetSaint. В настоящий момент, хотя сайт NetSaint работает, дальнейшая разработка проекта продолжается под именем Nagios.
Nagios это рекурсивный акроним, расшифровывающийся как Nagios Ain’t Gonna Insist On Sainthood (Nagios не собирается настаивать на святости — намек на прежнее название проекта, NetSaint — сетевой святой)
Подключаем репозиторий Epel:
# rpm -Uvh http://dl.fedoraproject.org/pub/epel/5/i386/epel-release-5-4.noarch.rpm
Устанавливаем Nagios
# yum -y install nagios nagios-plugins-all
Устанавливаем Nagios в автозагрузку
# chkconfig nagios on
Устанавливаем httpd в автозагрузку
# chkconfig httpd on
Разрешаем доступ:
# cat /etc/httpd/conf.d/nagios.conf ScriptAlias /nagios/cgi-bin/ /usr/lib/nagios/cgi-bin/ Options ExecCGI order deny,allow deny from all allow from all AuthType Basic AuthUserFile /etc/nagios/passwd AuthName "nagios" require valid-user Alias /nagios/ /usr/share/nagios/html/ Options None order deny,allow deny from all allow from all AuthType Basic AuthUserFile /etc/nagios/passwd AuthName "nagios" require valid-user
Устанавливаем пароль для пользователя nagiosadmin
# htpasswd -c /etc/nagios/passwd nagiosadmin
Снимаем # в файле /etc/nagios/cgi.cfg
# grep -v -E "#|^$" cgi.cfg main_config_file=/etc/nagios/nagios.cfg physical_html_path=/usr/share/nagios/share url_html_path=/nagios show_context_help=0 use_authentication=1 authorized_for_system_information=nagiosadmin authorized_for_configuration_information=nagiosadmin authorized_for_system_commands=nagiosadmin authorized_for_all_services=nagiosadmin authorized_for_all_hosts=nagiosadmin authorized_for_all_service_commands=nagiosadmin authorized_for_all_host_commands=nagiosadmin default_statusmap_layout=5 default_statuswrl_layout=4 ping_syntax=/bin/ping -n -U -c 5 $HOSTADDRESS$ refresh_rate=90
Запускае nagios
# service nagios start
После всех стартовых манипуляций получаем мониторинг http://localhost/nagios/

Добавим тестовый Host на котором будем мониторить различные сервисы:
# mkdir /etc/nagios/hosts # touch test.cfg # cat test.cfg
# Host Definition
define host{
# Name of host template to use
use generic-host
host_name TEST
address 192.168.0.105
check_command check-host-alive
contact_groups admins
max_check_attempts 10
notification_interval 120
notification_period 24x7
notification_options d,u,r
}
# Service definition
define service{
# Name of service template to use
use generic-service
host_name TEST
service_description PING
is_volatile 0
check_period 24x7
max_check_attempts 3
normal_check_interval 1
retry_check_interval 1
#contact_groups admins
notification_interval 120
notification_period 24x7
notification_options c,r
check_command check_ping!250.0,20%!500.0,60%
}
Пропишем в /etc/nagios/nagios.cfg
cfg_file=/etc/nagios/hosts/test.cfg
Проверяем не допустили ли мы ошибок:
# nagios -v /etc/nagios/nagios.cfg Things look okay - No serious problems were detected during the pre-flight check
Перезагружаем nagios
# service nagios restart
Теперь будем добавлять мониторинг сервисов:
# Service definition HTTP
define service{
# Name of service template to use
use generic-service
host_name TEST
service_description HTTP
is_volatile 0
check_period 24x7
max_check_attempts 3
normal_check_interval 1
retry_check_interval 1
#contact_groups admins
notification_interval 120
notification_period 24x7
notification_options c,r
check_command check_http
}
# Service definition FTP
define service{
# Name of service template to use
use generic-service
host_name TEST
service_description FTP
is_volatile 0
check_period 24x7
max_check_attempts 3
normal_check_interval 1
retry_check_interval 1
#contact_groups admins
notification_interval 120
notification_period 24x7
notification_options c,r
check_command check_ftp
}
# Service definition POP3
define service{
# Name of service template to use
use generic-service
host_name TEST
service_description POP3
is_volatile 0
check_period 24x7
max_check_attempts 3
normal_check_interval 1
retry_check_interval 1
#contact_groups admins
notification_interval 120
notification_period 24x7
notification_options c,r
check_command check_pop
}
# Service definition SMTP
define service{
# Name of service template to use
use generic-service
host_name TEST
service_description SMTP
is_volatile 0
check_period 24x7
max_check_attempts 3
normal_check_interval 1
retry_check_interval 1
#contact_groups admins
notification_interval 120
notification_period 24x7
notification_options c,r
check_command check_smtp
}
Мониторинг сервисов с помощью NRPE

Подключаем репозиторий rpmforge
rpm -Uhv http://apt.sw.be/redhat/el5/en/i386/rpmforge/RPMS/rpmforge-release-0.3.6-1.el5.rf.i386.rpm
Устанавливаем nrpe
# yum -y install nagios-nrpe nagios-plugins-nrpe
В файле /etc/nagios/objects/commands.cfg описываем check_nrpe
define command{
command_name check_nrpe
command_line $USER1$/check_nrpe -H $HOSTADDRESS$ -c $ARG1$
}
В файле /etc/nagios/nrpe.cfg разрешаем доступ только с определенных ip
allowed_hosts=127.0.0.1,192.168.0.104
Мониторинг нагрузки LA
# Service definition
define service{
# Name of service template to use
use generic-service
host_name TEST
service_description LA
is_volatile 0
check_period 24x7
max_check_attempts 3
normal_check_interval 1
retry_check_interval 1
#contact_groups admins
notification_interval 120
notification_period 24x7
notification_options c,r
check_command check_nrpe!check_load
}
На тестовом сервере в файле /etc/nagios/nrpe.cfg
command[check_load]=/usr/lib/nagios/plugins/check_load -w 15,10,5 -c 30,25,20
Мониторинг дискового пространства
# Service definition
define service{
# Name of service template to use
use generic-service
host_name TEST
service_description DISK
is_volatile 0
check_period 24x7
max_check_attempts 3
normal_check_interval 1
retry_check_interval 1
#contact_groups admins
notification_interval 120
notification_period 24x7
notification_options c,r
check_command check_nrpe!check_disk
}
На тестовом сервере в файле /etc/nagios/nrpe.cfg
command[check_disk]=/usr/lib/nagios/plugins/check_disk -w 10% -v 5% -p / -p /boot
Мониторинг SWAP
# Service definition
define service{
# Name of service template to use
use generic-service
host_name TEST
service_description swap
is_volatile 0
check_period 24x7
max_check_attempts 3
normal_check_interval 1
retry_check_interval 1
#contact_groups admins
notification_interval 120
notification_period 24x7
notification_options c,r
check_command check_nrpe!check_swap
}
На тестовом сервере в файле /etc/nagios/nrpe.cfg
command[check_swap]=/usr/lib/nagios/plugins/check_swap -w 10% -c 5%
Перезагружаем nrpe
# service nrpe restart
Добавляем сервис nrpe в автозагрузку
# chkconfig nrpe on
Результат
