Basal Synthesis GmbH Apcupsd
Apcupsd
In OPNsense, Apcupsd provides essential UPS (Uninterruptible Power Supply) management capabilities, particularly for APC UPS devices. This integration ensures that during power outages, the system can manage power efficiently, triggering safe shutdown procedures to protect data integrity and prevent hardware damage. By continuously monitoring the UPS status, Apcupsd enhances the reliability and resilience of network infrastructure, making OPNsense a more robust solution for environments where power stability is critical.
Configurations
- Install Apcupsd plugin in Opnsense
- Connect UPS hardware with Opnsense hardware with a usb cable. The plugin detect this connection automatically.
- Set the setting in the UI:
- Define the code in the path /usr/local/etc/apcupsd/offbattery
#!/bin/sh
# Find the shessl script under /etc/apcupsd
# /etc/apcupsd/apccontrol calls the script if
# the UPS falls back to main after energy failure.
# An e-mail message will be sent to root.
echo "$(date) - offbattery script started" >> /var/log/apcupsd_eventscripts.log
HOSTNAME="APC Back-UPS"
MSG="$HOSTNAME UPS $1 Power has returned"
(
echo "Subject: $MSG"
echo " "
echo "$MSG"
echo " "
/usr/local/sbin/apcaccess status
) | $APCUPSD_MAIL -s "$MSG" $SYSADMIN
# Wake up the hardware, which is necessary.
wake igb0 macaddress
if [ $? -eq 0 ]; then
echo "Magic packet sent successfully" >> /var/log/apcupsd_eventscripts.log
else
echo "Failed to send magic packet" >> /var/log/apcupsd_eventscripts.log
fi
# Wait for a minute to allow the server to wake up
sleep 60
- Define the code in the path /usr/local/etc/apcupsd/onbattery
#!/bin/sh
# This shell script if placed in /etc/apcupsd
# will be called by /etc/apcupsd/apccontrol when the UPS
# goes on batteries.
# We send an email message to root to notify him.
# This script send a command to run a shutDown script on a server to make a secure shutdown.
echo "$(date) - onbattery script started" >> /var/log/apcupsd_eventscripts.log
HOSTNAME=`hostname`
MSG="$HOSTNAME UPS $1 Power Failure !!!"
(
echo "Subject: $MSG"
echo " "
echo "$MSG"
echo " "
/usr/local/sbin/apcaccess status
) | $APCUPSD_MAIL -s "$MSG" $SYSADMIN
if ssh -o BatchMode=yes user@server.example.com "sudo /path/to/script/script.sh" >> /var/log/apcupsd_eventscripts.log 2>&1; then
echo "$(date) - The /path/to/script/script.sh on server executed successfully" >> /var/log/apcupsd_eventscripts.log
else
echo "$(date) - The /path/to/script/script.sh on server executed failed" >> /var/log/apcupsd_eventscripts.log
fi
echo "$(date) - onbattery script finished" >> /var/log/apcupsd_eventscripts.log
exit 0
Status
Look at the status, if all configurations are correct it looks like:
Dashboard
The Dashboard automatically added a widget for apcupsd. I looks like:
Logs
The apcupsd also have log: