PowerChute Network Shutdown and multiple UPSes

I gotta tell you, APC’s PowerChute Network Shutdown (PCNS) has a shitty interface.

And shitty documentation.

I was using it to control a UPS in a rack, and I thought, well, I have other racks with other UPSes, do I need a PCNS instance for each one? And I started down the rabbit hole.

The answer is no, I don’t. A single PCNS instance can handle multiple UPSes (or groups of UPSes, even).

The secret sauce is in two places:

  1. The first is finding the place to add additional UPSes: Go to PowerChute Setup, choose advanced, and continue forward through the menu pages until you reach the UPS Details page. There you can add additional UPSes (or UPS “groups”). That took a bit of looking to find.
  2. The second, and important part, I couldn’t find documented anywhere. Rather than using Shutdown Settings, go to Configure Events. Configure each event you want to action with a command file (command files must be in your user_files directory on the PowerChute server, in my case that was in /opt/APC/PowerChute/user_files) and the script must exist before it can be associated with an event. So write your script, make it executable (I used bash files, but I’m sure Python would work).
    • The hidden part is the abstraction for multiple UPSes. I decided to use one for “PowerChute cannot communicate with NMC” as the test event and script. I
    • made a test bash script that uses the system logger. I cycled through $@ with a for loop and logged each arg received by PowerChute, and discovered that two of the args passed contain the UPS name. I discovered this by shutting off the switchport connecting the UPS to the network. This is a nondestructive way to test this functionality, as in, you don’t want to test UPS events by yoinking power, at least not unless you’re ready for the consequences. I found no documentation for script variables anywhere, I just assumed since the system supports multiple UPSes that it would include them, and tested for them, and found they were indeed there.
    • Once I have that, I can use PowerCLI for VMware (powershell plus some addons) to correlate events with the ESXi servers powered by the UPS. Example, query each ESXi server for running VMs and issue each a SUSPEND command, then shut down the ESXi server itself. This avoids VMs ungracefully losing power.

Hope this helps someone who might be looking for script variables for PowerChute.