Telegram Notification for Fail2Ban
-
Create a Telegram bot from the offical guide and the get the bot token.
-
Start a conversation with the bot.
-
Get the
chat id
from thegetUpdates
API call.# Replace <token> with the bot token. $ curl -s -X POST https://api.telegram.org/bot<token>/getUpdates {"ok":true,"result":[{"update_id":111111111,"message":{"message_id":2,"from":{"id":22222222,"is_bot":false,"first_name":"xxxxxx","last_name":"xxxxxx","username":"xx","language_code":"ko"},"chat":{"id":22222222,"first_name":"xxxxxx","last_name":"xxxxx","username":"xxx","type":"private"},"date":1602336707,"text":"Hello, Bot!"}}]}
You can get the
chat id
from the JSON response."chat":{"id":<chat_id>", ...
-
Copy the
telegram.conf
to/etc/fail2ban/action.d/telegram.conf
. -
Set the
telegram_chat_id
andtelegram_bot_token
values to the jail. (don't surrounded by double quotes.) example: sshd.local.example. -
Restart the Fail2ban.
sudo systemctl restart fail2ban