A Telegram bot for monitoring fail2ban activity: bans, statistics, service status, and geolocation mapping of attackers.
- ✅ Real-time ban statistics (hour, day, week, month, year)
- ✅ Comparison with previous periods
- ✅ Service status:
fail2banrunning/enabled/version/start time - ✅ SSH jail details via
fail2ban-client status sshd - 🌍 Geo-mapping of banned IPs:
- World map with unique colors per country
- Countries without bans → white
- Legend with country + ban count
- 🔁 Auto-update of GeoIP database (monthly)
- 📢 Telegram notifications on GeoIP update
- 🐳 Fully Dockerized
- 📦 Easy deployment with
.envconfig
fail2baninstalled and running- Telegram Bot Token (from @BotFather)
- MaxMind account for GeoLite2 (free tier)
git clone https://github.com/ksalab/fail2ban_bot.git
cd fail2ban_botcp example.env .envdocker build -t fail2ban-bot .docker run -d --name fail2ban-bot \
-v /var/log/fail2ban.log:/var/log/fail2ban.log:ro \
-v ./geoip:/app/geoip:rw \
--restart unless-stopped \
--env-file .env \
fail2ban-bot🔹 The bot will auto-download GeoIP DB on first run.
| COMMANDS | DESCRIPTIONS |
|---|---|
/start |
Welcome message |
/stats |
Ban stats by period |
/status |
Service status |
/geo |
Global geo map of banned IPs |
/geo→ world map with colored countries- From stats menu → "🗺️ Geo Stats for This Period"
- Auto-updates GeoIP DB every 28 days
- Sends Telegram alert on update
MIT License — see LICENSE
PRs welcome! Please follow Python best practices and keep code clean.