I'd say /tool netwatch is your friend.
It does exactly what you need, just fill in scripts for up/down that will fire on these events.
But it might get tricky b/c the script is only fired once, not every time the target gets checked.
So you might add another netwatch item which monitors your UPS. Once that goes down, it disables the netwatch item for the server.
Once the UPS is back online, the server netwatch item will be enabled again. Now checks the server, detects that it's down and triggers the WoL script.
I'd suggest to start that up script with a delay of a minute or so, just to make sure the server definitely has AC power again.
MTCNA, MTCUME, MTCWE
There are 10 types of people: Those who understand binary and those who don't.
There are two types of people: Those who can extrapolate from incomplete data