91 lines
2.5 KiB
Markdown
91 lines
2.5 KiB
Markdown
# 📡 Fail2Ban Discord Alert
|
||
|
||
Ein Python-basiertes Monitoring-Tool, das automatisch IP-Sperren aus der `fail2ban.log` erkennt und sie mit Länderflagge und Geodaten in Echtzeit an einen Discord-Webhook sendet.
|
||
|
||
---
|
||
|
||
## 🔧 Features
|
||
|
||
- ✅ Überwachung von `/var/log/fail2ban.log` in Echtzeit
|
||
- 🛡️ Versand von Discord-Embed-Nachrichten bei neuen IP-Bans
|
||
- 🌍 Geo-IP-Lookup mit Ländererkennung via [ipapi.co](https://ipapi.co)
|
||
- 🇩🇪🇺🇸 Automatische Anzeige von Länderflaggen im Embed
|
||
- 🧠 SQLite-Datenbank zur Vermeidung doppelter Benachrichtigungen
|
||
- 📁 `.env`-Konfigurationsdatei für sicheren Webhook-Zugriff
|
||
- 🧰 Automatischer Systemd-Service für dauerhaftes Monitoring
|
||
|
||
---
|
||
|
||
## 📦 Voraussetzungen
|
||
|
||
- Linux mit systemd
|
||
- Python 3.6+
|
||
- Zugriff auf `/var/log/fail2ban.log`
|
||
- Funktionierender Fail2Ban-Dienst
|
||
- Ein Discord-Webhook-Link
|
||
|
||
---
|
||
|
||
## 🚀 Installation
|
||
|
||
```bash
|
||
git clone https://github.com/dein-nutzername/fail2ban-discord-alert.git
|
||
cd fail2ban-discord-alert
|
||
chmod +x install_fail2ban_discord.sh
|
||
sudo ./install_fail2ban_discord.sh
|
||
```
|
||
|
||
> 📩 Während der Installation wirst du nach einem Discord Webhook gefragt. Es wird automatisch eine Testnachricht gesendet und alles eingerichtet.
|
||
|
||
---
|
||
|
||
## ⚙️ Dateien im Projekt
|
||
|
||
| Datei | Funktion |
|
||
|--------------------------------|-----------------------------------------------|
|
||
| `fail2ban_discord.py` | Hauptmonitor-Skript |
|
||
| `.env` | Webhook-Konfiguration (wird befüllt) |
|
||
| `requirements.txt` | Python-Abhängigkeiten |
|
||
| `install_fail2ban_discord.sh` | Installationsskript inkl. systemd-Anbindung |
|
||
| `bans.db` | SQLite-Datenbank für verarbeitete IPs |
|
||
|
||
---
|
||
|
||
## 🔁 Service-Verwaltung
|
||
|
||
```bash
|
||
# Status prüfen
|
||
systemctl status fail2ban_discord_alert.service
|
||
|
||
# Dienst starten/stoppen
|
||
sudo systemctl start fail2ban_discord_alert.service
|
||
sudo systemctl stop fail2ban_discord_alert.service
|
||
```
|
||
|
||
---
|
||
|
||
## 🧪 Test-Webhook erneut senden
|
||
|
||
```bash
|
||
curl -H "Content-Type: application/json" \
|
||
-X POST \
|
||
-d '{"content": "✅ Testnachricht vom Fail2Ban Discord Alert!"}' \
|
||
"$(grep DISCORD_WEBHOOK_URL .env | cut -d '=' -f2)"
|
||
```
|
||
|
||
---
|
||
|
||
## 🧼 Uninstall (optional)
|
||
|
||
Ein `uninstall.sh` Skript entfernt:
|
||
- den systemd-Dienst
|
||
- die Python-Umgebung
|
||
- die Datenbank
|
||
- die Konfigurationsdateien
|
||
|
||
---
|
||
|
||
## 📄 Lizenz
|
||
|
||
MIT License – frei verwendbar, auch in kommerziellen Umgebungen.
|