Small utilities to extract daily ban counts from Fail2Ban logs into a CSV and plot them.
The plotting script requires Matplotlib.
On Debian/Ubuntu you can install it with:
sudo apt update && sudo apt install -y python3-matplotlibReads /var/log/fail2ban.log* (plain and compressed) and writes a CSV file with the number of bans per day and per jail.
Run:
python3 generate_bans_summary.pyThis generates a CSV file (by default bans_summary.csv) with contents like:
date,All jails,sshd,nginx-forbidden,postfix
2025-07-28,8,5,3,0
2025-07-29,58,38,18,2
2025-07-30,66,49,13,4
...
Reads the CSV generated by the previous script and produces a line chart.
Run:
python3 plot_bans.pyThis generates an image (by default bans_summary.png) similar to:
Both scripts support other parameters, for instance:
python3 generate_bans_summary.py -o file.csv
python3 plot_bans.py -i file.csv -o file.png --width 12 --heigh 6 --dpi 100You can see all available options by running:
python3 generate_bans_summary.py --help
python3 plot_bans.py --helpMIT
