Инструменты пользователя

Инструменты сайта


сервис_nagios

Сервис Nagios

Базовая конфигурация

Установка

Windows

FreeBSD

[server:~] # pkg install nagios

[server:~] # cd /usr/local/etc/nagios/

[server:local/etc/nagios] # sh

# for i in *sample; do cp -v $i ${i%-sample}; done

# cd objects/

# for i in *sample; do cp -v $i ${i%-sample}; done

<Ctrl-D>

Debian

Готового пакета нет

Ubuntu

root@server:~# apt install nagios3

Пароль: nagios

root@server:~# cd /etc/nagios3/conf.d/

CentOS

Настройка web доступа

Windows

shell> notepad++ C:\Program Files\ICW\etc\nginx\nginx.conf
...
        listen       81;
...

FreeBSD

server# more cgi.cfg
...
use_authentication=1
...
[server:~] # cat /usr/local/etc/apache24/Includes/nagios.conf
   <Directory /usr/local/www/nagios>
     AllowOverride AuthConfig
     Require all granted
     
     DirectoryIndex index.php
     php_flag engine on
     php_admin_value open_basedir /usr/local/www/nagios/:/var/spool/nagios/
   </Directory>

   <Directory /usr/local/www/nagios/cgi-bin>
     Options ExecCGI
   </Directory>

   ScriptAlias /nagios/cgi-bin/ /usr/local/www/nagios/cgi-bin/
   Alias /nagios/ /usr/local/www/nagios/
# cat /usr/local/www/nagios/.htaccess
AuthName "Nagios Access"
AuthType Basic
AuthUserFile /usr/local/etc/nagios/htpasswd.users
require valid-user
htpasswd -c /usr/local/etc/nagios/htpasswd.users nagiosadmin

Настройка объектов мониторинга

Windows

C:\Program Files\ICW\etc\nagios\nagwin>notepad++ contacts.cfg
...
        email                           userX@isp.un	; <<***** CHANGE THIS TO YOUR EMAIL ADDRESS ******
...
C:\Program Files\ICW\etc\nagios\nagwin>notepad++ commands.cfg
...
# 'notify-host-by-email' command definition
define command{
	command_name	notify-host-by-email
	command_line	/usr/bin/printf ... -f nagios@corpX.un ... -server mail.isp.un
	}

# 'notify-service-by-email' command definition
define command{
	command_name	notify-service-by-email
	command_line	/usr/bin/printf ... -f nagios@corpX.un ... -server mail.isp.un
	}
...

FreeBSD

[server:local/etc/nagios] # cat nagios.cfg
...
cfg_file=/usr/local/etc/nagios/objects/corpX.cfg
[server:~] # cd /usr/local/etc/nagios/objects/

[server:etc/nagios/objects] # cat commands.cfg
...
# может не нужно
command_line    $USER1$/check_ping -H $HOSTADDRESS$ -w 3000.0,80% -c 5000.0,100% -p 5 -4
...

FreeBSD/Ubuntu/Windows

server# cat corpX.cfg
define host{
	use                     generic-host
	name			my-templ-host
	register		0

	max_check_attempts	1
  
# For Ubuntu (mail send to user root)
#        contacts                root
#        check_command       	check-host-alive_4

# For Windows and Freebsd (mail send to user nagios)
#        contacts                nagiosadmin
#        check_command       	check-host-alive
}

#---------------------------------

define host{
        use                     my-templ-host
        host_name               yandex
        alias                   yandex web site
        address                 ya.ru
}

define service{
        use                     generic-service
        host_name               yandex
        service_description     www
        check_command           check_http
        normal_check_interval   5
        retry_check_interval    1
}

#---------------------------------

define host{
        use                     my-templ-host
        host_name               switch
        alias                   core switch
        address                 switch
}

define service{
        use                     generic-service
        host_name               switch
        service_description     ping
#        check_command           check_winping

# может понадобиться ключ -4 в описание команды
#        check_command           check_ping!100.0,20%!500.0,60%
        normal_check_interval   5
        retry_check_interval    1
}

#---------------------------------

define servicedependency{
        host_name                       switch
        service_description             ping
        dependent_host_name             yandex
        dependent_service_description   www
        execution_failure_criteria      o
        notification_failure_criteria   w,u
}

Тестирование конфигурации и запуск

l/p: nagiosadmin/nagios

Windows

Все через кнопку «Пуск»

Ubuntu

root@server:~# nagios3 -v /etc/nagios3/nagios.cfg

root@server:~# /etc/init.d/nagios3 restart

FreeBSD

[server:~] # nagios -v /usr/local/etc/nagios/nagios.cfg

[server:~] # sysrc nagios_enable=yes

[server:~] # service nagios start

Запуск plugins на других хостах

root# sudo -u nagios sh
nagios$ cat .ssh/id_rsa.pub
...

nagios$ cat .ssh/config
...

nagios$ /usr/local/libexec/nagios/check_by_ssh -H server2 -C "/usr/lib/nagios/plugins/check_disk -w '10' -c '20' -e -p '/'"

server# cat corpX.cfg
define host{
        use                     my-templ-host
        host_name               server2
        address                 server2
}

