Nagios – Hilfe dabei, NRPE mit check_fail2ban.sh zum Laufen zu bringen

Nagios – Hilfe dabei, NRPE mit check_fail2ban.sh zum Laufen zu bringen

Ich versuche, fail2ban mit Nagios zu überwachen und habe daher über eine Google-Suche die folgende Prüfung gefunden: http://nagios.fm4dd.com/plugins/manual/check_fail2ban.htm

Ich versuche, die Prüfung auf einem Remote-Host zum Laufen zu bringen, aber ich schaffe es nicht, genaue Ergebnisse zu liefern. Ich verwende Fail2ban v0.9.3 auf CentOS 7, also musste ich eine Änderung am Skript über den folgenden Link vornehmen: https://exchange.nagios.org/directory/Plugins/Security/Firewall-Software/check_fail2ban/details#rev-3948

*NOTIZ: Die gesamte Ausgabe unten stammt vom „Remote-Server“ und nicht von meinem „Nagios-Server“.

Die von mir vorgenommene Änderung (Zeile 108) ist unten:

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

Ich habe dem Nagios-Benutzer und NRPE bereits die Berechtigungen gemäß dem Wiki erteilt:

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

Ich kann den Fail2ban-Client und das Skript sowohl als Nagios- als auch als NRPE-Benutzer ausführen:

[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;;;;

Folgendes erhalte ich, wenn ich es lokal ausführe:

[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;;;;

Folgendes erhalte ich, wenn ich es lokal mit NRPE ausführe:

[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;;
|
  • Ich erhalte das gleiche Ergebnis, wenn ich es auf meinem Nagios-Server ausführe

Mein Befehl ist in meiner nrpe.cfg definiert:

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

Ich habe einige „Debugging“-Aktionen durchgeführt, indem ich meiner Datei nrpe.cfg Folgendes hinzugefügt habe:

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

„Debug“-Ausgabe:

[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

Ich habe zusätzliches Debuggen versucht, indem ich NRPE auf debug =1 gesetzt habe. Hier ist die Ausgabe, wenn ich den Befehl von meinem Nagios-Server aus ausführe.

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.
  • Ich erhalte das Gleiche, wenn ich es lokal vom Server mit check_nrpe ausführe.

Es sieht so aus, als würde NRPE möglicherweise nicht die gesamte Ausgabe des Skripts erfassen. Bitte verzeihen Sie mir, wenn ich etwas Dummes übersehen habe, da ich ein Windows-Benutzer bin, der unter Linux sehr wenig macht. Jede Hilfe ist sehr willkommen!


* ***ANTWORTEN BEARBEITEN* ***

User4556274, ich glaube, es ist aktiviert. Hier ist die Ausgabe dieses Befehls:

[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

verwandte Informationen