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

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


сервис_nagios

Это старая версия документа.


Сервис Nagios

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

Установка

Debian 10

# a2enmod auth_digest

# a2enmod authz_groupfile

# systemctl restart apache2

# apt install nagios4

# cd /etc/nagios4/conf.d/

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

server# /usr/lib/nagios/plugins/check_http -I val.bmstu.ru
server# cat corpX.cfg
define host{
	use                     generic-host
	name			my-templ-host
	register		0

	max_check_attempts	1
#        check_command       	check-host-alive
#        check_command       	check-host-alive_4
  

# mail send to user nagios
        contacts                nagiosadmin

}

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

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
#        check_command           check_http_4
        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

Debian 10

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

root@server:~# service nagios4 restart

Запуск 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
# cd /usr/lib/nagios/plugins

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

# 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

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)
...

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.1582778120.txt.gz · Последние изменения: 2020/02/27 07:35 — val