Nagios: ayuda para que NRPE funcione con check_fail2ban.sh

Nagios: ayuda para que NRPE funcione con check_fail2ban.sh

Estoy intentando monitorear fail2ban con Nagios, así que encontré la siguiente verificación a través de una búsqueda en Google: http://nagios.fm4dd.com/plugins/manual/check_fail2ban.htm

Estoy intentando que la verificación funcione en un host remoto, pero no logro que arroje resultados precisos. Estoy usando Fail2ban v0.9.3 en CentOS 7, por lo que tuve que realizar un cambio en el script según el siguiente enlace: https://exchange.nagios.org/directory/Plugins/Security/Firewall-Software/check_fail2ban/details#rev-3948

*NOTA: Todos los resultados a continuación provienen del "Servidor remoto" y no de mi "Servidor Nagios".

El cambio que hice (Línea 108) está a continuación:

jail_list=$($fail2ban_client status|grep "list" |cut -d : -f 2 |tr -d ,)

Ya le di permisos de usuario y NRPE a Nagios según la wiki:

setfacl -m u:nagios:rwx /var/run/fail2ban/fail2ban.sock

Puedo ejecutar el cliente fail2ban y el script como usuarios de Nagios y NRPE:

[root@localhost plugins]# sudo -u nrpe fail2ban-client status
Status
|- Number of jail:      2
`- Jail list:   openvpn, sshd

[root@localhost plugins]# sudo -u nagios fail2ban-client status
Status
|- Number of jail:      2
`- Jail list:   openvpn, sshd

[root@localhost etc]# sudo -u nagios /usr/lib64/nagios/plugins/check_fail2ban.sh -w 10 -c 20
OK: 1 banned IP(s) in 2 active jails|banned_IP=1;10;20;;
jail openvpn blocks 1 IP(s): 76.123.218.206
jail sshd blocks 0 IP(s):
| openvpn=1;;;; sshd=0;;;;

[root@localhost etc]# sudo -u nrpe /usr/lib64/nagios/plugins/check_fail2ban.sh -w 10 -c 20
OK: 1 banned IP(s) in 2 active jails|banned_IP=1;10;20;;
jail openvpn blocks 1 IP(s): 76.123.218.206
jail sshd blocks 0 IP(s):
| openvpn=1;;;; sshd=0;;;;

Esto es lo que obtengo cuando lo ejecuto localmente:

[root@localhost plugins]# ./check_fail2ban.sh -w 10 -c 20
OK: 1 banned IP(s) in 2 active jails|banned_IP=1;10;20;;
jail openvpn blocks 1 IP(s): 46.133.118.236
jail sshd blocks 0 IP(s):
| openvpn=1;;;; sshd=0;;;;

Esto es lo que obtengo cuando lo ejecuto localmente con NRPE:

[root@localhost plugins]# /usr/lib64/nagios/plugins/check_nrpe -t 60 -H 127.0.0.1 -p 5666 -c check_fail2ban -a 10 20
OK: 0 banned IP(s) in active jails|banned_IP=0;10;20;;
|
  • Obtengo el mismo resultado cuando lo ejecuto en mi servidor Nagios

Mi comando está definido en mi nrpe.cfg:

command[check_fail2ban]=/usr/lib64/nagios/plugins/check_fail2ban.sh -w $ARG1$ -c $ARG2$

Intenté algo de "depuración" agregando lo siguiente a mi archivo nrpe.cfg:

command[check_fail2ban]=whoami
command[check_fail2ban]=env

Salida de "depuración":

[root@localhost plugins]# /usr/lib64/nagios/plugins/check_nrpe -t 60 -H 127.0.0.1 -p 5666 -c check_fail2ban -a 10 20
SHELL=/sbin/nologin
NRPE_PROGRAMVERSION=2.15
USER=nrpe
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin
PWD=/
LANG=en_US.UTF-8
SHLVL=1
HOME=/var/run/nrpe
LOGNAME=nrpe
NRPE_SSL_OPT=
NRPE_MULTILINESUPPORT=1
_=/usr/bin/env

