Skip to content

Instantly share code, notes, and snippets.

@kekh
Last active November 25, 2015 01:06
Show Gist options
  • Save kekh/bc26e919fcd338cc4918 to your computer and use it in GitHub Desktop.
Save kekh/bc26e919fcd338cc4918 to your computer and use it in GitHub Desktop.
KISS Fail2Ban send mail action with temporisation. This allows to not beiing spammed on each bans after system (re)boot or Fail2Ban service (re)start... Rely on "gracetime" script in https://github.com/kekh/Fail2Ban-Tweaks.
[Definition]
actionstart =
actionstop =
actionban = GRACE_CMD="/usr/bin/gracetime all 10"
if [ "$(${GRACE_CMD})" = "NO" ]
then
printf %%b "Hi,\n
The IP <ip> has just been banned by Fail2Ban after
<failures> attempts against <name>.\n\n
Here is more information about <ip> :\n
`/usr/bin/whois <ip> || echo missing whois program`\n\n
Lines containing IP:<ip> in <logpath>\n
`grep -E <grepopts> '(^|[^0-9])<ip>([^0-9]|$)' <logpath>`\n\n
Regards,\n
Fail2Ban" | /usr/sbin/sendmail -f <sender> <dest>
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment