Wednesday, August 1, 2012

Fail2Ban with Pushover Notification

I recently purchased the pushover notification app for android due to a discount offer. As a result, I decide to integrate pushover notification with some Fedora services on my home server.

Fail2Ban

To enable pushover notification, I added a pushover-notify action to /etc/fail2ban/action.d/pushover-notify.conf.
# Fail2Ban configuration file
#

[Definition]
# Notify on Startup
actionstart = /usr/bin/curl -s -F "token="  -F "user=" -F "title=[Fail2Ban]" -F "message=Jail  has been started successfully." https://api.pushover.net/1/messages
# Notify on Shutdown
actionstop = /usr/bin/curl -s -F "token="  -F "user=" -F "title=[Fail2Ban]" -F "message=Jail  has been stopped." https://api.pushover.net/1/messages
# 
actioncheck = 
# Notify on Banned
actionban = /usr/bin/curl -s -F "token="  -F "user=" -F "title=[Fail2Ban]  banned" -F "message=Banned IP:  Attempts:  `geoiplookup `" https://api.pushover.net/1/messages
# Notify on Unbanned
actionunban = 

[Init]
# Defaut name of the chain
#
name = default

# Application token key
#
token = PLACE_YOUR_APPLICATION_TOKEN_HERE

# User API key
#
user = PLACE_YOUR_USER_API_KEY_HERE

This action script uses curl and geoiplookup. Since I have SELinux enforced, I had to add policies to allow this action to run. Once done, I edit my jail.conf to enable this action.

Smartd

Add the curl command to the /usr/libexec/smartmontools/smartdnotify.

Apcaccess

Finally, I added pushover notification to my UPS monitoring services to notify me for power blackout.

4 comments:

  1. Hi, this is awesome, thanks for posting it. However I'm unable to get it to work. What does the jail.conf need to have to enable it?

    Thanks.

    ReplyDelete
  2. The filter with the action needs to enabled

    ReplyDelete
  3. I have get it working on the banned notify but, missing ip and attempt info.
    Wonder what is missing ?

    ReplyDelete
  4. code above doesn't work, as blockspot hides the brackets.. but a view source of page, and then copy his code and this works like a CHAMP.. AWESOME
    Thanks!

    ReplyDelete