Skip to content

Instantly share code, notes, and snippets.

@CHERTS
Last active August 29, 2022 11:19
Show Gist options
  • Star 7 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save CHERTS/1bcd0ff30f93109a9c1cd2d46b2990b0 to your computer and use it in GitHub Desktop.
Save CHERTS/1bcd0ff30f93109a9c1cd2d46b2990b0 to your computer and use it in GitHub Desktop.
Fail2ban + Telegram using telegram-send
# lsb_release -a
No LSB modules are available.
Distributor ID: Debian
Description: Debian GNU/Linux 8.9 (jessie)
Release: 8.9
Codename: jessie
Installing telegram-send
# pip install telegram-send
Enter chat_id and token for Telegram bot:
# telegram-send --configure
Testing
# /usr/local/bin/telegram-send --format markdown Test
# File /etc/fail2ban/jail.conf
[ssh]
enabled = true
port = ssh
filter = sshd
logpath = /var/log/auth.log
maxretry = 6
action = %(action_)s
telegram[name=SSH]
# File /etc/fail2ban/action.d/telegram.conf
[Definition]
actionstart = /usr/local/bin/telegram-send --format markdown "[Fail2Ban] The jail <name> has been started on `uname -n` successfully."
actionstop = /usr/local/bin/telegram-send --format markdown "[Fail2Ban] The jail <name> has been stopped on `uname -n`."
actioncheck =
actionban = /usr/local/bin/telegram-send --format markdown "[Fail2Ban] The IP <ip> has just been banned by Fail2Ban after <failures> attempts against <name> from `uname -n`"
actionunban = /usr/local/bin/telegram-send --format markdown "[Fail2Ban] The IP <ip> has just been unbanned by Fail2Ban after <failures> attempts against <name> from `uname -n`"
[Init]
init = 'Fail2Ban Telegram plugins activated"
@baralgin584
Copy link

Bug: if in name exist symbol _ it didn't send to telegram
like
action = %(action_)s
telegram[name=zabbix_login]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment