Код: Выделить всё
[srv:/usr/ports]#make search name=nagios
Port: nagios-2.5
Path: /usr/ports/net-mgmt/nagios
Info: Extremely powerful network monitoring system
cat >> /etc/rc.conf
nagios_enable="YES"
Ctrl+<D>
Предполагается,что,веб-сервер apache уже поставлен.Если нет- ставим и запускаем.Если по-простому,то ничего конфигурить не надо.
в /usr/local/etc/apache21/httpd.conf после
Код: Выделить всё
<Directory />
AllowOverride None
Order deny,allow
Deny from all
</Directory>
Код: Выделить всё
ScriptAlias /nagios/cgi-bin /usr/local/www/nagios/cgi-bin/
<Directory "/usr/local/www/nagios">
Options ExecCGI
AllowOverride None
Order allow,deny
Allow from all
AuthName "Nagios Access"
AuthType Basic
AuthUserFile /usr/local/etc/nagios/htpasswd.users
Require valid-user
</Directory>
Alias /nagios /usr/local/www/nagios/
<Directory "/usr/local/www/nagios/cgi-bin">
Options None
AllowOverride None
Order allow,deny
Allow from all
AuthName "Nagios Access"
AuthType Basic
AuthUserFile /usr/local/etc/nagios/htpasswd.users
Require valid-user
</Directory>
Код: Выделить всё
#/usr/local/sbin/htpasswd -c /usr/local/etc/nagios/htpasswd.users nagios
#/usr/local/sbin/htpasswd /usr/local/etc/nagios/htpasswd.users boss
Тепери можно зайти на http://<IP-сервака>/nagios/ ,авторизоваться и полюбоваться интерфейсом.
Конфигурационные файлы нагиос, на мой взгляд, сделаны не самым лучшим образом и их имена могут меняться от версии к версии. Например, описание всех серверов и их сервисов в одном файле я считаю не самым лучшим вариантом, поэтому у меня на каждый сервер – свой файл (проще искать и править, если что-то не так). К счастью, Nagios позволяет менять структуру конфигов.
И так, в папке /usr/local/etc/nagios/ у меня находятся следующие файлы:
cgi.cfg - этот файл в основном содержит разграничение прав доступа к системе через веб. я его не почти не трогал. просто создал пользователей, как там. nagios-пользователь, под которым заходит админ, boss - все остальные. Эти пользователи не системные, так что поменять их потом не составит труда. так же задаются звуки, которые проигрываются в браузере в результате события.
default.cfg - в этот файл я собрал стандартные для всех серверов параметры - объявление периодов времени, группы, контакты и шаблоны
htpasswd.users - этот файлик мы потом создадим для паролей
resource.cfg - я его не трогал. В стандартном варианте он содержит пути к компонентам (1 путь)
commands.cfg - файл, в котором описаны команды вызова модулей и оповещений. При добавлении нового модуля его надо прописывать именно туда.
hosts - папка, в которой лежат описания хостов
nagios.cfg - основной конфигурационный файл. Его переименовывать нельзя
sample - папка. Туда я скинул дефолтовые файлы конфигурации
Итак, файлы. Подробно расписывать просто нет времени, но там коментов хватает и так. В основном, все понятно
cgi.cfg:
Код: Выделить всё
main_config_file=/usr/local/etc/nagios/nagios.cfg
# Путь к www файлам
physical_html_path=/usr/local/www/nagios
# то,что добавляем в браузере после имени сервера
url_html_path=/nagios
show_context_help=1
use_authentication=1
default_user_name=guest
# Раздаем права
authorized_for_system_information=nagios,boss
authorized_for_configuration_information=nagios,boss
authorized_for_system_commands=nagios
authorized_for_all_services=nagios,guest,boss
authorized_for_all_hosts=nagios,guest,boss
authorized_for_all_service_commands=nagios
authorized_for_all_host_commands=nagios
default_statusmap_layout=5
default_statuswrl_layout=4
ping_syntax=/bin/ping -n -U -c 5 $HOSTADDRESS$
refresh_rate=45
# Назначаем звуки. Должни находиться в папке /usr/local/www/nagios/sound
host_unreachable_sound=hostdown.wav
host_down_sound=hostdown.wav
service_critical_sound=critical.wav
service_warning_sound=warning.wav
service_unknown_sound=warning.wav
normal_sound=noproblem.wav
default.cfg
Код: Выделить всё
#Задаем периоды оповещения
define timeperiod{
timeperiod_name 24x7
alias 24 Hours A Day, 7 Days A Week
sunday 00:00-24:00
monday 00:00-24:00
tuesday 00:00-24:00
wednesday 00:00-24:00
thursday 00:00-24:00
friday 00:00-24:00
saturday 00:00-24:00
}
define timeperiod{
timeperiod_name workhours
alias "Normal" Working Hours
monday 09:00-17:00
tuesday 09:00-17:00
wednesday 09:00-17:00
thursday 09:00-17:00
friday 09:00-17:00
}
define timeperiod{
timeperiod_name nonworkhours
alias Non-Work Hours
sunday 00:00-24:00
monday 00:00-09:00,17:00-24:00
tuesday 00:00-09:00,17:00-24:00
wednesday 00:00-09:00,17:00-24:00
thursday 00:00-09:00,17:00-24:00
friday 00:00-09:00,17:00-24:00
saturday 00:00-24:00
}
define timeperiod{
timeperiod_name none
alias No Time Is A Good Time
}
# Определяем контакты для оповещений, время оповещения(шоб ночью не будил)
# и события, при которых трезвонить
define contact{
contact_name nagios-admin
alias Nagios Admin
service_notification_period 24x7
host_notification_period 24x7
service_notification_options w,u,c,r
host_notification_options d,r
service_notification_commands notify-by-email
host_notification_commands host-notify-by-email
email sav@russvet.ru
}
# Создаем группу контактов. Для каждого сервера можно оповещать
# Свою группу
define contactgroup{
contactgroup_name admins
alias Nagios Administrators
members nagios-admin
}
# Стандартные шаблоны хостов
define host{
name generic-host ; The name of this host template
notifications_enabled 1 ; Host notifications are enabled
event_handler_enabled 1 ; Host event handler is enabled
flap_detection_enabled 1 ; Flap detection is enabled
failure_prediction_enabled 1 ; Failure prediction 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
notification_period 24x7 ; Send host notifications at any time
register 0 ; DONT REGISTER THIS DEFINITION
}
define host{
name freebsd-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, FreeBSD hosts are checked round the clock
max_check_attempts 10 ; Check each FreeBSD host 10 times (max)
check_command check-host-alive ; Default command to check FreeBSD hosts
notification_period 24x7 ; FreeBSD admins hate to be woken up, so we only notify during the day
; Note that the notification_period variable is being overridden from
; the value that is inherited from the generic-host template!
notification_interval 30 ; Resend notification every 2 hours
notification_options d,u,r ; Only send notifications for specific host states
contact_groups admins ; Notifications get sent to the admins by default
register 0 ; DONT REGISTER THIS DEFINITION
}
# Группы хостов
define hostgroup{
hostgroup_name in_servers
alias Local Servers
members localhost, in.ns.lpower.ru, in.ns.russvet.ru
}
define hostgroup{
hostgroup_name out_servers
alias External Servers
members out.ns.lpower.ru, out.ns.russvet.ru
}
define hostgroup{
hostgroup_name DB_servers
alias DataBase Servers
members rusmail, ntload
}
# Стандартные шаблоны сервисов
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
obsess_over_service 1 ; We should obsess over this service
check_freshness 0 ; Default is to NOT check service
notifications_enabled 1 ; Service notifications are enabled
event_handler_enabled 1 ; Service event handler is enabled
flap_detection_enabled 1 ; Flap detection is enabled
failure_prediction_enabled 1 ; Failure prediction 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
register 0 ; DONT REGISTER THIS DEFINITION
}
define service{
name local-service ; The name of this service template
use generic-service ; Inherit default values from the generic
check_period 24x7 ; The service can be checked at any time
max_check_attempts 4 ; Re-check the service up to 4 times
normal_check_interval 5 ; Check the service every 5 minutes under normal conditions
retry_check_interval 1 ; Re-check the service every minute until a hard state can be determined
contact_groups admins ; Notifications get sent out to everyone in the 'admins' group
notification_options w,u,c,r ; Send notifications about warning, unknown, critical, and recovery events
notification_interval 60 ; Re-notify about service problems every hour
notification_period 24x7 ; Notifications can be sent out at any time
register 0 ; DONT REGISTER THIS DEFINITION
}
Код: Выделить всё
define command{
command_name check_local_disk
command_line $USER1$/check_disk -w $ARG1$ -c $ARG2$ -p $ARG3$
}
«command_line $USER1$/check_disk -w $ARG1$ -c $ARG2$ -p $ARG3$» - как будем вызывать.$USER1$ - содержит /usr/local/libexec/nagios/, т.е. вызываем /usr/local/libexec/nagios/check_disk. далее передаем аргументы.чтобы узнать,какие ключи использует компонент, набираем /usr/local/libexec/nagios/check_disk -h. Так надо описать каждый компонент,который будем использовать.Изначально описан минимум,в /usr/local/libexec/nagios их больше
Если в файле хостов пишем «check_local_disk!1!2!3», то в итоге будет вызвано «/usr/local/libexec/nagios/check_disk -w 1 -c 2 -p 3»
nagios.cfg:
тут я только добавил инклуды моих файлов:
Код: Выделить всё
# Host and service definitions for monitoring this machine
cfg_file=/usr/local/etc/nagios/default.cfg
cfg_file=/usr/local/etc/nagios/hosts/localhost.host
#cfg_file=/usr/local/etc/nagios/hosts/server.host
server.host:
Код: Выделить всё
define host{
use freebsd-server ; Name of host template to use
host_name localhost
alias localhost
address 192.168.93.220
}
define service{
use local-service ; Name of service template to use
host_name localhost
service_description PING
check_command check_ping!100.0,20%!500.0,60%
}
define service{
use local-service ; Name of service template to use
host_name localhost
service_description Root Partition
check_command check_local_disk!20%!10%!/
}
define service{
use local-service ; Name of service template to use
host_name localhost
service_description Current Users
check_command check_local_users!20!50
}
define service{
use local-service ; Name of service template to use
host_name localhost
service_description Total Processes
check_command check_local_procs!250!400!RSZDT
}
define service{
use local-service ; Name of service template to use
host_name localhost
service_description Current Load
check_command check_local_load!5.0,4.0,3.0!10.0,6.0,4.0
}
define service{
use local-service ; Name of service template to use
host_name localhost
service_description ntp service
check_command check_ntp
}
define service{
use local-service ; Name of service template to use
host_name localhost
service_description dns service
check_command check_dns
}
define service{
use local-service ; Name of service template to use
host_name localhost
service_description ftp service
check_command check_ftp
}
define service{
use local-service ; Name of service template to use
host_name localhost
service_description ssh service
check_command check_ssh!30
}
define service{
use local-service ; Name of service template to use
host_name localhost
service_description mailqu service
check_command check_mailq!1!3
}
use local-service - используемый шаблон
host_name localhost - имя хоста,для кот выполняем проверку
service_description mailqu service - описание проверки
check_command check_mailq!1!3 - команда проверки и ее параметры
Вот,впринципе, и все. Писал уже с настроенного сервака,так что могут быть неточности....
Написано довольно криво-сам знаю,но на лучшее просто нету времени..Если кого реально заинтересует-напишу более подробно