Added RPM spec file to apc checks

This commit is contained in:
Tómas Edwardsson 2010-08-11 22:28:59 +00:00
parent dc4030c67d
commit 033820d6c3
6 changed files with 1093 additions and 0 deletions

View File

@ -0,0 +1 @@
check_apcext.pl - APC Extra gear checks (netbotz/pdus)

View File

@ -0,0 +1,447 @@
#!/usr/bin/perl
#
# check_apcext.pl - APC Extra gear monitoring plugin for Nagios
# 05.02.07 Paul Venezia
#
# v0.0.1
#
#
use Net::SNMP;
use Getopt::Std;
use Data::Dumper;
use vars qw/ %opt /;
use strict;
sub getmasked_values ($$);
if ($ARGV[0] =~ /(--help|-h|help)/ || !defined$ARGV[0]) {
&usage;
exit 0;
}
my $opts = 's:lmC:H:p:w:c:';
getopts ( "$opts", \%opt ) or &usage;
my $host = $opt{H};
my $comm = $opt{C};
my $param = $opt{p};
my $warn = $opt{w};
my $crit = $opt{c};
my $metric = $opt{m};
my $list = $opt{l};
my $sensor_int_name = $opt{s};
my ($oid, $oidbase, $fval, $unit, $outmsg);
my $retval = 0;
my %rpduamps;
my %oids = (
'nbmstemp' => {
'label' => 'Temp',
'unit' => ($metric ? 'degC' : 'degF'),
'oidbase' => '.1.3.6.1.4.1.5528.100.4.1.1.1',
'sensor_key' => 5,
'sensor_val' => 2,
'cdef' => ($metric ? '$val * 0.1' : '($val * .18) + 32')
},
'nbmshum' => {
'label' => 'Humidity',
'unit' => '%',
'oidbase' => '.1.3.6.1.4.1.5528.100.4.1.2.1',
'sensor_key' => 5,
'sensor_val' => 8,
},
'nbmsairflow' => {
'label' => 'Air Flow',
'unit' => 'CFM',
'oidbase' => '.1.3.6.1.4.1.5528.100.4.1.5.1',
'sensor_val' => 8,
'sensor_key' => 5,
'mod' => 'lt'
},
'nbmsaudio' => {
'label' => 'Audio Level',
'unit' => '',
'oidbase' => '.1.3.6.1.4.1.5528.100.4.1.4.1',
'sensor_val' => 7,
'sensor_key' => 5,
'mod' => ''
},
'rpduamps' => {
'label' => 'Power Output',
'unit' => 'Amps',
'oid' => '.1.3.6.1.4.1.318.1.1.12.2.3.1.1.2.',
'cdef' => '$val * .10'
},
'acscstatus' => {
'label' => 'Status',
'unit' => '',
'oid' => '.1.3.6.1.4.1.318.1.1.13.3.4.1.2.1.0'
},
'acscload' => {
'label' => 'Cooling Load',
'unit' => 'kW',
'oid' => '.1.3.6.1.4.1.318.1.1.13.3.4.1.2.3.0',
'cdef' => '$val * .10'
},
'acscoutput' => {
'label' => 'Cooling output',
'unit' => 'kW',
'oid' => '.1.3.6.1.4.1.318.1.1.13.3.4.1.2.2.0',
'cdef' => '$val * .10'
},
'acscsupair' => {
'label' => 'Supply Air',
'unit' => 'F',
'oid' => '.1.3.6.1.4.1.318.1.1.13.3.4.1.2.8.0',
'cdef' => '$val * .10'
},
'acscretair' => {
'label' => 'Return Air',
'unit' => 'F',
'oid' => '.1.3.6.1.4.1.318.1.1.13.3.4.1.2.10.0',
'cdef' => '$val * .10'
},
'acscairflow' => {
'label' => 'Airflow',
'unit' => 'CFM',
'oid' => '.1.3.6.1.4.1.318.1.1.13.3.4.1.2.4.0',
},
'acscracktemp' => {
'label' => 'Rack Inlet Temp',
'unit' => 'F',
'oid' => '.1.3.6.1.4.1.318.1.1.13.3.4.1.2.6.0',
'cdef' => '$val * .10'
},
'acsccondin' => {
'label' => 'Cond Inlet Temp',
'unit' => 'F',
'oid' => '.1.3.6.1.4.1.318.1.1.13.3.4.1.2.30.0',
'cdef' => '$val * .10'
},
'acsccondout' => {
'label' => 'Cond Outlet Temp',
'unit' => 'F',
'oid' => '.1.3.6.1.4.1.318.1.1.13.3.4.1.2.28.0',
'cdef' => '$val * .10'
},
'acrcstatus' => {
'label' => 'Status',
'unit' => '',
'oid' => '.1.3.6.1.4.1.318.1.1.13.3.2.2.2.1.0'
},
'acrcload' => {
'label' => 'Cooling Load',
'unit' => 'kW',
'oid' => '.1.3.6.1.4.1.318.1.1.13.3.2.2.2.2.0',
'cdef' => '$val * .10'
},
'acrcoutput' => {
'label' => 'Cooling Output',
'unit' => 'kW',
'oid' => '.1.3.6.1.4.1.318.1.1.13.3.2.2.2.3.0',
'cdef' => '$val * .10'
},
'acrcairflow' => {
'label' => 'Airflow',
'unit' => 'CFM',
'oid' => '.1.3.6.1.4.1.318.1.1.13.3.2.2.2.4.0'
},
'acrcracktemp' => {
'label' => 'Rack Inlet Temp',
'unit' => 'F',
'oid' => '.1.3.6.1.4.1.318.1.1.13.3.2.2.2.6.0',
'cdef' => '$val * .10'
},
'acrcsupair' => {
'label' => 'Supply Air',
'unit' => 'F',
'oid' => '.1.3.6.1.4.1.318.1.1.13.3.2.2.2.8.0',
'cdef' => '$val * .10'
},
'acrcretair' => {
'label' => 'Return Air',
'unit' => 'F',
'oid' => '.1.3.6.1.4.1.318.1.1.13.3.2.2.2.10.0',
'cdef' => '$val * .10'
},
'acrcfanspeed' => {
'label' => 'Fan Speed',
'unit' => '%',
'oid' => '.1.3.6.1.4.1.318.1.1.13.3.2.2.2.16.0',
'cdef' => '$val * .10',
},
'acrcfluidflow' => {
'label' => 'Fluid Flow',
'unit' => 'GPM',
'oid' => '.1.3.6.1.4.1.318.1.1.13.3.2.2.2.21.0',
'cdef' => '$val * .10',
'mod' => 'lt'
},
'acrcflenttemp' => {
'label' => 'Entering Fluid Temp',
'unit' => 'F',
'oid' => '.1.3.6.1.4.1.318.1.1.13.3.2.2.2.23.0',
'cdef' => '$val * .10'
},
'acrcflrettemp' => {
'label' => 'Returning Fluid Temp',
'unit' => 'F',
'oid' => '.1.3.6.1.4.1.318.1.1.13.3.2.2.2.25.0',
'cdef' => '$val * .10'
},
);
if ($list) {
my ($baseoid, $int_name_id, $value_id) = @_;
my ($session, $error) = Net::SNMP->session(
-hostname => $host,
-community => $comm,
-version => 1,
# -translate => [-octetstring => 0x0],
-port => "161"
);
my $response = $session->get_table(-baseoid => ".1.3.6.1.4.1.5528.100.2.1.1");
my $err = $session->error;
if ($err){
$retval = 3;
$outmsg = "UNKNOWN";
$session->close();
print "$outmsg $err - SNMP Error connecting to $host\n";
exit $retval;
}
my %sensor;
foreach my $k (keys %{$response}) {
my ($type, $id) = (split(/\./, $k))[-2,-1];
next if ($type != 1 and $type != 4);
next if ($id < 2000000000);
if ($type == 1) {
$sensor{$id}->{"int_name"} = $response->{$k};
} else {
$sensor{$id}->{"friendly_name"} = $response->{$k};
}
}
print <<" EO";
Specify a sensor by using the -s and the INTERNAL name of the sensor
Detected sensors:
EO
printf("\t%-32s %s\n", "Friendly Name", "Internal Name");
foreach my $id (sort { $sensor{$a}->{"friendly_name"} cmp $sensor{$b}->{"friendly_name"} } keys %sensor) {
printf ("\t%-32s %s\n", "\"$sensor{$id}->{friendly_name}\"", "\"$sensor{$id}->{int_name}\"");
}
exit 0;
} elsif (!$oids{$param}) {
print "No test parameter specified";
exit 3;
} else {
$oid = $oids{$param}->{oid};
$oidbase = $oids{$param}->{oidbase};
}
my ($session, $error) = Net::SNMP->session(
-hostname => $host,
-community => $comm,
-version => 1,
# -translate => [-octetstring => 0x0],
-port => "161"
);
if ($param eq "rpduamps") {
# $param = "RackPDU";
my $i;
for ($i=1;$i<4;$i++) {
my $phoid = $oid . $i;
my $response = $session->get_request($phoid);
my $err = $session->error;
if ($err){
$retval = 3;
$outmsg = "UNKNOWN";
$session->close();
print "$outmsg $err - SNMP Error connecting to $host\n";
exit $retval;
}
$rpduamps{$i} = $response->{$phoid};
}
$session->close;
#$crit = ($crit * 10);
#$warn = ($warn * 10);
$unit = "Amps";
foreach my $ph ( sort keys %rpduamps ) {
my $tphase = ($rpduamps{$ph} * .1);
if (($tphase >= $crit) && ($retval < 2)) {
$retval = 2;
$outmsg = "CRITICAL";
} elsif (($tphase >= $warn) && ($retval < 1)) {
$retval = 1;
$outmsg = "WARNING";
} elsif ($retval < 1) {
$retval = 0;
$outmsg = "OK";
}
$fval .= "Phase $ph: " . $tphase;
#$fval .= "Phase $ph: " . ($tphase * .1);
if ($ph lt 3) {
$fval .= " Amps, ";
#} else {
# $fval .= " ";
}
}
} else {
my $val;
if ($oid) {
my $response = $session->get_request($oid);
my $err = $session->error;
if ($err){
$retval = 3;
$outmsg = "UNKNOWN";
$session->close();
print "$outmsg $err - SNMP Error connecting to $host\n";
exit $retval;
}
$val = $response->{$oid};
$session->close();
} else {
my $snmpd = getmasked_values($oidbase, { $oids{$param}->{sensor_key} => 'sensor_key',
$oids{$param}->{sensor_val} => 'sensor_val' });
if ((keys %{$snmpd}) > 1 && !$sensor_int_name) {
print "UNKNOWN - Many sensors found but none specified, see -s and -l\n";
exit 3;
} elsif ((keys %{$snmpd}) == 0) {
print "UNKNOWN - no sensors found on this device\n";
exit 3;
} else {
my $id = (keys %{$snmpd})[0];
$val = $snmpd->{$id}->{sensor_val};
}
if ($sensor_int_name) {
foreach my $k (keys %{$snmpd}) {
if (lc($snmpd->{$k}->{sensor_key}) eq lc($sensor_int_name)) {
$val = $snmpd->{$k}->{sensor_val};
}
}
}
if ($val eq "") {
print Dumper $snmpd;
print "UNKNOWN Unable to get sensor status\n";
exit 3;
}
}
if ($param eq "acscstatus" || $param eq "acrcstatus") {
if ($val == 1) {
$fval = "Standby";
$retval = 1;
$outmsg = "WARNING";
} elsif ($val == 2) {
$fval = "On";
$retval = 0;
$outmsg = "OK";
}
} else {
if ($oids{$param}->{cdef}) {
$fval = eval "$oids{$param}->{cdef}";
} else {
$fval = $val;
}
if ($fval > $crit) {
$retval = 2;
$outmsg = "CRITICAL";
} elsif ($fval > $warn) {
$retval = 1;
$outmsg = "WARNING";
} else {
$retval = 0;
$outmsg = "OK";
}
}
}
print "$outmsg - " . $oids{$param}->{label} . " " .$fval . " " . $oids{$param}->{unit} . " | $param=$fval$oids{$param}->{unit}\n";
exit $retval;
sub usage {
print "Usage: $0 -H <hostip> -C <community> -p <parameter> -w <warnval> -c <critval> [-l] [-s sensor]\n";
print "\nParameters:\n";
print <<" EO";
APC NetBotz
nbmstemp NetBotz main sensor temp | nbmshum NetBotz main sensor humidity
nbmsairflow NetBotz main sensor airflow | nbmsaudio NetBotz main sensor audio
-l List connected sensors | -s sensor Sensor we want info from
APC Metered Rack PDU
rpduamps Amps on each phase
APC ACSC In-Row
acscstatus System status (on/standby) | acscload Cooling load
acscoutput Cooling output | acscsupair Supply air
acscairflow Air flow | acscracktemp Rack inlet temp
acsccondin Condenser input temp | acsccondout Condenser outlet temp
APC ACRC In-Row
acrcstatus System status (on/standby) | acrcload Cooling load
acrcoutput Cooling output | acrcairflow Air flow
acrcracktemp Rack inlet temp | acrcsupair Supply air
acrcretair Return air | acrcfanspeed Fan speed
acrcfluidflow Fluid flow | acrcflenttemp Fluid entering temp
acrcflrettemp Fluid return temp
EO
exit 3;
}
sub getmasked_values ($$) {
my ($baseoid, $values) = @_;
my ($session, $error) = Net::SNMP->session(
-hostname => $host,
-community => $comm,
-version => 1,
-port => "161"
);
my $response = $session->get_table(-baseoid => $baseoid);
my $err = $session->error;
if ($err){
$retval = 3;
$outmsg = "UNKNOWN";
$session->close();
print "$err - SNMP Error connecting to $host\n";
exit $retval;
}
my %snmpdata;
foreach my $k (keys %{$response}) {
my ($type, $id) = (split(/\./, $k))[-2,-1];
if ($values->{$type}) {
$snmpdata{$id}->{$values->{$type}} = $response->{$k};
}
}
return \%snmpdata;
}

