http://ubuntuforums.org/showthread.php?t=2186751
Keeps an eye on UPS state. If UPS is on battery, and falls below a certain percentage, the script runs whatever code you want, and suspends/hibernates/powers off the system.
See the ubuntu forums link above for a full description.