Giter VIP home page Giter VIP logo

fail2ban_telegram_notifications's Introduction

Fail2ban Telegram Notifications

Sending fail2ban notifications using a Telegram bot

Installation and configuration

  • 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

Usage

  • /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)

Buy me a coffe

ko-fi

fail2ban_telegram_notifications's People

Contributors

castillo92 avatar deividgdt avatar the0tter0ne avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

fail2ban_telegram_notifications's Issues

action prevents block of ip

When I add the code to my jail.local,

action   = iptables[name=nginx-custom, port=80, protocol=tcp]
               telegram

the IP is not stopped anymore. It is still in the iptable, but it I can still access the server from that ip. Any thoughts?

syntax error near unexpected token

Hola, muchas gracias por tu aporte.

Al intentar hacer funcionar el script ejecutando solo /etc/fail2ban/scripts/send_telegram_notif.sh -b

Me da este error: -bash: syntax error near unexpected token `newline'

Sabes a que se debe?

Gracias

Could be possible add info about the jail

Hello! Your script works great for me at the first try. I found a very good tutorial from you in NextCloud Support Forum.

Now, I would like to pass to Telegram the name of the Jail that block the IP.

Looking at /etc/fail2ban/jail.conf I saw:

# The simplest action to take: ban only
action_ = %(banaction)s[name=%(__name__)s, port="%(port)s", protocol="%(protocol)s", chain="%($

And:

# "filter" defines the filter to use by the jail.
#  By default jails have names matching their filter name
#
filter = %(__name__)s[mode=%(mode)s]

So... is name=%(__name__)s, the way of obtain the jail name? If yes, could you help me edit your script to make possible send the jail name?

To show for example this message in Telegram:
The IP: 150.136.60.xxx has been banned by 'apache-badbots'

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.