July 11, 2009
Meuon
0 comments
keywords:
| APC 10KVA UPS monitoring via SNMP |
First you have to find the right MIB for your ups. This one is a "Smart-UPS RT 10000 XL" from APC. The real trick is using the right mib file with the -m "./mibfile.mib" command line syntax. The quotes make a lot of difference. The same trick works for snmpwalk and other snmp utilities. I'm running a much fancier version of what I have below in a production setting, but this is a good starting place and has the essentials working.
Sure beats serial cables and Java runtimes for the "official APC method" and you can run this on multiple servers, each with their own decision tree and set of commands. ie: Keep the mission critical stuff up the longest, drop the junk you don't need quickly and make that UPS last longer.
#!/usr/bin/perl #This is as simple of an APC power monitor as I could make. #Should be run as a cron job every 5 minutes or less. replace 192.168.192.4 with the IP of your UPS.
$shutdownthreshhold = 20 ; open(IN,"/usr/bin/snmpget -v1 -c public -m "/home/juice/apc/powernet395.mib" 192.168.192.4 PowerNet-MIB::upsAdvBatteryCapacity.0 |") ; while(<IN>) { @d = split(/ /) ; $capacity = $d[3] * 1 ; } ; open(IN,"/usr/bin/snmpget -v1 -c public -m "/home/juice/apc/powernet395.mib" 192.168.192.4 PowerNet-MIB::upsBasicOutputStatus.0 |") ; while(<IN>) { @d = split(/ /) ; $status = $d[3] ; chop($status) ; } ; open(OUT,">/tmp/powercheck") ; print OUT "Battery Capacity: $capacity percent Battery Status: $status Shutdown at $shutdownthreshhold" ; close(OUT) ;
if($status eq 'onBattery(3)') { if($capacity < $shutdownthreshhold) { print "SHUTDOWN " ; system("/sbin/shutdown -P now") ; #standard Linux shutdown, -P is power off } ;
} ;
|
| |