XYMon CyberPower Monitoring Ubuntu
XYMon CyberPower Monitoring CentOS
PowerFail = Any event like losing power, if active, will initate sript if you lose power for 1 second, generally not wanted
lowbatt = This is what you want, do X when Battery gets to Level Y
cat << 'EOL' >/etc/pwrstatd.conf #!/bin/sh powerfail-active = no powerfail-cmd-path = /etc/pwrstatd-powerfail.sh powerfail-delay = 0 powerfail-duration = 0 powerfail-shutdown = no lowbatt-active = yes lowbatt-cmd-path = /etc/pwrstatd-lowbatt.sh lowbatt-shutdown = yes lowbatt-threshold = 35 runtime-threshold = 600 lowbatt-duration = 1 shutdown-sustain = 60 enable-alarm = yes turn-ups-off = yes ups-polling-rate = 3 ups-retry-rate = 10 prohibit-client-access = no hibernate = no EOL chmod 755 /etc/pwrstatd.conf
I like to do everything in shutdown.sh
sudo rm /etc/pwrstatd-*
Shutdown the Host and/or Other Servers & send E-Mail Alerts
cat << 'EOL' >/etc/shutdown.sh #!/bin/bash email=alert@domain.com remotehost=AnotherServer echo "The Server $remotehost is about to shutdown due to Low UPS Power" | mail -s "UPS Notification for $remotehost" "$email" ssh root@"$remotehost" "sudo shutdown -h now" host=Server echo "The Server $host is about to shutdown due to Low UPS Power" | mail -s "UPS Notification for $host" "$email" shutdown -h now EOL chmod +x /etc/shutdown.sh
VMWare UPS VM Host Shutdown
cat << 'EOL' >/etc/shutdown.sh #!/bin/bash host=ESXiHost email=alert@domain.com echo "The VMWare ESXi VM Server $host is about to shutdown due to Low UPS Power" | mail -s "UPS Notification for $host" "$email" ssh root@"$host" "/sbin/shutdown.sh && /sbin/poweroff" EOL chmod +x /etc/shutdown.sh
Triple Check Permissions, as this will fail without correct permissions, and that's a lame reason to have this fail!
chmod +x /etc/shutdown.sh
Restarted Daemon to make changes take effect immediately!
sudo service pwrstatd restart && sudo pwrstat -config && sudo pwrstat -status