Logoj0ke.net Open Build Service > Projects > server:monitoring > nagios-plugins-snmp > check_snmp_apc_pdu
Sign Up | Log In

File check_snmp_apc_pdu of Package nagios-plugins-snmp

x
 
1
#! /usr/bin/perl -w
2
#
3
# check_snmp_apc_pdu v1.0 plugin for nagios
4
#
5
# checks with SNMP the power status of APC PDUs
6
# be sure to have the required MIB (PowerNet-MIB) ready in the snmp mib path
7
# default path is /usr/share/snmp/mibs
8
#
9
# Copyright Notice: GPL
10
#
11
# History:
12
#
13
# v1.0 Rouven Homann - rouven.homann@cimt-ag.de
14
#       + Initial Release
15
#
16
17
#use strict;
18
use SNMP;
19
use Getopt::Std;
20
use FindBin;
21
use lib $FindBin::Bin;
22
use utils qw($TIMEOUT %ERRORS &print_revision &support);
23
use vars qw($PROGNAME);
24
use Getopt::Long;
25
use vars qw($opt_V $opt_h $opt_H $opt_C $verbose $opt_c $opt_w); 
26
27
my $PROGNAME = "check_snmp_apc_pdu";
28
my $PROGVERSION = '1.0';
29
30
$ENV{'MIBS'}="ALL";                     # PowerNet-MIB required      
31
32
sub print_help ();
33
sub print_usage ();
34
35
Getopt::Long::Configure('bundling');
36
GetOptions ("V"   => \$opt_V, "version"    => \$opt_V,
37
        "h"   => \$opt_h, "help"       => \$opt_h,
38
        "v" => \$verbose, "verbose"  => \$verbose,
39
        "w=s" => \$opt_w, "warning=s"  => \$opt_w,
40
    "H=s" => \$opt_H, "host=s" => \$opt_H,
41
    "C=s" => \$opt_C, "community=s" => \$opt_C,
42
        "c=s" => \$opt_c, "critical=s" => \$opt_c);
