add AIX and AS400 support

git-svn-id: http://svn.centreon.com/Plugins/Dev@2946 6bcd3966-0018-0410-8128-fd23d134de7e
This commit is contained in:
Julien Mathis 2007-08-07 19:41:40 +00:00
parent e5421414bc
commit 15c49f8b7a
1 changed files with 342 additions and 330 deletions

View File

@ -1,330 +1,342 @@
#! /usr/bin/perl -w #! /usr/bin/perl -w
################################################################### ###################################################################
# Oreon is developped with GPL Licence 2.0 # Oreon is developped with GPL Licence 2.0
# #
# GPL License: http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt # GPL License: http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt
# #
# Developped by : Julien Mathis - Romain Le Merlus # Developped by : Julien Mathis - Romain Le Merlus
# Christophe Coraboeuf - Sugumaran Mathavarajan # Christophe Coraboeuf - Sugumaran Mathavarajan
# #
################################################################### ###################################################################
# This program is free software; you can redistribute it and/or # This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License # modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2 # as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version. # of the License, or (at your option) any later version.
# #
# This program is distributed in the hope that it will be useful, # This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of # but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details. # GNU General Public License for more details.
# #
# For information : contact@merethis.com # For information : contact@merethis.com
#################################################################### ####################################################################
# #
# Script init # Script init
# #
use strict; use strict;
use Net::SNMP qw(:snmp); use Net::SNMP qw(:snmp);
use FindBin; use FindBin;
use lib "$FindBin::Bin"; use lib "$FindBin::Bin";
use lib "@NAGIOS_PLUGINS@"; use lib "@NAGIOS_PLUGINS@";
use utils qw($TIMEOUT %ERRORS &print_revision &support); use utils qw($TIMEOUT %ERRORS &print_revision &support);
if (eval "require oreon" ) { if (eval "require oreon" ) {
use oreon qw(get_parameters); use oreon qw(get_parameters);
use vars qw(%oreon); use vars qw(%oreon);
%oreon=get_parameters(); %oreon=get_parameters();
} else { } else {
print "Unable to load oreon perl module\n"; print "Unable to load oreon perl module\n";
exit $ERRORS{'UNKNOWN'}; exit $ERRORS{'UNKNOWN'};
} }
use vars qw($PROGNAME); use vars qw($PROGNAME);
use Getopt::Long; use Getopt::Long;
use vars qw($opt_V $opt_h $opt_v $opt_f $opt_C $opt_d $opt_k $opt_u $opt_p $opt_n $opt_w $opt_c $opt_H $opt_s @test); use vars qw($opt_V $opt_t $opt_h $opt_v $opt_f $opt_C $opt_d $opt_k $opt_u $opt_p $opt_n $opt_w $opt_c $opt_H $opt_s @test);
# Plugin var init # Plugin var init
my ($hrStorageDescr, $hrStorageAllocationUnits, $hrStorageSize, $hrStorageUsed); my ($hrStorageDescr, $hrStorageAllocationUnits, $hrStorageSize, $hrStorageUsed);
my ($AllocationUnits, $Size, $Used); my ($AllocationUnits, $Size, $Used);
my ($tot, $used, $pourcent, $return_code); my ($tot, $used, $pourcent, $return_code);
$PROGNAME = "$0"; $PROGNAME = "$0";
sub print_help (); sub print_help ();
sub print_usage (); sub print_usage ();
Getopt::Long::Configure('bundling'); Getopt::Long::Configure('bundling');
GetOptions GetOptions
("h" => \$opt_h, "help" => \$opt_h, ("h" => \$opt_h, "help" => \$opt_h,
"u=s" => \$opt_u, "username=s" => \$opt_u, "u=s" => \$opt_u, "username=s" => \$opt_u,
"p=s" => \$opt_p, "password=s" => \$opt_p, "p=s" => \$opt_p, "password=s" => \$opt_p,
"k=s" => \$opt_k, "key=s" => \$opt_k, "k=s" => \$opt_k, "key=s" => \$opt_k,
"V" => \$opt_V, "version" => \$opt_V, "V" => \$opt_V, "version" => \$opt_V,
"s" => \$opt_s, "show" => \$opt_s, "s" => \$opt_s, "show" => \$opt_s,
"v=s" => \$opt_v, "snmp=s" => \$opt_v, "v=s" => \$opt_v, "snmp=s" => \$opt_v,
"C=s" => \$opt_C, "community=s" => \$opt_C, "C=s" => \$opt_C, "community=s" => \$opt_C,
"d=s" => \$opt_d, "disk=s" => \$opt_d, "d=s" => \$opt_d, "disk=s" => \$opt_d,
"n" => \$opt_n, "name" => \$opt_n, "n" => \$opt_n, "name" => \$opt_n,
"w=s" => \$opt_w, "warning=s" => \$opt_w, "w=s" => \$opt_w, "warning=s" => \$opt_w,
"c=s" => \$opt_c, "critical=s" => \$opt_c, "c=s" => \$opt_c, "critical=s" => \$opt_c,
"H=s" => \$opt_H, "hostname=s" => \$opt_H); "H=s" => \$opt_H, "hostname=s" => \$opt_H,
"t=s" => \$opt_t);
if ($opt_V) {
print_revision($PROGNAME,'$Revision: 1.2 $'); if ($opt_V) {
exit $ERRORS{'OK'}; print_revision($PROGNAME,'$Revision: 1.2 $');
} exit $ERRORS{'OK'};
}
if ($opt_h) {
print_help(); if ($opt_h) {
exit $ERRORS{'OK'}; print_help();
} exit $ERRORS{'OK'};
if (!$opt_H) { }
print_usage(); if (!$opt_H) {
exit $ERRORS{'OK'}; print_usage();
} exit $ERRORS{'OK'};
}
if ($opt_n && !$opt_d) {
print "Option -n (--name) need option -d (--disk)\n"; if ($opt_n && !$opt_d) {
exit $ERRORS{'UNKNOWN'}; print "Option -n (--name) need option -d (--disk)\n";
} exit $ERRORS{'UNKNOWN'};
my $snmp = "1"; }
$snmp = $opt_v if ($opt_v && $opt_v =~ /^[0-9]$/); my $snmp = "1";
$snmp = $opt_v if ($opt_v && $opt_v =~ /^[0-9]$/);
if ($snmp eq "3") {
if (!$opt_u) { if ($snmp eq "3") {
print "Option -u (--username) is required for snmpV3\n"; if (!$opt_u) {
exit $ERRORS{'OK'}; print "Option -u (--username) is required for snmpV3\n";
} exit $ERRORS{'OK'};
if (!$opt_p && !$opt_k) { }
print "Option -k (--key) or -p (--password) is required for snmpV3\n"; if (!$opt_p && !$opt_k) {
exit $ERRORS{'OK'}; print "Option -k (--key) or -p (--password) is required for snmpV3\n";
} elsif ($opt_p && $opt_k) { exit $ERRORS{'OK'};
print "Only option -k (--key) or -p (--password) is needed for snmpV3\n"; } elsif ($opt_p && $opt_k) {
exit $ERRORS{'OK'}; print "Only option -k (--key) or -p (--password) is needed for snmpV3\n";
} exit $ERRORS{'OK'};
} }
}
$opt_C = "public" if (!$opt_C);
$opt_d = 2 if (!$opt_d); $opt_C = "public" if (!$opt_C);
$opt_d = 2 if (!$opt_d);
($opt_d) || ($opt_d = shift) || ($opt_d = 2);
($opt_d) || ($opt_d = shift) || ($opt_d = 2);
my $partition = 0;
if ($opt_d =~ /([0-9]+)/ && !$opt_n){ my $partition = 0;
$partition = $1; if ($opt_d =~ /([0-9]+)/ && !$opt_n){
} elsif (!$opt_n){ $partition = $1;
print "Unknown -d number expected... or it doesn't exist, try another disk - number\n"; } elsif (!$opt_n){
exit $ERRORS{'UNKNOWN'}; print "Unknown -d number expected... or it doesn't exist, try another disk - number\n";
} exit $ERRORS{'UNKNOWN'};
if (!$opt_c) { }
$opt_c = 95; if (!$opt_c) {
} $opt_c = 95;
if (!$opt_w) { }
$opt_w = 90; if (!$opt_w) {
} $opt_w = 90;
my $critical = 95; }
if ($opt_c && $opt_c =~ /^[0-9]+$/) { my $critical = 95;
$critical = $opt_c; if ($opt_c && $opt_c =~ /^[0-9]+$/) {
} $critical = $opt_c;
my $warning = 90; }
if ($opt_w && $opt_w =~ /^[0-9]+$/) { my $warning = 90;
$warning = $opt_w; if ($opt_w && $opt_w =~ /^[0-9]+$/) {
} $warning = $opt_w;
}
if ($critical <= $warning){
print "(--crit) must be superior to (--warn)"; if ($critical <= $warning){
print_usage(); print "(--crit) must be superior to (--warn)";
exit $ERRORS{'OK'}; print_usage();
} exit $ERRORS{'OK'};
}
my $name = $0;
$name =~ s/\.pl.*//g; my $name = $0;
$name =~ s/\.pl.*//g;
# Plugin snmp requests
# Plugin snmp requests
my $OID_hrStorageDescr =$oreon{MIB2}{HR_STORAGE_DESCR}; my $OID_hrStorageDescr = "";
my $OID_hrStorageAllocationUnits =$oreon{MIB2}{HR_STORAGE_ALLOCATION_UNITS}; if (defined($opt_t) && ($opt_t eq "AIX" || $opt_t eq "AS400")){
my $OID_hrStorageSize =$oreon{MIB2}{HR_STORAGE_SIZE}; $OID_hrStorageDescr = ".1.3.6.1.2.1.25.3.8.1.2";
my $OID_hrStorageUsed =$oreon{MIB2}{HR_STORAGE_USED}; } else {
$OID_hrStorageDescr = $oreon{MIB2}{HR_STORAGE_DESCR};
# create a SNMP session }
my ($session, $error); my $OID_hrStorageAllocationUnits = $oreon{MIB2}{HR_STORAGE_ALLOCATION_UNITS};
if ($snmp eq "1" || $snmp eq "2") { my $OID_hrStorageSize = $oreon{MIB2}{HR_STORAGE_SIZE};
($session, $error) = Net::SNMP->session(-hostname => $opt_H, -community => $opt_C, -version => $snmp); my $OID_hrStorageUsed = $oreon{MIB2}{HR_STORAGE_USED};
if (!defined($session)) {
print("UNKNOWN: SNMP Session : $error\n"); # create a SNMP session
exit $ERRORS{'UNKNOWN'}; my ($session, $error);
} if ($snmp eq "1" || $snmp eq "2") {
}elsif ($opt_k) { ($session, $error) = Net::SNMP->session(-hostname => $opt_H, -community => $opt_C, -version => $snmp);
($session, $error) = Net::SNMP->session(-hostname => $opt_H, -version => $snmp, -username => $opt_u, -authkey => $opt_k); if (!defined($session)) {
if (!defined($session)) { print("UNKNOWN: SNMP Session : $error\n");
print("UNKNOWN: SNMP Session : $error\n"); exit $ERRORS{'UNKNOWN'};
exit $ERRORS{'UNKNOWN'}; }
} }elsif ($opt_k) {
}elsif ($opt_p) { ($session, $error) = Net::SNMP->session(-hostname => $opt_H, -version => $snmp, -username => $opt_u, -authkey => $opt_k);
($session, $error) = Net::SNMP->session(-hostname => $opt_H, -version => $snmp, -username => $opt_u, -authpassword => $opt_p); if (!defined($session)) {
if (!defined($session)) { print("UNKNOWN: SNMP Session : $error\n");
print("UNKNOWN: SNMP Session : $error\n"); exit $ERRORS{'UNKNOWN'};
exit $ERRORS{'UNKNOWN'}; }
} }elsif ($opt_p) {
} ($session, $error) = Net::SNMP->session(-hostname => $opt_H, -version => $snmp, -username => $opt_u, -authpassword => $opt_p);
if (!defined($session)) {
#getting partition using its name instead of its oid index print("UNKNOWN: SNMP Session : $error\n");
if ($opt_n) { exit $ERRORS{'UNKNOWN'};
my $result = $session->get_table(Baseoid => $OID_hrStorageDescr); }
if (!defined($result)) { }
printf("ERROR: hrStorageDescr Table : %s.\n", $session->error);
$session->close; #getting partition using its name instead of its oid index
exit $ERRORS{'UNKNOWN'}; if ($opt_n) {
} my $result = $session->get_table(Baseoid => $OID_hrStorageDescr);
my $expr = ""; if (!defined($result)) {
if ($opt_d =~ m/^[A-Za-z]:/) { printf("ERROR: hrStorageDescr Table : %s.\n", $session->error);
$opt_d =~ s/\\/\\\\/g; $session->close;
$expr = "^$opt_d"; exit $ERRORS{'UNKNOWN'};
}elsif ($opt_d =~ m/^\//) { }
$expr = "$opt_d\$"; my $expr = "";
}else { if ($opt_d =~ m/^[A-Za-z]:/) {
$expr = "$opt_d"; $opt_d =~ s/\\/\\\\/g;
} $expr = "^$opt_d";
foreach my $key ( oid_lex_sort(keys %$result)) { }elsif ($opt_d =~ m/^\//) {
if ($result->{$key} =~ m/$expr/) { $expr = "$opt_d\$";
my @oid_list = split (/\./,$key); }else {
$partition = pop (@oid_list) ; $expr = "$opt_d";
} }
} foreach my $key ( oid_lex_sort(keys %$result)) {
} if (defined($opt_t) && $opt_t eq "AS400"){
if ($opt_s) { $result->{$key} =~ s/\ //g;
# Get description table }
my $result = $session->get_table( if ($result->{$key} =~ m/$expr/) {
Baseoid => $OID_hrStorageDescr my @oid_list = split (/\./,$key);
); $partition = pop (@oid_list) ;
}
if (!defined($result)) { }
printf("ERROR: hrStorageDescr Table : %s.\n", $session->error); }
$session->close;
exit $ERRORS{'UNKNOWN'}; if ($opt_s) {
} # Get description table
my $result = $session->get_table(
foreach my $key ( oid_lex_sort(keys %$result)) { Baseoid => $OID_hrStorageDescr
my @oid_list = split (/\./,$key); );
my $index = pop (@oid_list) ;
print "hrStorage $index :: $$result{$key}\n"; if (!defined($result)) {
} printf("ERROR: hrStorageDescr Table : %s.\n", $session->error);
exit $ERRORS{'OK'}; $session->close;
} exit $ERRORS{'UNKNOWN'};
}
my $result = $session->get_request(
-varbindlist => [$OID_hrStorageDescr.".".$partition , foreach my $key ( oid_lex_sort(keys %$result)) {
$OID_hrStorageAllocationUnits.".".$partition , my @oid_list = split (/\./,$key);
$OID_hrStorageSize.".".$partition, my $index = pop (@oid_list) ;
$OID_hrStorageUsed.".".$partition print "hrStorage $index :: $$result{$key}\n";
] }
); exit $ERRORS{'OK'};
if (!defined($result)) { }
printf("ERROR: %s", $session->error);
if ($opt_n) { print(" - You must specify the disk name when option -n is used");}
print ".\n"; my $result = $session->get_request(
$session->close; -varbindlist => [$OID_hrStorageDescr.".".$partition ,
exit $ERRORS{'UNKNOWN'}; $OID_hrStorageAllocationUnits.".".$partition ,
} $OID_hrStorageSize.".".$partition,
$hrStorageDescr = $result->{$OID_hrStorageDescr.".".$partition }; $OID_hrStorageUsed.".".$partition
$AllocationUnits = $result->{$OID_hrStorageAllocationUnits.".".$partition }; ]
$Size = $result->{$OID_hrStorageSize.".".$partition }; );
$Used = $result->{$OID_hrStorageUsed.".".$partition }; if (!defined($result)) {
printf("ERROR: %s", $session->error);
if ($opt_n) { print(" - You must specify the disk name when option -n is used");}
# Plugins var treatment print ".\n";
$session->close;
if (!$Size){ exit $ERRORS{'UNKNOWN'};
print "Disk CRITICAL - no output (-p number expected... it doesn't exist, try another disk - number\n"; }
exit $ERRORS{'CRITICAL'};
} $hrStorageDescr = $result->{$OID_hrStorageDescr.".".$partition };
$AllocationUnits = $result->{$OID_hrStorageAllocationUnits.".".$partition };
if (($Size =~ /([0-9]+)/) && ($AllocationUnits =~ /([0-9]+)/)){ $Size = $result->{$OID_hrStorageSize.".".$partition };
if (!$Size){ $Used = $result->{$OID_hrStorageUsed.".".$partition };
print "The number of the option -p is not a hard drive\n";
exit $ERRORS{'CRITICAL'};
} # Plugins var treatment
$tot = 1;
$tot = $Size * $AllocationUnits; if (!$Size){
if (!$tot){$tot = 1;} print "Disk CRITICAL - no output (-p number expected... it doesn't exist, try another disk - number\n";
$used = $Used * $AllocationUnits; exit $ERRORS{'CRITICAL'};
$pourcent = ($used * 100) / $tot; }
if (length($pourcent) > 2){ if (($Size =~ /([0-9]+)/) && ($AllocationUnits =~ /([0-9]+)/)){
@test = split (/\./, $pourcent); if (!$Size){
$pourcent = $test[0]; print "The number of the option -p is not a hard drive\n";
} exit $ERRORS{'CRITICAL'};
my $lastTot = $tot; }
$tot = $tot / 1073741824; $tot = 1;
$Used = ($Used * $AllocationUnits) / 1073741824; $tot = $Size * $AllocationUnits;
if (!$tot){$tot = 1;}
# Plugin return code $used = $Used * $AllocationUnits;
$pourcent = ($used * 100) / $tot;
if ($pourcent >= $critical){
print "Disk CRITICAL - "; if (length($pourcent) > 2){
$return_code = 2; @test = split (/\./, $pourcent);
} elsif ($pourcent >= $warning){ $pourcent = $test[0];
print "Disk WARNING - "; }
$return_code = 1; my $lastTot = $tot;
} else { $tot = $tot / 1073741824;
print "Disk OK - "; $Used = ($Used * $AllocationUnits) / 1073741824;
$return_code = 0;
} # Plugin return code
if ($hrStorageDescr){ if ($pourcent >= $critical){
print $hrStorageDescr . " TOTAL: "; print "Disk CRITICAL - ";
printf("%.3f", $tot); $return_code = 2;
print " Go USED: " . $pourcent . "% : "; } elsif ($pourcent >= $warning){
printf("%.3f", $Used); print "Disk WARNING - ";
print " Go"; $return_code = 1;
my $size_o = $Used * 1073741824; } else {
my $warn = $opt_w * $size_o; print "Disk OK - ";
my $crit = $opt_c * $size_o; $return_code = 0;
print "|size=".$lastTot."o used=".$size_o.";".$warn.";".$crit; }
print "\n";
exit $return_code; if ($hrStorageDescr){
} else { $hrStorageDescr =~ s/\ //g if (defined($opt_t) && $opt_t eq "AS400");
print "TOTAL: "; print $hrStorageDescr . " TOTAL: ";
printf("%.3f", $tot); printf("%.3f", $tot);
print " Go USED: " . $pourcent . "% : "; print " Go USED: " . $pourcent . "% : ";
printf("%.3f", $Used); printf("%.3f", $Used);
print " Go\n"; print " Go";
exit $return_code; my $size_o = $Used * 1073741824;
} my $warn = $opt_w * $size_o;
} else { my $crit = $opt_c * $size_o;
print "Disk CRITICAL - no output (-d number expected... it doesn't exist, try another disk - number\n"; print "|size=".$lastTot."o used=".$size_o.";".$warn.";".$crit;
exit $ERRORS{'CRITICAL'}; print "\n";
} exit $return_code;
} else {
sub print_usage () { print "TOTAL: ";
print "\nUsage:\n"; printf("%.3f", $tot);
print "$PROGNAME\n"; print " Go USED: " . $pourcent . "% : ";
print " -H (--hostname) Hostname to query - (required)\n"; printf("%.3f", $Used);
print " -C (--community) SNMP read community (defaults to public,\n"; print " Go\n";
print " used with SNMP v1 and v2c\n"; exit $return_code;
print " -v (--snmp_version) 1 for SNMP v1 (default)\n"; }
print " 2 for SNMP v2c\n"; } else {
print " -d (--disk) Set the disk (number expected) ex: 1, 2,... (defaults to 2 )\n"; print "Disk CRITICAL - no output (-d number expected... it doesn't exist, try another disk - number\n";
print " -n (--name) Allows to use disk name with option -d instead of disk oid index\n"; exit $ERRORS{'CRITICAL'};
print " (ex: -d \"C:\" -n, -d \"E:\" -n, -d \"Swap Memory\" -n, -d \"Real Memory\" -n\n"; }
print " (choose an unique expression for each disk)\n";
print " -s (--show) Describes all disk (debug mode)\n"; sub print_usage () {
print " -w (--warn) Signal strength at which a warning message will be generated\n"; print "\nUsage:\n";
print " (default 80)\n"; print "$PROGNAME\n";
print " -c (--crit) Signal strength at which a critical message will be generated\n"; print " -H (--hostname) Hostname to query - (required)\n";
print " (default 95)\n"; print " -C (--community) SNMP read community (defaults to public,\n";
print " -V (--version) Plugin version\n"; print " used with SNMP v1 and v2c\n";
print " -h (--help) usage help\n"; print " -v (--snmp_version) 1 for SNMP v1 (default)\n";
print " 2 for SNMP v2c\n";
} print " -d (--disk) Set the disk (number expected) ex: 1, 2,... (defaults to 2 )\n";
print " -n (--name) Allows to use disk name with option -d instead of disk oid index\n";
sub print_help () { print " (ex: -d \"C:\" -n, -d \"E:\" -n, -d \"Swap Memory\" -n, -d \"Real Memory\" -n\n";
print "##############################################\n"; print " (choose an unique expression for each disk)\n";
print "# Copyright (c) 2004-2007 Centreon #\n"; print " -s (--show) Describes all disk (debug mode)\n";
print "# Bugs to http://bugs.oreon-project.org/ #\n"; print " -w (--warn) Signal strength at which a warning message will be generated\n";
print "##############################################\n"; print " (default 80)\n";
print_usage(); print " -c (--crit) Signal strength at which a critical message will be generated\n";
print "\n"; print " (default 95)\n";
} print " -V (--version) Plugin version\n";
print " -h (--help) usage help\n";
}
sub print_help () {
print "##############################################\n";
print "# Copyright (c) 2004-2007 Centreon #\n";
print "# Bugs to http://bugs.oreon-project.org/ #\n";
print "##############################################\n";
print_usage();
print "\n";
}