0
Nagios module for monitoring the load on APC PDU Through SNMP
The script is made to work without the MIB’s installed and designed to use the threshold values set in the pdu itself, if you want to change this it should be fairly simple to understand and alter the code.
The code is release as is, under the GNU GPL v2 License, with no guarantee whatsoever:
#!/usr/bin/php
<?php
# Copyright (C) Mikkel Mikjaer Christensen, 2011
# Released under GNU GPL v2
DEFINE ("PDU_CURRENT_LOAD", "SNMPv2-SMI::enterprises.318.1.1.12.2.3.1.1.2.1");
DEFINE ("PDU_OVERLOAD_TRESHOLD", "SNMPv2-SMI::enterprises.318.1.1.12.2.2.1.1.4.1");
DEFINE ("PDU_NEAR_OVERLOAD_TRESHOLD", "SNMPv2-SMI::enterprises.318.1.1.12.2.2.1.1.3.1");
DEFINE ("PDU_LOW_LOAD_TRESHOLD", "SNMPv2-SMI::enterprises.318.1.1.12.2.2.1.1.2.1");
if (!@$argv[1])
{
die("Usage: check_apc.php <hostname>\n");
}
else
{
$hostname = $argv[1];
}
function getvalue($id)
{
global $hostname;
if (!$ret = @snmpget($hostname, 'public', $id))
{
die("CRITICAL: No response from pdu: $hostname\n");
die(2);
}
if (snmp_get_valueretrieval() & SNMP_VALUE_OBJECT) {
die("CRITICAL: No response from pdu: $hostname\n");
die(2);
}
else
{
$r = preg_split("/: /",$ret);
return $r[1];
}
}
$current=(getvalue(PDU_CURRENT_LOAD)/10);
$low=getvalue(PDU_LOW_LOAD_TRESHOLD);
$overload=getvalue(PDU_OVERLOAD_TRESHOLD);
$warning=getvalue(PDU_NEAR_OVERLOAD_TRESHOLD);
if (false) // Change to true for debug
{
print "Curent load : $current A\n";
print "Lowload threshold : $low A\n";
print "Overload threshold : $overload A\n";
print "Near overload treshold : $warning A\n";
}
if ($current < $low)
{
print("CRITICAL: PDU Underloaded by ".($low-$current)." A, total: $current A\n");
die(2);
} else if ($current > $overload)
{
print("CRITICAL: PDU Overloaded by ".($current-$overload)." A, total: $current A\n");
die(2);
} else if ($current > $warning) {
print("WARNING: PDU Within ".(($current-$overload) * -1)." A of overload, total: $current A\n");
die(1);
} else {
print("OK: Current load $current A\n");
die(0);
}
?>
