Skip navigation.

exploreopera

| Help

Sign up | Help

Posts tagged with "snmp"

Windows SNMP UPS Support

, , ,

My last post went into my development of UPS support for the QNAP TS-109 Pro. I ended with the question of whether or not Windows support of my SNMP UPS monitor could be developed.

After a couple of days of frustration, the answer is Yes!

Windows has built-in support for UPS monitoring via a "minidriver" interface provided by a DLL.

The frustration started when I found I could not develop a DLL using Microsoft's C++ Express edition. Instead, I had to dig through my CD collection looking for an old copy of Visual C++ (5.0).

I haven't done any low-level Windows programming for ages, so it was a bit of a steep (re)learning curve figuring out how to setup DLL exports, manage threads and events, and do UDP network programming. My first attempt kept on crashing, until I found Microsoft's demo UPS driver, which worked fine. I copied my C code over that and suddenly my code started working fine too! :faint: Obviously some magic in the demo build environment.

It's still not quite perfect, as for some reason no notifications are being shown, even though they're selected. However, once a low battery state is signaled, my PC shuts down!

The minidriver listens out for three types of APC SNMP traps: 9 (power good), 5 (on battery), and 7 (battery low). It doesn't care where the trap came from, so it may not be good on an untrusted network!

Below is a ZIP of my DLL, if anyone is interested. Right click on the INF and select Install. Probably not, as it's only good for APC SNMP notifications, in which case you'll already have proper APC software.

upsmon.zip (12KB)

For building, I can't help with the compiler, but the Windows Device Driver DDK is very handy, as is the MSDN documentation on Writing UPS Minidrivers!

QNAP TS-109 Pro UPS Support

, , ,

I recently purchased a QNAP TS-109 Pro. This is basically a hard drive enclosure with a Linux box inside. It is a NAS (Network Attached Storage) and cannot connect directly to your computer. It's intended to be used as a standalone server, from which you can share files, host your web site, etc. That barely scratches the surface of what it can do.

Anyway, since it is a "full blown" computer, it doesn't like power failures too much. In fact, from reading the forums, a power failure at the wrong moment could create all sorts of problems. So, UPS support with an orderly shutdown in case of power failure was a must.

The problem is that the QNAP only supports UPSs from APC. None of my UPSs were compatible. What I did notice was that the QNAP did support remote UPS monitoring via SNMP. I'd not long finished a home brew NTP server and had a prototype board floating around doing nothing.



:idea: Solution - get this board to monitor the UPS state (the easy part) and report that to the QNAP via SNMP compatible with the APC protocol (the hard part).

I was very pleased at how well the prototype design matched the UPS monitoring requirements - two bi-colour LEDs to reflect the state of the battery (good/low) and mains power (good/fail), and the serial port with enough I/O pins to connect to the UPS monitoring port (which isn't a serial port, it just connects internally to a couple of relays inside the UPS).

The hard part was figuring out the SNMP protocol. It's sad, but there's no way anyone could implement it just from reading the specification documents. Far too much vital information just isn't there! Nevertheless, by looking at some Wireshark sample captures, using what little information made sense in the relevant RFCs, and then finally lots of trial-and-error building packets and seeing how Wireshark interpreted them, I was able to put together a working SNMP Trap packet the QNAP server understood. (Edit: After searching some more, I've found a lot of the binary structure can be explained by Basic Encoding Rules.)

The way the QNAP handles a remote UPS is very simple. It has an SNMP daemon that waits for a certain set of SNMP traps to be sent to it. Those traps indicate the UPS state. The config file /etc/config/ups_snmptrapd.conf on the QNAP has all the important details.

After all that, I now have a network-enabled UPS! Yay! :hat:

Next project - can my Windows XP computer do something with those SNMP traps? (Edit: The answer is: Yes!)
October 2008
SMTWTFS
September 2008November 2008
1234
567891011
12131415161718
19202122232425
262728293031