Intenté una depuración adicional configurando NRPE en depuración =1. Aquí está el resultado cuando ejecuto el comando desde mi servidor Nagios.

Sep 27 12:36:46 localhost nrpe[31031]: Connection from 192.168.1.200 port 61853
Sep 27 12:36:46 localhost nrpe[31031]: Host address is in allowed_hosts
Sep 27 12:36:46 localhost nrpe[31031]: Handling the connection...
Sep 27 12:36:46 localhost nrpe[31031]: Host is asking for command 'check_fail2ban' to be run...
Sep 27 12:36:46 localhost nrpe[31031]: Running command: usr/lib64/nagios/plugins/check_fail2ban.sh -w 10 -c 20
Sep 27 12:36:46 localhost nrpe[31031]: Command completed with return code 0 and output: OK: 0 banned IP(s) in active jails|banned_IP=0;10;20;;#012|
Sep 27 12:36:46 localhost nrpe[31031]: Return Code: 0, Output: OK: 0 banned IP(s) in active jails|banned_IP=0;10;20;;#012|
Sep 27 12:36:46 localhost nrpe[31031]: Connection from `bYj closed.
  • Me sale lo mismo cuando lo ejecuto localmente desde el servidor con check_nrpe.

¿Parece que es posible que NRPE no esté capturando todo el resultado del script? Por favor, perdónenme si esto es algo estúpido que me he perdido, ya que soy un usuario de Windows, que hace muy poco en Linux. ¡Cualquier ayuda es muy apreciada!


* ***EDITAR A RESPUESTAS* ***

Usuario4556274, creo que está habilitado. Aquí está el resultado de ese comando:

[root@localhost etc]# ls -Z /usr/lib64/nagios/plugins
-rwxr-xr-x. root root unconfined_u:object_r:usr_t:s0   check_apc
-rwxr-xr-x. root root unconfined_u:object_r:usr_t:s0   check_asterisk_pri.php
-rwxr-xr-x. root root system_u:object_r:nagios_checkdisk_plugin_exec_t:s0 check_disk
-rwxr-xr-x. root root unconfined_u:object_r:lib_t:s0   check_fail2ban.old
-rwxr-xr-x. root root unconfined_u:object_r:lib_t:s0   check_fail2ban.sh
-rwxr-xr-x. root root system_u:object_r:nagios_system_plugin_exec_t:s0 check_load
-rwxr-xr-x. root root unconfined_u:object_r:lib_t:s0   check_mem.pl
-rwxr-xr-x. root root system_u:object_r:nagios_services_plugin_exec_t:s0 check_nrpe
-rwxr-xr-x. root root unconfined_u:object_r:usr_t:s0   check_openmanage
-rwxr-xr-x. root root unconfined_u:object_r:lib_t:s0   check_openvpn.php
-rwxr-xr-x. root root unconfined_u:object_r:lib_t:s0   check_openvpn_user_list
-rwxr-xr-x. root root unconfined_u:object_r:lib_t:s0   check_openvpn_user_status
-rwxr-xr-x. root root unconfined_u:object_r:lib_t:s0   check_openvpn_user_traffic
-rwxr-xr-x. root root unconfined_u:object_r:lib_t:s0   check_ping
-rwxr-xr-x. root root system_u:object_r:nagios_system_plugin_exec_t:s0 check_procs
-rwxr-xr-x. root root system_u:object_r:nagios_system_plugin_exec_t:s0 check_swap
-rwxr-xr-x. root root unconfined_u:object_r:usr_t:s0   check_swraid.py
-rwxr-xr-x. root root unconfined_u:object_r:usr_t:s0   check_swraid.sh
-rwxr-xr-x. root root system_u:object_r:nagios_system_plugin_exec_t:s0 check_users
-rwxr-xr-x. root root system_u:object_r:bin_t:s0       negate
-rwxr-xr-x. root root system_u:object_r:bin_t:s0       urlize
-rwxr-xr-x. root root system_u:object_r:bin_t:s0       utils.sh

información relacionada