View File

@ -0,0 +1,562 @@
#!/usr/bin/perl
# Copyright (C) 2004 Altinity Limited
# E: info@altinity.com W: http://www.altinity.com/
#
# Edited by Roderick Derks (roderick@r71.nl)
# I changed the output of this plugin so it can bu used with Nagiosgrapher
# to create nice graphs (output is in hours is changed to minutes).
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#
# Adjusted by Roderick Derks (roderick@r71.nl)
# Output of snmp query for remaing battery runtime is in minutes or in hours. This
# is a problem when you want to create some nice graphs because of the different
# output. Now hours are converted to minutes.
#
use Net::SNMP;
use Getopt::Std;
$script = "check_snmp_apcups";
$script_version = "2.1.0";
$metric = 1;
$ipaddress = "192.168.1.1"; # default IP address, if none supplied
$version = "1"; # SNMP version
$timeout = 2; # SNMP query timeout
# $warning = 100;
# $critical = 150;
$status = 0;
$returnstring = "";
$community = "public"; # Default community string
# .1.3.6.1.4.1.
# enterprises.318.1.1.1.1.1.1.0 = STRING: "SMART-UPS 1000" upsIdent
# enterprises.318.1.1.1.2.2.1.0 Battery capacity (%)
# enterprises.318.1.1.1.2.2.2.0 Temperature (Celcius)
# enterprises.318.1.1.1.2.2.3.0 Battery runtime remaining
# enterprises.318.1.1.1.2.2.4.0 Battery replace indicator (1=ok, 2=replace)
# enterprises.318.1.1.1.2.2.5.0 Number of battery packs
# enterprises.318.1.1.1.2.2.6.0 Number of bad battery packs
# enterprises.318.1.1.1.3.2.1.0 Input voltage
# enterprises.318.1.1.1.3.2.4.0 Input frequency
# enterprises.318.1.1.1.3.2.5.0 Reason for last transfer to UPS battery power:
# enterprises.318.1.1.1.4.2.1.0 Output voltage
# enterprises.318.1.1.1.4.2.2.0 Output frequency
# enterprises.318.1.1.1.4.2.3.0 Output load as % of capacity
# enterprises.318.1.1.1.4.2.4.0 Output current in ampheres
# enterprises.318.1.1.1.4.2.1.0 Configured voltage
# enterprises.318.1.1.1.8.1.0 Whether agent is communicating with UPS (1)
$oid_upstype = ".1.3.6.1.4.1.318.1.1.1.1.1.1.0";
$oid_battery_capacity = ".1.3.6.1.4.1.318.1.1.1.2.2.1.0";
$oid_battery_temperature = ".1.3.6.1.4.1.318.1.1.1.2.2.2.0";
$oid_battery_runtimeremain = ".1.3.6.1.4.1.318.1.1.1.2.2.3.0";
$oid_battery_replace = ".1.3.6.1.4.1.318.1.1.1.2.2.4.0";
$oid_input_voltage = ".1.3.6.1.4.1.318.1.1.1.3.2.1.0";
$oid_input_frequency = ".1.3.6.1.4.1.318.1.1.1.3.2.4.0";
$oid_input_reasonforlasttransfer = ".1.3.6.1.4.1.318.1.1.1.3.2.5.0";
$oid_output_voltage = ".1.3.6.1.4.1.318.1.1.1.4.2.1.0";
$oid_output_frequency = ".1.3.6.1.4.1.318.1.1.1.4.2.2.0";
$oid_output_load = ".1.3.6.1.4.1.318.1.1.1.4.2.3.0";
$oid_output_current = ".1.3.6.1.4.1.318.1.1.1.4.2.4.0";
$oid_output_configuredvoltage = ".1.3.6.1.4.1.318.1.1.1.4.2.1.0";
$oid_comms = ".1.3.6.1.4.1.318.1.1.1.8.1.0";
$oid_test_result = ".1.3.6.1.4.1.318.1.1.1.7.2.3.0";
$oid_test_date = ".1.3.6.1.4.1.318.1.1.1.7.2.4.0";
$oid_sysDescr = ".1.3.6.1.2.1.1.1.0";
$upstype = "";
$battery_capacity = 0;
$battery_temperature = 0;
$battery_runtimeremain = 0;
$battery_replace = "";
$input_voltage = 0;
$input_frequency = 0;
$input_reasonforlasttransfer = "";
$output_voltage = 0;
$output_frequency = 0;
$output_load = 0;
$output_current = 0;
$output_configuredvoltage = 0;
$outagecause = "";
$test_result = "";
$test_date = "";
# Do we have enough information?
if (@ARGV < 1) {
print "Too few arguments\n";
usage();
}
getopts("h:H:C:w:c:");
if ($opt_h){
usage();
exit(0);
}
if ($opt_H){
$hostname = $opt_H;
}
else {
print "No hostname specified\n";
usage();
}
if ($opt_C){
$community = $opt_C;
}
else {
}
# Create the SNMP session
my ($s, $e) = Net::SNMP->session(
-community => $community,
-hostname => $hostname,
-version => $version,
-timeout => $timeout,
);
main();
# Close the session
$s->close();
if ($returnstring eq ""){
$status = 3;
}
if ($status == 0){
print "Status is OK - $returnstring\n";
# print "$returnstring\n";
}
elsif ($status == 1){
print "Status is a WARNING level - $returnstring\n";
}
elsif ($status == 2){
print "Status is CRITICAL - $returnstring\n";
}
else{
print "Problem with plugin. No response from SNMP agent.\n";
}
exit $status;
####################################################################
# This is where we gather data via SNMP and return results #
####################################################################
sub main {
#######################################################
if (!defined($s->get_request($oid_comms))) {
if (!defined($s->get_request($oid_sysDescr))) {
$returnstring = "SNMP agent not responding";
$status = 1;
return 1;
}
else {
$returnstring = "SNMP OID does not exist";
$status = 1;
return 1;
}
}
foreach ($s->var_bind_names()) {
$temp = $s->var_bind_list()->{$_};
}
if ($temp eq "1"){
}
else {
append("SNMP agent not communicating with UPS");
$status = 2;
return 1;
}
#######################################################
if (!defined($s->get_request($oid_upstype))) {
if (!defined($s->get_request($oid_sysDescr))) {
$returnstring = "SNMP agent not responding";
$status = 1;
return 1;
}
else {
$returnstring = "SNMP OID does not exist";
$status = 1;
return 1;
}
}
foreach ($s->var_bind_names()) {
$upstype = $s->var_bind_list()->{$_};
}
#######################################################
if (!defined($s->get_request($oid_battery_capacity))) {
if (!defined($s->get_request($oid_sysDescr))) {
$returnstring = "SNMP agent not responding";
$status = 1;
return 1;
}
else {
$returnstring = "SNMP OID does not exist";
$status = 1;
return 1;
}
}
foreach ($s->var_bind_names()) {
$battery_capacity = $s->var_bind_list()->{$_};
}
#######################################################
if (!defined($s->get_request($oid_battery_temperature))) {
if (!defined($s->get_request($oid_sysDescr))) {
$returnstring = "SNMP agent not responding";
$status = 1;
return 1;
}
else {
$returnstring = "SNMP OID does not exist";
$status = 1;
return 1;
}
}
foreach ($s->var_bind_names()) {
$battery_temperature = $s->var_bind_list()->{$_};
}
#######################################################
if (!defined($s->get_request($oid_battery_runtimeremain))) {
if (!defined($s->get_request($oid_sysDescr))) {
$returnstring = "SNMP agent not responding";
$status = 1;
return 1;
}
else {
$returnstring = "SNMP OID does not exist";
$status = 1;
return 1;
}
}
foreach ($s->var_bind_names()) {
$battery_runtimeremain = $s->var_bind_list()->{$_};
}
# RRD if output is in hours, change it to minutes so we can make a nice graph
if ( $battery_runtimeremain =~ "hour" ) {
$battery_runtimeremain2 = "$battery_runtimeremain";
$battery_runtimeremain =~s/hour.*//g;
$battery_runtimeremain = $battery_runtimeremain*60;
$battery_runtimeremain = "$battery_runtimeremain minutes";
}
#######################################################
if (!defined($s->get_request($oid_battery_replace))) {
if (!defined($s->get_request($oid_sysDescr))) {
$returnstring = "SNMP agent not responding";
$status = 1;
return 1;
}
else {
$returnstring = "SNMP OID does not exist";
$status = 1;
return 1;
}
}
foreach ($s->var_bind_names()) {
$battery_replace = $s->var_bind_list()->{$_};
}
#######################################################
if (!defined($s->get_request($oid_input_voltage))) {
if (!defined($s->get_request($oid_sysDescr))) {
$returnstring = "SNMP agent not responding";
$status = 1;
return 1;
}
else {
$returnstring = "SNMP OID does not exist";
$status = 1;
return 1;
}
}
foreach ($s->var_bind_names()) {
$input_voltage = $s->var_bind_list()->{$_};
}
#######################################################
if (!defined($s->get_request($oid_input_frequency))) {
if (!defined($s->get_request($oid_sysDescr))) {
$returnstring = "SNMP agent not responding";
$status = 1;
return 1;
}
else {
$returnstring = "SNMP OID does not exist";
$status = 1;
return 1;
}
}
foreach ($s->var_bind_names()) {
$input_frequency = $s->var_bind_list()->{$_};
}
#######################################################
if (!defined($s->get_request($oid_input_reasonforlasttransfer))) {
if (!defined($s->get_request($oid_sysDescr))) {
$returnstring = "SNMP agent not responding";
$status = 1;
return 1;
}
else {
$returnstring = "SNMP OID does not exist";
$status = 1;
return 1;
}
}
foreach ($s->var_bind_names()) {
$input_reasonforlasttransfer = $s->var_bind_list()->{$_};
}
#######################################################
if (!defined($s->get_request($oid_output_voltage))) {
if (!defined($s->get_request($oid_sysDescr))) {
$returnstring = "SNMP agent not responding";
$status = 1;
return 1;
}
else {
$returnstring = "SNMP OID does not exist";
$status = 1;
return 1;
}
}
foreach ($s->var_bind_names()) {
$output_voltage = $s->var_bind_list()->{$_};
}
#######################################################
if (!defined($s->get_request($oid_output_frequency))) {
if (!defined($s->get_request($oid_sysDescr))) { $returnstring = "SNMP agent not responding";
$status = 1;
return 1;
}
else {
$returnstring = "SNMP OID does not exist";
$status = 1;
return 1;
}
}
foreach ($s->var_bind_names()) {
$output_frequency = $s->var_bind_list()->{$_};
}
#######################################################
if (!defined($s->get_request($oid_output_load))) {
if (!defined($s->get_request($oid_sysDescr))) {
$returnstring = "SNMP agent not responding";
$status = 1;
return 1;
}
else {
$returnstring = "SNMP OID does not exist";
$status = 1;
return 1;
}
}
foreach ($s->var_bind_names()) {
$output_load = $s->var_bind_list()->{$_};
}
#######################################################
if (!defined($s->get_request($oid_test_result))) {
if (!defined($s->get_request($oid_sysDescr))) {
$returnstring = "SNMP agent not responding";
$status = 1;
return 1;
}
else {
$returnstring = "SNMP OID does not exist";
$status = 1;
return 1;
}
}
foreach ($s->var_bind_names()) {
$test_result = $s->var_bind_list()->{$_};
}
#######################################################
if (!defined($s->get_request($oid_test_date))) {
if (!defined($s->get_request($oid_sysDescr))) {
$returnstring = "SNMP agent not responding";
$status = 1;
return 1;
}
else {
$returnstring = "SNMP OID does not exist";
$status = 1;
return 1;
}
}
foreach ($s->var_bind_names()) {
$test_date = $s->var_bind_list()->{$_};
}
#######################################################
$issue = "";
if ($input_reasonforlasttransfer eq "1"){
$outagecause = "No events"
}
elsif ($input_reasonforlasttransfer eq "2"){
$outagecause = "High line voltage"
}
elsif ($input_reasonforlasttransfer eq "3"){
$outagecause = "Brownout"
}
elsif ($input_reasonforlasttransfer eq "4"){
$outagecause = "Loss of mains power"
}
elsif ($input_reasonforlasttransfer eq "5"){
$outagecause = "Small temporary power drop"
}
elsif ($input_reasonforlasttransfer eq "6"){
$outagecause = "Large temporary power drop"
}
elsif ($input_reasonforlasttransfer eq "7"){
$outagecause = "Small spike"
}
elsif ($input_reasonforlasttransfer eq "8"){
$outagecause = "Large spike"
}
elsif ($input_reasonforlasttransfer eq "9"){
$outagecause = "UPS self test"
}
elsif ($input_reasonforlasttransfer eq "10"){
$outagecause = "Excessive input voltage fluctuation"
}
else {
$outagecause = "Cannot establish reason"
}
if ($test_result eq "1") {
$test_result_string = "Passed";
}
elsif ($test_result eq "2") {
$test_result_string = "Failed";
}
elsif ($test_result eq "4") {
$test_result_string = "In Progress";
}
else {
$test_result_string = "Unknown";
}
if ($battery_capacity < 50) {
$issue = $issue . "BATTERY CAPACITY WARNING! ";
$status = 1;
}
if ($output_load > 80) {
$status = 1;
$issue = $issue . "OUTPUT LOAD WARNING! ";
}
if ($test_result eq "2") {
$issue = $issue . "SELF TEST FAILED! ";
$status = 1;
}
if ($input_voltage < 1){
$status = 2;
$issue = $issue . "RUNNING ON BATTERY! ";
}
if ($battery_capacity < 25) {
$issue = $issue . "BATTERY RUNNING LOW! ";
$status = 2;
}
if ($output_load > 90) {
$issue = $issue . "HIGH OUTPUT LOAD! ";
$status = 2;
}
if ($battery_replace eq "2") {
$issue = $issue . "REPLACE BATTERY! ";
$status = 2;
}
# Modified by Pall Sigurdsson <palli@opensource.is> to add some perfdata
# Modified 2010-06-03
my $perfdata="| 'battery_capacity'=$battery_capacity% 'temperature'=$battery_temperature 'input_voltage'=$input_voltage input_frequency=$input_frequency output_voltage=$output_voltage output_frequency=$output_frequency output_load=$output_load%";
if ($status == 0){
$temp = sprintf "$upstype - BATTERY:(capacity $battery_capacity%%, temperature $battery_temperature C, runtime $battery_runtimeremain) INPUT:(voltage $input_voltage V, frequency $input_frequency Hz) OUTPUT:(voltage $output_voltage V, frequency $output_frequency Hz, load $output_load%%) SELF TEST:($test_result_string on $test_date) LAST EVENT:($outagecause) $perfdata";
}
else {
$temp = sprintf "$issue - $upstype - BATTERY:(capacity $battery_capacity%%, temperature $battery_temperature C, runtime $battery_runtimeremain) INPUT:(voltage $input_voltage V, frequency $input_frequency Hz) OUTPUT:(voltage $output_voltage V, frequency $output_frequency Hz, load $output_load%%) LAST EVENT:$outagecause $perfdata ";
}
append($temp);
}
####################################################################
# help and usage information #
####################################################################
sub usage {
print << "USAGE";
-----------------------------------------------------------------
$script v$script_version
Monitors APC SmartUPS via AP9617 SNMP management card.
Usage: $script -H <hostname> -c <community> [...]
Options: -H Hostname or IP address
-C Community (default is public)
-----------------------------------------------------------------
Copyright 2004 Altinity Limited
This program is free software; you can redistribute it or modify
it under the terms of the GNU General Public License
-----------------------------------------------------------------
USAGE
exit 1;
}
####################################################################
# Appends string to existing $returnstring #
####################################################################
sub append {
my $appendstring = @_[0];
$returnstring = "$returnstring$appendstring";
}

View File

@ -0,0 +1,41 @@
%define debug_package %{nil}
Summary: A Nagios plugin to check APC devices
Name: nagios-okplugin-apc
Version: 0.0.1
Release: 1%{?dist}
License: GPLv2+
Group: Applications/System
URL: http://opensource.ok.is/trac/wiki/Nagios-OKPlugin-APC
Source0: http://opensource.ok.is/trac/browser/nagios-plugins/check_apcext.pl/releases/nagios-okplugin-apc-%{version}.tar.gz
Requires: nagios-plugins
BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-root-%(%{__id_u} -n)
Packager: Tomas Edwardsson <tommi@ok.is>
%description
Checks APC devices, both netbotz and UPS
%prep
%setup -q
#perl -pi -e "s|/usr/lib|%{_libdir}|g" check_sip
%build
%install
rm -rf %{buildroot}
install -D -p -m 0755 check_apcext.pl %{buildroot}%{_libdir}/nagios/plugins/check_apcext.pl
install -D -p -m 0755 check_snmp_apc_ups %{buildroot}%{_libdir}/nagios/plugins/snmp_apc_ups
%clean
rm -rf %{buildroot}
%files
%defattr(-,root,root,-)
%doc README
%{_libdir}/nagios/plugins/*
%changelog
* Mon Mar 1 2010 Tomas Edwardsson <tommi@ok.is> 0.1-1
- Initial packaging

View File

@ -0,0 +1 @@
check_apcext.pl - APC Extra gear checks (netbotz/pdus)

View File

@ -0,0 +1,41 @@
%define debug_package %{nil}
Summary: A Nagios plugin to check APC devices
Name: nagios-okplugin-apc
Version: 0.0.1
Release: 1%{?dist}
License: GPLv2+
Group: Applications/System
URL: http://opensource.ok.is/trac/wiki/Nagios-OKPlugin-APC
Source0: http://opensource.ok.is/trac/browser/nagios-plugins/check_apcext.pl/releases/nagios-okplugin-apc-%{version}.tar.gz
Requires: nagios-plugins
BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-root-%(%{__id_u} -n)
Packager: Tomas Edwardsson <tommi@ok.is>
%description
Checks APC devices, both netbotz and UPS
%prep
%setup -q
#perl -pi -e "s|/usr/lib|%{_libdir}|g" check_sip
%build
%install
rm -rf %{buildroot}
install -D -p -m 0755 check_apcext.pl %{buildroot}%{_libdir}/nagios/plugins/check_apcext.pl
install -D -p -m 0755 check_snmp_apc_ups %{buildroot}%{_libdir}/nagios/plugins/snmp_apc_ups
%clean
rm -rf %{buildroot}
%files
%defattr(-,root,root,-)
%doc README
%{_libdir}/nagios/plugins/*
%changelog
* Mon Mar 1 2010 Tomas Edwardsson <tommi@ok.is> 0.1-1
- Initial packaging