Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
72 changes: 72 additions & 0 deletions action.d/telegram.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
## Version 2024/11/07
# Fail2Ban configuration file
#
# Author: smith8ca
#
# Add the following to jail.local (uncommented) to apply the telegram action to all bans with all jails
# Update the bot_token and chat_id (within the Init section) with your own values from Telegram's BotFather
#
#

[Definition]

# Option: actionstart
# Notes.: command executed once at the start of Fail2Ban.
# Values: CMD
#
# Comment out this action as necessary
actionstart = curl -X POST -H Content-Type:application/json <url><bot_token>/sendMessage \
--data '{ "text": "Started <name>", "chat_id": "<chat_id>" }'

# Option: actionstop
# Notes.: command executed once at the end of Fail2Ban
# Values: CMD
#
# Comment out this action as necessary
actionstop = curl -X POST -H Content-Type:application/json <url><bot_token>/sendMessage \
--data '{ "text": "Stopped <name>", "chat_id": "<chat_id>" }'

# Option: actioncheck
# Notes.: command executed once before each actionban command
# Values: CMD
#
actioncheck =

# Option: actionban
# Notes.: command executed when banning an IP. Take care that the
# command is executed with Fail2Ban user rights.
# Tags: See jail.conf(5) man page
# Values: CMD
#
actionban = curl -X POST -H Content-Type:application/json <url><bot_token>/sendMessage \
--data '{ "text": "<name>: <ip> got banned for <bantime> seconds after <failures> tries.\n\nUnban command:\nfail2ban-client unban <ip>", "chat_id": "<chat_id>" }'

# Option: actionunban
# Notes.: command executed when unbanning an IP. Take care that the
# command is executed with Fail2Ban user rights.
# Tags: See jail.conf(5) man page
# Values: CMD
#
actionunban = curl -X POST -H Content-Type:application/json <url><bot_token>/sendMessage \
--data '{ "text": "<name>: <ip> is now unbanned", "chat_id": "<chat_id>" }'


[Init]

# Option: bot_token
# Notes.: The token of the telegram bot
# Values: [ STRING ]
#
bot_token =

# Option: chat_id
# Notes.: The chat id of the telegram user or group
# Values: [ STRING ]
#
chat_id =

# Option: url
# Notes.: The url of the telegram API
# Values: [ STRING ]
#
url = https://api.telegram.org/bot