Last active
August 29, 2015 14:14
-
-
Save iDemonix/5d23d99036ed3930d572 to your computer and use it in GitHub Desktop.
Nagios/Icinga check for Austin Hughes PPS-02-S basic check of total amps on a given PDU level
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/perl -w | |
# check_ah_pdu_level.pl | |
# | |
# checks the total amps for a given bank on an Austin Hughes PPS-02-S | |
# author Dan Walker | |
# email [email protected] | |
# created 2015-01-30 | |
use strict 'vars'; | |
use Net::SNMP qw(ticks_to_time);; | |
use Switch; | |
use Getopt::Std; | |
use Time::Local; | |
my $script_name = 'check_ah_pdu_level.pl'; | |
my $script_version = '1.0'; | |
# Command arguments | |
# H = hostname | |
# C = community | |
# w = warning level | |
# c = critical level | |
# p = port (SNMP) | |
# t = timeout | |
# L = level | |
# z = zero | |
my %options=(); | |
getopts("H:C:p:t:w:c:L:z", \%options); | |
my $help_info = <<END; | |
\n$script_name - v$script_version | |
Check total amps on an Austin Hughes PPS-02-S for a given bank | |
Usage: | |
-H\tAddress of hostname of PDU | |
-C\tSNMP community string | |
-p\tSNMP port (optional, defaults to port 161) | |
-t\tConnection timeout (optional, default 30s) | |
-w\tWarning threshold (optional, default 6) | |
-c\tCritical threshold (optional, default 8) | |
-l\tLevel - refers to daisy-chained PDUs (optional, default 1) | |
-z\tZero - if set, will return critical if level is 0 | |
Example: | |
$script_name -H pdu1.rack1.place -C public -w 13 -c 15 | |
END | |
# check OIDs | |
my $oid_totalamps = ".1.3.6.1.4.1.34550.20.2.1.1.1.14"; # Total AMP count OID | |
# exit codes | |
my $exit_ok = 0; | |
my $exit_warning = 1; | |
my $exit_critical = 2; | |
my $exit_unknown = 3; | |
# options | |
my $opt_host = $options{H}; | |
my $opt_comm = $options{C}; | |
my $opt_warn = $options{w} || 6; | |
my $opt_crit = $options{c} || 8; | |
my $opt_port = $options{p} || 161; | |
my $opt_time = $options{t} || 30; | |
my $opt_level = $options{L} || 1; | |
my $opt_zero = $options{z} || 0; | |
# SNMP vars | |
my $session; | |
my $error; | |
# check for arguments | |
if(!defined $options{H} || !defined $options{C}){ | |
print "$help_info\nNot all required options were specified.\n\n"; | |
exit $exit_unknown; | |
} | |
# basic sanity checks | |
if ( $opt_warn > $opt_crit ) { print "Whoops: You can't have a warning threshold higher than the critical threshold\n"; exit $exit_unknown; } | |
if ( $opt_level > 16 ) { print "Whoops: You can't have over a higher PDU level than 16\n"; exit $exit_unknown; } | |
# Setup the SNMP session | |
($session, $error) = Net::SNMP->session( | |
-hostname => $opt_host, | |
-community => $opt_comm, | |
-timeout => $opt_time, | |
-port => $opt_port, | |
-translate => [-timeticks => 0x0], | |
); | |
if (!defined $session) { | |
print "Whoops: Failed to establish an SNMP session\n"; | |
exit $exit_critical; | |
} | |
my $total = query_oid($oid_totalamps.'.'.$opt_level) * 0.1; | |
if ( $total eq 0 && $opt_zero ) { | |
print "Critical: Level $opt_level total amps is 0 amps!"; | |
exit($exit_critical); | |
} elsif ( $total > $opt_crit ) { | |
print "CRITICAL: Level $opt_level total amps is: $total amps\n"; | |
exit($exit_critical); | |
} elsif ( $total > $opt_warn ) { | |
print "WARNING: Level $opt_level total amps is: $total amps\n"; | |
exit($exit_warning); | |
} elsif ( $total > 0 ) { | |
print "OK: Level $opt_level total amps is: $total amps\n"; | |
exit($exit_ok); | |
} else { | |
print "Unknown: Level $opt_level total amps is: $total amps\n"; | |
exit($exit_unknown); | |
} | |
sub query_oid { | |
# This function will poll the active SNMP session and return the value | |
# of the OID specified. Only inputs are OID. Will use global $session | |
# variable for the session. | |
my $oid = $_[0]; | |
my $response = $session->get_request(-varbindlist => [ $oid ],); | |
# If there was a problem querying the OID error out and exit | |
if (!defined $response) { | |
$session->close(); | |
print "Unknown: Can't get total amps for PDU level $opt_level\n"; | |
exit $exit_unknown; | |
} | |
return $response->{$oid}; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment