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.