PDU Nagios

From Secure Computing Wiki
Revision as of 13:19, 30 May 2008 by Ecrist (Talk | contribs) (Requirements)

Jump to: navigation, search
We've recently acquired a Tripp Lite PDUMH20ATNET, which is a power-switching appliance. We're using it at our data center, where there was a recent PDU failure. Since we were on the PDU that failed, and we only had power connections to that single PDU, we lost all of our systems.

Going forward, we've added a second PDU circuit to our rack and have the Tripp Lite PDU switch for our single-power supply systems such as switches and a couple routers. Having this unit would help mitigate further problems, but as this unit supports SNMP monitoring, I've written a script that allows Nagios to poll via SNMP the input and output voltages, frequency, and output current.

In addition, check out the PDU Cacti page for the cacti graphs I've created, along with the perl script to go along with it.


This script has the following prerequisites:

  1. Perl 5.8.8 or newer (may work with older versions, I'm not perl expert.)
  2. SNMP Perl Module (/usr/ports/net-mgmt/p5-SNMP-Utils on FreeBSD)
  3. SNMP MIBs.

Perl Script

Here's the perl script. This requires the SNMP perl module, as well as the obligatory nagios perl modules, be installed.

#use warnings;

use SNMP; # requires net-mgmt/p5-SNMP-Utils
use lib "/usr/local/libexec/nagios";
use utils qw(%ERRORS);

my $usage = '
Usage: ${0} hostname snmp_community key min max

Connects via SNMP to a UPS or PDU and pulls Input/Output
voltages and frequencies, as well as current output (amps).

hostname is the name of the host youi\'re checking
snmp_community is the SNMP community string for authenticaiton
key, is the specific key you\'re requesting, from:
        inputf......Input Frequency
        inputv......Input Voltage
        outputf.....Output Frequency
        outputv.....Output Voltage
        outputc.....Output Current

This script outputs performance data compatible with Nagios.

$ENV{'MIBS'} = "ALL";
$host = $ARGV[0]; die $usage unless defined $host;
$community = $ARGV[1]; die $usage unless defined $community;
$key = $ARGV[2]; die $usage unless defined $key;
$min = $ARGV[3]; die $usage unless defined $min;
$max = $ARGV[4]; die $usage unless defined $max;

$session = new SNMP::Session (DestHost => $host, Community => $community, Version => "2c");
$oids = new SNMP::VarList (['UPS-MIB::upsIdentManufacturer'],   #0
                           ['UPS-MIB::upsIdentModel'],          #1
                           ['UPS-MIB::upsInputVoltage'],        #2
                           ['UPS-MIB::upsInputFrequency'],      #3
                           ['UPS-MIB::upsOutputVoltage'],       #4
                           ['UPS-MIB::upsOutputFrequency'],     #5
                           ['UPS-MIB::upsOutputCurrent']);      #6

@status = $session->getnext($oids);
$manuf = $status[0];
$model = $status[1];
$inputv = $status[2];
$inputf = $status[3]/10;
$outputv = $status[4];
$outputf = $status[5]/10;
$outputc = $status[6]/10;

if (($min < $${key}) and ($${key} < $max)){
        print "NORMAL: $manuf($model) $$key | inputf=${inputf}";
        exit $ERRORS{'OK'};
} else {
        print "CRITICAL: $manuf($model) $$key | intputf=${inputf}";
        exit $ERRORS{'CRITICAL'};