Как-то работая у одного провайдера локальных сетей, стал вопрос о круглосуточном слежении за сетью.

Вариантов реализации данного вопроса в принципе не мало, от самописных скриптов, до отправки SMSок теми же скриптами.
Но зачем изобретать велосипед, если уже есть такая система, которая вполне выполняет свою роль. Следит, шлет на почту отчеты о проблеме и восстановлении её, можно прикрутить к жаберу, аське и телефону с которого можно слать СМС. Также в любое время можно поднять и просмотреть логи через веб-интерфейс, в общем не программа, а сказка..

Итак, установка и настройка nagios:


# cd /usr/ports/net-mgmt/nagios
# make install clean
# cd /usr/ports/net-mgmt/nagios-plugins/
# make install clean
# echo 'nagios_enable="YES"' >> /etc/rc.conf
# cd /usr/local/etc/nagios
# ls /usr/local/etc/nagios/objects/*sample
/usr/local/etc/nagios/objects/commands.cfg-sample
/usr/local/etc/nagios/objects/contacts.cfg-sample
/usr/local/etc/nagios/objects/localhost.cfg-sample
/usr/local/etc/nagios/objects/printer.cfg-sample
/usr/local/etc/nagios/objects/switch.cfg-sample
/usr/local/etc/nagios/objects/templates.cfg-sample
/usr/local/etc/nagios/objects/timeperiods.cfg-sample
........
# cd /usr/local/etc/nagios/objects/
# cp commands.cfg-sample commands.cfg
# cp contacts.cfg-sample contacts.cfg
# cp hostgroups.cfg
# cp hosts.cfg
# cp services.cfg
# cp timeperiods.cfg-sample timeperiods.cfg
..............
# ls /usr/local/etc/nagios/*sample
/usr/local/etc/nagios/cgi.cfg-sample
/usr/local/etc/nagios/resource.cfg-sample
/usr/local/etc/nagios/nagios.cfg-sample
# cd /usr/local/etc/nagios/
# cp nagios.cfg-sample nagios.cfg
# cp cgi.cfg-sample cgi.cfg
# cp resource.cfg-sample resource.cfg

Первым делом, правим файл cgi.cfg -раздавая права пользователям, для управления nagios через вебинтерфейс:

main_config_file=/usr/local/etc/nagios/nagios.cfg
physical_html_path=/usr/local/www/nagios
url_html_path=/nagios
show_context_help=0
use_pending_states=1
use_authentication=1
use_ssl_authentication=0
authorized_for_system_information=admin,guest,andrey
authorized_for_configuration_information=admin,andrey
authorized_for_system_commands=admin,andrey
authorized_for_all_services=admin,guest,andrey
authorized_for_all_hosts=admin,guest,andrey
authorized_for_all_service_commands=admin,guest,andrey
authorized_for_all_host_commands=admin,guest,andrey
default_statusmap_layout=5
default_statuswrl_layout=4
ping_syntax=/sbin/ping -n -c 5 $HOSTADDRESS$
refresh_rate=10
escape_html_tags=1
action_url_target=_blank
notes_url_target=_blank
lock_author_names=1

Потом, файл nagios.cfg:

log_file=/var/spool/nagios/nagios.log
cfg_file=/usr/local/etc/nagios/objects/commands.cfg
cfg_file=/usr/local/etc/nagios/objects/contacts.cfg
cfg_file=/usr/local/etc/nagios/objects/timeperiods.cfg
cfg_file=/usr/local/etc/nagios/objects/hosts.cfg
cfg_file=/usr/local/etc/nagios/objects/services.cfg
cfg_file=/usr/local/etc/nagios/objects/hostgroups.cfg
object_cache_file=/var/spool/nagios/objects.cache
precached_object_file=/var/spool/nagios/objects.precache
resource_file=/usr/local/etc/nagios/resource.cfg
status_file=/var/spool/nagios/status.dat
status_update_interval=10
nagios_user=nagios
nagios_group=nagios
check_external_commands=1
command_check_interval=-1
command_file=/var/spool/nagios/rw/nagios.cmd
external_command_buffer_slots=4096
lock_file=/var/spool/nagios/nagios.lock
temp_file=/var/spool/nagios/nagios.tmp
temp_path=/tmp
event_broker_options=-1
log_rotation_method=d
log_archive_path=/var/spool/nagios/archives
use_syslog=1
log_notifications=1
log_service_retries=1
log_host_retries=1
log_event_handlers=1
log_initial_states=0
log_external_commands=1
log_passive_checks=1
service_inter_check_delay_method=s
max_service_check_spread=30
service_interleave_factor=s
host_inter_check_delay_method=s
max_host_check_spread=30
max_concurrent_checks=0
check_result_reaper_frequency=10
max_check_result_reaper_time=30
check_result_path=/var/spool/nagios/checkresults
max_check_result_file_age=3600
cached_host_check_horizon=15
cached_service_check_horizon=15
enable_predictive_host_dependency_checks=1
enable_predictive_service_dependency_checks=1
soft_state_dependencies=0
auto_reschedule_checks=0
auto_rescheduling_interval=30
auto_rescheduling_window=180
sleep_time=0.25
service_check_timeout=60
host_check_timeout=30
event_handler_timeout=30
notification_timeout=30
ocsp_timeout=5
perfdata_timeout=5
retain_state_information=1
state_retention_file=/var/spool/nagios/retention.dat
retention_update_interval=60
use_retained_program_state=1
use_retained_scheduling_info=1
retained_host_attribute_mask=0
retained_service_attribute_mask=0
retained_process_host_attribute_mask=0
retained_process_service_attribute_mask=0
retained_contact_host_attribute_mask=0
retained_contact_service_attribute_mask=0
interval_length=60
use_aggressive_host_checking=0
execute_service_checks=1
accept_passive_service_checks=1
execute_host_checks=1
accept_passive_host_checks=1
enable_notifications=1
enable_event_handlers=1
process_performance_data=0
obsess_over_services=0
obsess_over_hosts=0
translate_passive_host_checks=0
passive_host_checks_are_soft=0
check_for_orphaned_services=1
check_for_orphaned_hosts=1
check_service_freshness=1
service_freshness_check_interval=60
check_host_freshness=0
host_freshness_check_interval=60
additional_freshness_latency=15
enable_flap_detection=1
low_service_flap_threshold=5.0
high_service_flap_threshold=20.0
low_host_flap_threshold=5.0
high_host_flap_threshold=20.0
date_format=euro
p1_file=/usr/local/bin/p1.pl
enable_embedded_perl=1
use_embedded_perl_implicitly=1
illegal_object_name_chars=`~!$%^&*|'"<>?,()=
illegal_macro_output_chars=`~$&|'"<>
use_regexp_matching=0
use_true_regexp_matching=0
admin_email=nagios
admin_pager=pagenagios
daemon_dumps_core=0
use_large_installation_tweaks=0
enable_environment_macros=1
debug_level=0
debug_verbosity=1
debug_file=/var/spool/nagios/nagios.debug
max_debug_file_size=1000000

resource.cfg:

$USER1$=/usr/local/libexec/nagios

Далее..

# cd objects

после чего составляем файлы hosts.cfg и hostgroups.cfg:


# cat hosts.cfg
define host{
name generic-host
notifications_enabled 1
event_handler_enabled 1
flap_detection_enabled 1
failure_prediction_enabled 1
process_perf_data 1
retain_status_information 1
retain_nonstatus_information 1
notification_period 24x7
register 0
}
.................
define host{
use generic-host
host_name mail
alias Mail Server
address mail.domain.ua
check_command check-host-alive
max_check_attempts 10
notification_interval 120
notification_period 24x7
notification_options d,u,r
}
...........
define host{
use generic-host
host_name ftp
alias FTP Server
address 10.10.1.253
check_command check-host-alive
max_check_attempts 10
notification_interval 120
notification_period 24x7
notification_options d,u,r
}

Таким образом описываем остальные сервера, свичи, роутеры, и т.д.


# cat hostgroups.cfg
define hostgroup{
hostgroup_name servers
alias Servers
members ftp, mail
}

И ещё два файла осталось, файл контактов contacts.cfg:


# cat contacts.cfg
define contact{
name generic-contact ; The name of this contact template
service_notification_period 24x7 ; service notifications can be sent anytime
host_notification_period 24x7 ; host notifications can be sent anytime
service_notification_options w,u,c,r,f,s ; send notifications for all service states, flapping events, and scheduled downtime events
host_notification_options d,u,r,f,s ; send notifications for all host states, flapping events, and scheduled downtime events
service_notification_commands notify-service-by-email ; send service notifications via email
host_notification_commands notify-host-by-email ; send host notifications via email
register 0 ; DONT REGISTER THIS DEFINITION - ITS NOT A REAL CONTACT, JUST A TEMPLATE!
}
define contact{
contact_name admin ; Short name of user
use generic-contact ; Inherit default values from generic-contact template (defined above)
alias Admin ; Full name of user
email admin@domain.ua ; <<***** CHANGE THIS TO YOUR EMAIL ADDRESS ****** } define contact{ contact_name reports ; Short name of user use generic-contact ; Inherit default values from generic-contact template (defined above) alias Reports for Admins ; Full name of user email nagios@domain.ua ; <<***** CHANGE THIS TO YOUR EMAIL ADDRESS ****** } define contactgroup{ contactgroup_name admins alias Admins members reports,admin }

и файл сервисов services.cfg:


define service{
name generic-service
active_checks_enabled 1
passive_checks_enabled 1
parallelize_check 1
obsess_over_service 0
check_freshness 0
notifications_enabled 1
event_handler_enabled 1
flap_detection_enabled 1
failure_prediction_enabled 1
process_perf_data 1
retain_status_information 1
retain_nonstatus_information 1
is_volatile 0
check_period 24x7
max_check_attempts 3
normal_check_interval 10
retry_check_interval 2
contact_groups admins
notification_options w,u,c,r
notification_interval 60
notification_period 24x7
register 0
}
define service{
name local-service ; The name of this service template
use generic-service ; Inherit default values from the generic-service definition
max_check_attempts 4 ; Re-check the service up to 4 times in order to determine its final (hard) state
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
register 0 ; DONT REGISTER THIS DEFINITION - ITS NOT A REAL SERVICE, JUST A TEMPLATE!
}
define service{
use generic-service
host_name www
service_description HTTP
is_volatile 0
check_period 24x7
normal_check_interval 5
retry_check_interval 1
contact_groups admins
notification_interval 120
notification_period 24x7
notification_options w,u,c,r
check_command check_http
}
define service{
use generic-service
host_name www
service_description PING
is_volatile 0
check_period 24x7
max_check_attempts 3
normal_check_interval 5
retry_check_interval 1
contact_groups admins
notification_interval 120
notification_period 24x7
notification_options w,u,c,r
check_command check_ping!100.0,20%!500.0,60%
}
define service{
use generic-service
host_name mail
service_description SMTP
is_volatile 0
check_period 24x7
max_check_attempts 3
normal_check_interval 5
retry_check_interval 1
contact_groups admins
notification_interval 120
notification_period 24x7
notification_options w,u,c,r
check_command check_smtp
}

Ну, теперь осталось добавить путь в apache и запустить сам nagios.


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
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
Require valid-user
</Directory>

Добавляем пользователей и делаем им пароли:

# /usr/local/sbin/htpasswd -c /usr/local/etc/nagios/htpasswd admin
# /usr/local/sbin/htpasswd /usr/local/etc/nagios/htpasswd andrey
# /usr/local/sbin/htpasswd /usr/local/etc/nagios/htpasswd guest
# sh /usr/local/etc/rc.d/nagios start

Теперь можно заходить на http://ваш.домен/nagios
На запрос логина и пароля, ввводим данные и получаем картинку 🙂

Напоминаю всем копирующим мой контент о существовании закона "Об авторском праве".
В связи с этим, прошу во избежании конфликтов при копировании данного материала, ставить на него ссылку:

http://noted.org.ua/?p=894


Также, вы можете отблагодарить меня переслав любую сумму на любой кошелек WebMoney, для поддержания данного ресурса. Или просто админу на пиво ;)

Кошельки для получения благодарности:
R386985788805
U234140473141
Z147712360455

На данной странице нет комментариев, возможно они закрыты. Если Вы хотите оставить свой комментарий, перейдите на специально созданный раздел

Add your comment now

You must be logged in to post a comment.