This story begins more or less like this with an innocent phone call (ed: names were changed because I wanted an excuse to write that the names were changed, how cool is it?):
> Hi Angelo, I need a UPS with a network card, a 1500VA is fine, what do you propose?
< Um let me think, APC as usual I guess, by when do you need it?
> Yesterday! [...]
< Okay, okay [...], there is this available, Smart-UPS lineup, seems ok, price X$
> I'll take it! I'll pay later as usual [:-p] thanks
Now what could have gone wrong with a simple UPS?
Here is a picture, or rather THE picture, that is worth more than a thousand words, more or less all of them expletive cut and colorful
The problem
The problem, or at least the source of the problem, is certainly me….
When I think about a UPS with a network card I assume that it has a web interface and supports SNMP.
NOPE!
APC, on the other hand, has seen fit to, shall we say, give an extra option to its customers: a Cloud platform, called SmartConnect, where my shiny new UPS can register and notify events with a virtually Auntie Bess-proof deployment.
Now all of this is certainly a plus for Auntie Bess, but for everyone else the little symbol in the image above should worry you a bit.
Basically zero local access by http/ssh/telnet and no SNMP support.
I guess the choice is then commercial, a way of tying you to the ubiquitous (sigh) “as a service” model (that alone would merit a separate discussion), and I go looking for supported integrations on SmartConnect: notifications only, by email or Slack or Teams.
That’s all.
Of a plain and simple straightforward API service to date no trace.
The solution
The solution, as is often the case, is to make the best out of what you have and know: a website and browser DevTools.
Leaving aside for the moment the login process which caused me quite a bit of trouble, I find that once authenticated the site uses REST endpoints to retrieve and update the status of my UPS:
-
The basic data and status of all registered devices
/api/v1/gateways
-
The basic data and status of the individual device
/api/v1/gateways/<gateway_id>
-
Detailed status of the individual device
/api/v1/gateways/<gateway_id>?collection=input,output,battery,network,main_outlet,switched_outlets
-
A sort of dictionary of possible states and event
/api/v1/dictionaries/en
Each of them returns the relevant data in JSON format, so come on, with the right patience and taking advantage of the work calm in August I can do it!
APC-ScrapConnect
APC-ScrapConnect is the name I gave to a little script I wrote to handle login and retrieve data.
I came up with the name thinking about the scraping it actually does to be able to login and how much of a cr*p this whole process was to get through.
From the initial URL to the actual login we have to go through like 7 different https calls each to be parsed for cookies and redirects set via javascript or for tokens to be used in the next call.
But obviously this interests me more than you, so here’s how to use it straight out of the manifest
|
|
And here’s the GitHub link to the full script to get started using it
It doesn’t end here
You may have seen that there is also a discovery option that is well suited to be integrated with Zabbix, if you are interested keep following us, I will also try to publish a dedicated template.