Skip to content

Instantly share code, notes, and snippets.

@meinside
Last active May 3, 2022 08:08
Show Gist options
  • Save meinside/bdbcfc1c15bc6aca57bada57dcce06c0 to your computer and use it in GitHub Desktop.
Save meinside/bdbcfc1c15bc6aca57bada57dcce06c0 to your computer and use it in GitHub Desktop.
Notify with pushbullet message on fail2ban's ban actions
#!/bin/bash
#
# notify-fail2ban.sh
#
# Notifies on fail2ban's ban actions through pushbullet
#
# NOTE: this script will be run as root, so don't forget to put related config files under /root/.config/
#
# USAGE: $ ./notify-fail2ban.sh 8.8.8.8 ssh
#
#
# last update: 2019.06.05.
#
# by meinside@duck.com
# binary paths
#
# go get -u github.com/meinside/ipstack-go/cmd/ip2loc
LOCATOR=/path/to/ip2loc
# go get -u github.com/meinside/pb-send
SENDER=/path/to/pb-send
# command line params
IP=$1
PORT=$2
# fetch location,
LOCATION=`$LOCATOR "$IP"`
MESSAGE="`hostname` fail2ban banned $PORT: $LOCATION"
# and run sender
$SENDER "$MESSAGE"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment