Sending fail2ban notifications using a Telegram bot
-
Add the following two lines, for example, to SSHD in the file /etc/fail2ban/jail.conf, make sure to tab the word telegram.
action = iptables[name=SSH, port=22, protocol=tcp] telegram
Example:
-
Download the file telegram.conf and move it to /etc/fail2ban/action.d/
-
Download the file send_telegram_notif.sh move it to /etc/fail2ban/scripts/
-
Modify the file /etc/fail2ban/scripts/send_telegram_notif.sh and add your Token and your Chat ID:
telegramBotToken=YOUR_BOT_TOKEN telegramChatID=YOUR_CHAT_ID
-
Make the file executable
chmod +x /etc/fail2ban/scripts/send_telegram_notif.sh
-
Restart the fail2ban service and enjoy!
systemctl restart fail2ban
- /etc/fail2ban/scripts/send_telegram_notif.sh -a [ start || stop ] || [ -n $NAME -b $IP || -n $NAME -u $IP ]"
- -a (action)
- -n (jail name)
- -b (ban)
- -u (unban)