2021-10-17 16:50:59 +02:00
|
|
|
#!/bin/bash
|
|
|
|
: <<=cut
|
2021-03-13 19:46:45 +01:00
|
|
|
|
|
|
|
=head1 NAME
|
|
|
|
|
2021-10-17 16:50:59 +02:00
|
|
|
fail2ban - Plugin to monitor fail2ban blacklists
|
2021-03-13 19:46:45 +01:00
|
|
|
|
2021-10-17 16:50:59 +02:00
|
|
|
=head1 APPLICABLE SYSTEMS
|
2021-03-13 19:46:45 +01:00
|
|
|
|
2021-10-17 16:50:59 +02:00
|
|
|
All systems with "bash" and "fail2ban"
|
2021-03-13 19:46:45 +01:00
|
|
|
|
2021-10-17 16:50:59 +02:00
|
|
|
=head1 CONFIGURATION
|
2021-03-13 19:46:45 +01:00
|
|
|
|
2021-10-17 16:50:59 +02:00
|
|
|
The following is the default configuration
|
2021-03-13 19:46:45 +01:00
|
|
|
|
2021-10-17 16:50:59 +02:00
|
|
|
[fail2ban]
|
|
|
|
env.client /usr/bin/fail2ban-client
|
|
|
|
env.config_dir /etc/fail2ban
|
2021-03-13 19:46:45 +01:00
|
|
|
|
2021-10-17 16:50:59 +02:00
|
|
|
The user running this plugin needs read and write access to the
|
|
|
|
fail2ban communications socket. You will need to add this:
|
2021-03-13 19:46:45 +01:00
|
|
|
|
2021-10-17 16:50:59 +02:00
|
|
|
[fail2ban]
|
|
|
|
user root
|
2021-03-13 19:46:45 +01:00
|
|
|
|
2021-10-17 16:50:59 +02:00
|
|
|
=head1 INTERPRETATION
|
2021-03-13 19:46:45 +01:00
|
|
|
|
2021-10-17 16:50:59 +02:00
|
|
|
This plugin shows a graph with one line per active fail2ban jail, each
|
|
|
|
showing the number of blacklisted addresses for that jail.
|
2021-03-13 19:46:45 +01:00
|
|
|
|
2021-10-17 16:50:59 +02:00
|
|
|
In addition, a line with the total number of blacklisted addresses is
|
|
|
|
displayed.
|
2021-03-13 19:46:45 +01:00
|
|
|
|
2021-10-17 16:50:59 +02:00
|
|
|
=head1 MAGIC MARKERS
|
2021-03-13 19:46:45 +01:00
|
|
|
|
2021-10-17 16:50:59 +02:00
|
|
|
#%# family=auto
|
|
|
|
#%# capabilities=autoconf
|
2021-03-13 19:46:45 +01:00
|
|
|
|
2021-10-17 16:50:59 +02:00
|
|
|
=head1 VERSION
|
2021-03-13 19:46:45 +01:00
|
|
|
|
2021-10-17 16:50:59 +02:00
|
|
|
1.0.20090423
|
2021-03-13 19:46:45 +01:00
|
|
|
|
2021-10-17 16:50:59 +02:00
|
|
|
=head1 BUGS
|
2021-03-13 19:46:45 +01:00
|
|
|
|
2021-10-17 16:50:59 +02:00
|
|
|
Needs bash, due zo using bashisms to avoid running external programs.
|
2021-03-13 19:46:45 +01:00
|
|
|
|
2021-10-17 16:50:59 +02:00
|
|
|
=head1 AUTHOR
|
2021-03-13 19:46:45 +01:00
|
|
|
|
2021-10-17 16:50:59 +02:00
|
|
|
Stig Sandbeck Mathisen <ssm@fnord.no>
|
2021-03-13 19:46:45 +01:00
|
|
|
|
2021-10-17 16:50:59 +02:00
|
|
|
=head1 LICENSE
|
2021-03-13 19:46:45 +01:00
|
|
|
|
2021-10-17 16:50:59 +02:00
|
|
|
GPLv2
|
2021-03-13 19:46:45 +01:00
|
|
|
|
|
|
|
=cut
|
|
|
|
|
|
|
|
|
2021-10-17 16:50:59 +02:00
|
|
|
##############################
|
|
|
|
# Configurable variables
|
|
|
|
client=${client:-/usr/bin/fail2ban-client}
|
|
|
|
config_dir=${config_dir:-/etc/fail2ban}
|
2021-03-13 19:46:45 +01:00
|
|
|
|
2021-10-17 16:50:59 +02:00
|
|
|
##############################
|
|
|
|
# Functions
|
2021-03-13 19:46:45 +01:00
|
|
|
|
2021-10-17 16:50:59 +02:00
|
|
|
# Run fail2ban
|
|
|
|
run_fail2ban() {
|
|
|
|
"$client" -c "$config_dir" "$@"
|
|
|
|
}
|
2021-03-13 19:46:45 +01:00
|
|
|
|
2021-10-17 16:50:59 +02:00
|
|
|
# List jails, one on each line
|
|
|
|
list_jails() {
|
|
|
|
run_fail2ban status | while read -r line; do
|
|
|
|
case $line in
|
|
|
|
*'Jail list:'*)
|
|
|
|
line="${line##*Jail list*:}"
|
|
|
|
line="${line//[ $'\t']/}"
|
|
|
|
if [ -n "$line" ]; then echo "${line//,/$'\n'}"; fi
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
done
|
2021-03-13 19:46:45 +01:00
|
|
|
}
|
|
|
|
|
2021-10-17 16:50:59 +02:00
|
|
|
# Print the munin values
|
|
|
|
values() {
|
|
|
|
list_jails | while read -r jail; do
|
|
|
|
run_fail2ban status "$jail" | while read -r line; do
|
|
|
|
case $line in
|
|
|
|
*'Currently banned'*)
|
|
|
|
line="${line##*Currently banned:}"
|
|
|
|
num="${line//[ $'\t']/}"
|
|
|
|
echo "${jail//[^0-9A-Za-z]/_}.value $num"
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
done
|
|
|
|
}
|
|
|
|
|
|
|
|
# Print the munin config
|
|
|
|
config() {
|
|
|
|
echo 'graph_title Hosts blacklisted by fail2ban'
|
|
|
|
echo 'graph_info This graph shows the number of host blacklisted by fail2ban'
|
|
|
|
echo 'graph_category network'
|
|
|
|
echo 'graph_vlabel Number of hosts'
|
|
|
|
|
|
|
|
echo 'graph_args --base 1000 -l 0'
|
|
|
|
echo 'graph_total total'
|
|
|
|
|
|
|
|
list_jails | while read -r jail; do
|
|
|
|
echo "${jail//[^0-9A-Za-z]/_}.label $jail"
|
|
|
|
done
|
|
|
|
}
|
|
|
|
|
|
|
|
# Print autoconfiguration hint
|
|
|
|
autoconf() {
|
|
|
|
if [ -e "$client" ]; then
|
|
|
|
if [ -x "$client" ]; then
|
|
|
|
if run_fail2ban ping >/dev/null; then
|
|
|
|
echo "yes"
|
|
|
|
else
|
|
|
|
echo "no (fail2ban-server does not respond to ping)"
|
|
|
|
fi
|
|
|
|
else
|
|
|
|
echo "no (${client} is not executable)"
|
|
|
|
fi
|
|
|
|
else
|
|
|
|
echo "no (${client} not found)"
|
|
|
|
fi
|
|
|
|
exit
|
|
|
|
}
|
2021-03-13 19:46:45 +01:00
|
|
|
|
2021-10-17 16:50:59 +02:00
|
|
|
##############################
|
|
|
|
# Main
|
|
|
|
|
|
|
|
case $1 in
|
|
|
|
config)
|
|
|
|
config
|
|
|
|
;;
|
|
|
|
autoconf)
|
|
|
|
autoconf
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
values
|
|
|
|
;;
|
|
|
|
esac
|