PowerPanel UPS Software Linux SSMTP Guide
This guide will show to how connect CyberPowers PowerPanel Linux software with SSMTP to send email alerts on a power failure.
Please note if your router and modem are not on a UPS or your internet fails during a power outage this process will be useless.
Install PowerPanel and make sure it can see your UPS by running “pwrstat – status”
Install SSMTP “apt-get install SSMTP” and edit the config file located at “etc/ssmtp/ssmtp.conf”. My config is using zoho as the SMTP host.
# # Config file for sSMTP sendmail # # The person who gets all mail for userids < 1000 # Make this empty to disable rewriting. email@example.com # 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.zoho.com:465 # Where will the mail seem to come from? rewriteDomain=email.com # The full hostname hostname=my # 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 AuthUserfirstname.lastname@example.org AuthPass=password AuthMethod=LOGIN UseTLS=YES
Create a file, “nano /etc/pwrstatd-email-ssmtp.sh” and paste the below script into that file. Modify the location, set your from address to be the same as SSMTP, set the to address to the email you want to receive the alert at.
# This is sample script of the send mail for pwrstatd daemon using SSMTP. #!/bin/sh LOCATION="HOME" SUBJECT="$EVENT - $LOCATION" FROM="email@example.com" TO="firstname.lastname@example.org" DATE=`date +'%Y/%m/%d %p %H:%M'` MESSAGE="Warning: $EVENT at $LOCATION has occurred for 30 seconds! \nEvent Time: $DATE \nEvent Type: $EVENT \nBattery Capacity> printf "To: $TO \nFrom: $FROM \nSubject: $SUBJECT \n\n$MESSAGE" | ssmtp "$TO" \ exit 0
Next we need to modify the PowerPanel software to call this file when the power goes out. “nano /etc/pwrstatd.conf” and edit powerfail-cmd-path to the new file we created “nano /etc/pwrstatd-email-ssmtp.sh”. Here is a sample of my file
# # pwrstatd configuration file # # You must restart pwrstatd after changing this file in order for changes to take effect. # Ex:/etc/init.d/pwrstatd restart # # Action setting for event of Power Failure # # A delay time in seconds since event of Power Failure occur then to run shell # script and shutdown system. Allowed range is 0 ~ 3600. Default is 60 sec. powerfail-delay = 30 # Enable to run shell script when the event of Power Failure occur. # The allowed options are yes and no. Default is yes. powerfail-active = yes # Assign a path of script file for event of Power Failure. # The default is /etc/pwrstatd-powerfail.sh powerfail-cmd-path = /etc/pwrstatd-email-ssmtp.sh # How much time in seconds to take script running for event of Power Failure. # The allowed range is 0 ~ 3600. Default is 0 sec. powerfail-duration = 1 # Allow Daemon to shutdown system for event of Power Failure. # The allowed options are yes and no. Default is yes. powerfail-shutdown = no
Make sure you restart the service “/etc/init.d/pwrstatd restart”.
You have now configured PowerPanel to use SSMTP to send you an email if utility power goes out. If you have any questions or comments leave them below!