Using UPS buzzer as a method of determining AC power
You can plug an AC to DC adapter to the mains. the output goes through a voltage divider to one of Rpi's IO. you can buy small USB adapters for as cheap as 2$. Now you can know when the mains goes off.

Powering the Rpi from a UPS is a very bad idea unless the UPS is actually used for some equipment or appliances. Check the quiescent power of the UPS. It's probably much more what the Rpi is consuming so you should know that the conversion efficiency of the inverter will be very low when you are consuming a small portion of the UPS power (which is the case you are only powering the Rpi) and will not be anywhere near the advertised efficiency.
Simply buy a battery charger to charge the batteries along with a switching DC-DC converter to power your electronics. That will be more efficient and much cheaper (obvious) than buying a UPS!