43
44
if ($opt_V) {
45
    print_revision($PROGNAME,'$Revision: '.$PROGVERSION.'$');
46
    exit $ERRORS{'UNKNOWN'};
47
}
48
49
if ($opt_h) {
50
    print_help();
51
    exit $ERRORS{'UNKNOWN'};
52
}
53
54
print_usage() unless ($opt_H && $opt_C);
55
56
57
my @APC_INFO = &snmpconnect();
58
59
### get default thresholds from snmp
60
if ($opt_c) {
61
    $critical = $1 if ($opt_c =~ /([0-9]+)/);
62
} else { 
63
    $critical = $APC_INFO[7];
64
}
65
66
if ($opt_w) {
67
    $warning = $1 if ($opt_w =~ /([0-9]+)/);
68
} else { 
69
    $warning = $APC_INFO[6];
70
}
71
72
if ($APC_INFO[2] == 1) { $APC_INFO[2]='Ok'; } elsif ($APC_INFO[2] == 0) { $APC_INFO[2]='Down'; } else { $APC_INFO[2]='Unknown'; };  # PDU's own Powerstatus
73
if ($APC_INFO[3] == 1) { $APC_INFO[3]='Ok'; } elsif ($APC_INFO[3] == 0) { $APC_INFO[3]='Down'; } else { $APC_INFO[3]='Unknown'; };  # PDU's own Powerstatus
74
75
## CRITICAL
76
if (($APC_INFO[5]>=$critical) || ($APC_INFO[2] eq 'Down') || ($APC_INFO[3] eq 'Down')) {
77
    if ($verbose) { 
78
    print "CRITICAL: Model: $APC_INFO[0], Serial: $APC_INFO[1], Power1: $APC_INFO[2], Power2: $APC_INFO[3], Ports: $APC_INFO[4], Load: $APC_INFO[5]A";  # Verbose Output
79
    } else { 
80
    if (($APC_INFO[2] eq 'Unknown') || ($APC_INFO[3] eq 'Unknown')) {
81
        print "CRITICAL: Load Critical, $APC_INFO[5]A reached!";
82
    } else { 
83
        print "CRITICAL: Load Critical, $APC_INFO[5]A reached!, Power1: $APC_INFO[2], Power2: $APC_INFO[3]";    # Small Output
84
    };
85
    };
86
    exit $ERRORS{'CRITICAL'};
87
} 
88
## WARNING
89
elsif (($APC_INFO[5] >= $warning) && ($APC_INFO[5] < $critical)) {
90
    if ($verbose) { 
91
    print "WARNING: Model: $APC_INFO[0], Serial: $APC_INFO[1], Power1: $APC_INFO[2], Power2: $APC_INFO[3], Ports: $APC_INFO[4], Load: $APC_INFO[5]A";   # Verbose Output
92
93
    } else {
94
    if (($APC_INFO[2] eq 'Unknown') || ($APC_INFO[3] eq 'Unknown')) {
95
        print "Warning Load Warning, $APC_INFO[5]A reached!";
96
    } else { 
97
        print "WARNING: Load Warning, $APC_INFO[5]A reached!, Power1: $APC_INFO[2], Power2: $APC_INFO[3]";  # Small Output
98
    };
99
    };
100
    exit $ERRORS{'WARNING'};
101
} 
102
## OK
103
elsif (($APC_INFO[5] < $warning) && ($APC_INFO[2] eq 'Ok') && ($APC_INFO[3] eq 'Ok')) {
104
    if ($verbose) { 
105
    print "OK: Model: $APC_INFO[0], Serial: $APC_INFO[1], Power1: $APC_INFO[2], Power2: $APC_INFO[3], Ports: $APC_INFO[4], Load: $APC_INFO[5]A";    # Verbose Output
106
    } else { 
107
    if (($APC_INFO[2] eq 'Unknown') || ($APC_INFO[3] eq 'Unknown')) {
108
        print "OK: Load $APC_INFO[5]A";
109
    } else { 
110
    print "OK: Load $APC_INFO[5]A, Power1: $APC_INFO[2], Power2: $APC_INFO[3]"; # Small Output
111
    };
112
    };
113
    exit $ERRORS{'OK'};
114
} 
115
## UNKNOWN
116
else {
117
    print "UNKNOWN: An error occured while running snmp command, check MIB and oids";
118
    exit $ERRORS{'UNKNOWN'};    
119
}
120
121
sub snmpconnect () {
122
    my $SESSION = new SNMP::Session (DestHost => $opt_H,
123
                                    Community => $opt_C,
124
                                    Version => 1);
125
                    
126
    # Populate a VarList with OID values.
127
    my $APC_VLIST =  new SNMP::VarList(['sPDUIdentModelNumber'],                #0
128
                                ['sPDUIdentSerialNumber'],                  #1
129
                                    ['rPDUPowerSupply1Status'],                 #2
130
                                ['rPDUPowerSupply2Status'],                 #3
131
                                ['rPDUOutletDevNumCntrlOutlets'],           #4
132
                                    ['rPDULoadStatusPhaseLoad'],        #5
133
                    ['rPDULoadConfigNearOverloadThreshold'],    #6
134
                    ['rPDULoadConfigOverloadThreshold']);   #7
135
136
    # Pass the VarList to getnext building an array of the output
137
    &errorexit() unless my @APC_INFO = $SESSION->getnext($APC_VLIST);
138
     
139
    $APC_INFO[0] =~ s/\"//g;                        # Ditch the quotes.
140
    $APC_INFO[1] =~ s/\"//g;
141
    $APC_INFO[5] = $APC_INFO[5] / 10;
142
    return @APC_INFO;
143
}
144
145
sub errorexit () {
146
    print "UNKNOWN: An error occured while running snmp command, possible wrong pdu or mib not present!";
147
    exit $ERRORS{'UNKNOWN'};    
148
}
149
150
sub print_usage () {
151
    print "Usage: $PROGNAME -H <Hostname> -C <Community> [-w <warn>] [-c <crit>] [-v] [-h]\n";
152
    exit $ERRORS{'UNKNOWN'} unless ($opt_h);
153
}
154
155
sub print_help () {
156
    print_revision($PROGNAME,'$Revision: '.$PROGVERSION.' $');
157
    print "Copyright (c) 2005 Rouven Homann\n";
158
    print "\n";
159
    print_usage();
160
    print "\n";
161
    print "-H <Hostname> = Hostname or IP-Address.\n";
162
    print "-C <Community> = Community read password.\n";
163
    print "-v = Verbose Output.\n";
164
    print "-h = This screen.\n\n";
165
    support();
166
}
167