define service{
        use                     generic-service
        host_name               server2
}

define command{
        command_name    ssh_disk_linux
        command_line    $USER1$/check_by_ssh -H '$HOSTADDRESS$' -C "/usr/lib/nagios/plugins/check_disk -w '$ARG1$' -c '$ARG2$' -e -p '$ARG3$'"
}

define service{
        use                     generic-service
        service_description     disk
        host_name               server2
        check_command           ssh_disk_bsd_linux!20%!10%!/
}

Использование plugin check_snmp

Тестирование plugin

shell> snmpwalk -c public -v2c router ifDescr

FreeBSD

[server:~] # cd /usr/ports/net-mgmt/nagios-plugins

[server:~] # make config
...
OPTIONS_FILE_SET+=NETSNMP
...
[server:~] # cd /usr/local/libexec/nagios/

Debian/Ubuntu

root@server:~# cd /usr/lib/nagios/plugins

FreeBSD/Debian/Ubuntu

# ./check_snmp -H router -C public -o ifInOctets.2,ifOutOctets.2 --rate -w 1000,1000 -c 10000,10000

Debian/Ubuntu

# rm -r /usr/var/*

# chown -R nagios /usr/var/

Настройка nagios на использование check_snmp

server# cat corpX.cfg
...
define command {
        command_name check_snmp_band
        command_line $USER1$/check_snmp --rate -H $HOSTADDRESS$ -C $ARG1$ -o $ARG2$ -w $ARG3$ -c $ARG4$
}

define host{
        use             my-templ-host
        host_name       cisco-router
        alias           Cisco 7200
        address         router
}

define service{
        use                     generic-service
        host_name               cisco-router
        service_description     int_if_bandwidth
        check_command check_snmp_band!public!ifInOctets.2,ifOutOctets.2!1000,1000!10000,10000
}

Использование plugin check_snmp_int

Установка plugin

FreeBSD

[server:~] # pkg install nagios-snmp-plugins-extras

[server:~] # cd /usr/local/libexec/nagios/

Debian/Ubuntu

root@server:~# apt install nagios-snmp-plugins

root@server:~# cd /usr/lib/nagios/plugins

Тестирование plugin

По умолчанию значения в KBytes/s

FreeBSD/Ubuntu

# ./check_snmp_int.pl -H router -C public -n FastEthernet1/0 -k -w 10,10 -c 100,100

# ./check_snmp_int.pl --help
...
-k, --perfcheck ; -q, --extperfcheck
   -k check the input/ouput bandwidth of the interface
   -q also check the error and discard input/output

-w, --warning=input,output[,error in,error out,discard in,discard out]
   warning level for input / output bandwidth (0 for no warning)
     unit depends on B,M,G,u options
   warning for error & discard input / output in error/min (need -q)

-c, --critical=input,output[,error in,error out,discard in,discard out]
   critical level for input / output bandwidth (0 for no critical)
     unit depends on B,M,G,u options
   critical for error & discard input / output in error/min (need -q)
...

FreeBSD

# cat /var/tmp/tmp_Nagios_int.router.FastEthernet1_0

# rm /var/tmp/tmp_Nagios_int.router.*

Ubuntu

# cat /tmp/tmp_Nagios_int.router.FastEthernet1_0

# rm /tmp/tmp_Nagios_int.router.*

Настройка nagios на использование plugin

FreeBSD/Ubuntu

server# cat corpX.cfg
...
define command {
        command_name check_snmp_int_band
        command_line $USER1$/check_snmp_int.pl -H $HOSTADDRESS$ -C $ARG1$ -n $ARG2$ -k -w $ARG3$ -c $ARG4$
}

define service{
        use                     generic-service
        host_name               cisco-router
        service_description     int_if_bandwidth
        check_command check_snmp_int_band!public!FastEthernet1/0!10,10!100,100
}

Интеграция с MRTG

# /usr/local/libexec/nagios/check_mrtg -h

# /usr/local/libexec/nagios/check_mrtgtraf -h

Использование скриптов

# cat /etc/nagios-dhcp-stat.sh
#!/bin/sh

#CMD='rsh router show ip dhcp binding | grep 192.168 | wc -l'
#MAX=99
#CUR=`eval $CMD`

#CMD='/usr/bin/dhcpd-pools -l /var/lib/dhcp/dhcpd.leases -c /etc/dhcp/dhcpd.conf -f c | grep 192.168.X.'
#CMD='/usr/local/bin/dhcpd-pools -l /var/db/dhcpd/dhcpd.leases -c /usr/local/etc/dhcpd.conf -f c | grep 192.168.X.'
#MAX=`eval $CMD | cut -d'"' -f8`
#CUR=`eval $CMD | cut -d'"' -f10`

echo CUR:$CUR MAX:$MAX

test $CUR -eq $MAX && exit 2

exit 0
# cat corpX.cfg
...
define command {
        command_name check_dhcp_stat
        command_line /etc/nagios-dhcp-stat.sh
}

define service{
        use generic-service
        host_name localhost
        service_description check dhcp stat
        check_command check_dhcp_stat
}

Установка Web-интерфейса Nagios

сервис_nagios.txt · Последние изменения: 2018/07/23 13:08 — val