Common problem in computer-rooms.
In larger deployments you usually have a UPS with a LAN -interface that can broadcast the shutdown to other computers.
In smaller setups with a USB connected UPS the computer that is directly connected is responsible to sending the message to the others.
Most UPS monitor software has features for both scenarios.
(APC PowerChute or the open source NUT. Just to name 2 of the more well-known software packages.)
You determine what is the longest shutdown-time among all computers/devices. You add some safety margin to that (3-5 minutes) and you configure the UPS (or the monitoring computer) to send out the "shutdown now!" command to everyone that many minutes prior to the USP battery being completely depleted.
That should give everybody time enough to be safely shut down.
Obviously you will have to have the network equipment on the UPS too.
E.g Say you find that the slowest systems need about 5 minutes to shutdown. + 5 minutes safety-margin = 10 minutes.
So the shutdown command is send out 10 minutes before the UPS is really empty.
P.S. You DON'T want to go to shutdown immediately when the UPS switches to battery power, because chances are it is just a short spike and normal power is back in a few seconds.
And typical outage patterns in your locality may also determine exactly how you schedule things.
(I once had to setup a deployment were each day at 21:00 the power-grid would go unstable for 5 to 10 minutes. Pottery factory next door that fired up a large kiln every night at 21:00. This would cause our UPS to kick in for a couple of seconds several times between 21:00 and 21:10.)