Power Monitoring with APCUPSD, Email using SSMTP and Google Apps

Recently I performed a large upgrade to my raid file-server, the information being stored is much more critical at this point in time and I have chosen to step up the game in four ways:

  1. Move from on-board Intel controller to dual LSI L8i 8channel hba controllers
  2. Move from raid5 to raid6
  3. Install an APC UPS and monitor it with apcupsd
  4. System monitoring with email alerts via mdadm and Google SMTP

(Sorry for re-iteration if you are following the feed, trying to establish context)

The apcupsd tool lets you connect to your UPS and control when the machine shuts itself down during a scenario where you loose power. Another really nice thing this will do is allow you to send yourself an email through whatever MTA you set up.

The difficult part of getting email setup is configuring a MTA (Mail Transfer Agent). I searched for quite a while on how to get this setup. My initial impression was that I would have to host my own via postfix or some other alternative. I was happy to find that I could use a much more lightweight solution with ssmtp and an email I created from my google apps account.

Install ssmtp

sudo apt-get install ssmtp

Configure ssmtp via its config file /etc/ssmtp/ssmtp.conf

# Config file for sSMTP sendmail
#
# The person who gets all mail for userids < 1000
# Make this empty to disable rewriting.
root=serveremailaddress@yourgoogleappsdomain.tld

# The place where the mail goes. The actual machine name is required no
# MX records are consulted. Commonly mailhosts are named mail.domain.com
mailhub=smtp.gmail.com:587

# Where will the mail seem to come from?
#rewriteDomain=

# The full hostname
hostname=servername.yourgoogleappsdomain.tld

# Are users allowed to set their own From: address?
# YES – Allow the user to specify their own From: address
# NO – Use the system generated From: address
#FromLineOverride=YES

UseSTARTTLS=YES
UseTLS=YES
AuthUser=serveremailaddress@yourgoogleappsdomain.tld
AuthPass=password

Now for a test of ssmtp, create a test file with some text in it. My test file was called ‘test’:

ssmtp youremail@yourgoogleappsdomain.tld < test

For apcupsd we need to modify two files to set our email address up for alerts. They are both located in the /etc/apcupsd directory and are called ‘onbattery’ and ‘offbattery’. I would suggest to leave these as they are because if you set up ssmtp like I have, when an email comes in for root it will be sent on to the ssmtp root address.

Now unplug your UPS and wait for the emails to come!

Leave a Reply