git-svn-id: http://svn.centreon.com/Plugins/Dev@2351 6bcd3966-0018-0410-8128-fd23d134de7e
This commit is contained in:
Mat Sugumaran 2007-05-22 16:12:09 +00:00
parent a09e206db1
commit fd541f24c6
2 changed files with 200 additions and 168 deletions

View File

@ -28,12 +28,19 @@ 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 "/srv/nagios/libexec";
use utils qw($TIMEOUT %ERRORS &print_revision &support); use utils qw($TIMEOUT %ERRORS &print_revision &support);
if (eval "require oreon" ) {
use oreon qw(get_parameters);
use vars qw(%oreon);
%oreon=get_parameters();
} else {
print "Unable to load oreon perl module\n";
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_C $opt_d $opt_n $opt_w $opt_c $opt_H $opt_D $opt_s @test); use vars qw($opt_V $opt_h $opt_v $opt_f $opt_C $opt_d $opt_n $opt_w $opt_c $opt_H $opt_s @test);
# Plugin var init # Plugin var init
@ -53,6 +60,7 @@ GetOptions
"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,
"f" => \$opt_f, "perfparse" => \$opt_f,
"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,
@ -68,20 +76,26 @@ if ($opt_h) {
print_help(); print_help();
exit $ERRORS{'OK'}; exit $ERRORS{'OK'};
} }
if (!$opt_H) {
$opt_H = shift unless ($opt_H); print_usage();
(print_usage() && exit $ERRORS{'OK'}) unless ($opt_H); exit $ERRORS{'OK'};
}
if ($opt_n && !$opt_d) { if ($opt_n && !$opt_d) {
print "Option -n (--name) need option -d (--disk)\n"; print "Option -n (--name) need option -d (--disk)\n";
exit $ERRORS{'UNKNOWN'}; exit $ERRORS{'UNKNOWN'};
} }
my $snmp = "1";
if ($opt_v && $opt_v =~ /(\d)/) {
$snmp = $opt_v;
}
($opt_v) || ($opt_v = shift) || ($opt_v = "2"); if (!$opt_C) {
my $snmp = $1 if ($opt_v =~ /(\d)/); $opt_C = "public";
}
($opt_C) || ($opt_C = shift) || ($opt_C = "public"); if (!$opt_d) {
$opt_d = 2;
}
($opt_d) || ($opt_d = shift) || ($opt_d = 2); ($opt_d) || ($opt_d = shift) || ($opt_d = 2);
my $partition = 0; my $partition = 0;
@ -92,20 +106,21 @@ elsif (!$opt_n){
print "Unknown -d number expected... or it doesn't exist, try another disk - number\n"; print "Unknown -d number expected... or it doesn't exist, try another disk - number\n";
exit $ERRORS{'UNKNOWN'}; exit $ERRORS{'UNKNOWN'};
} }
my $critical = 95;
if ($opt_c && $opt_c =~ /^[0-9]+$/) {
$critical = $opt_c;
}
my $warning = 90;
if ($opt_w && $opt_w =~ /^[0-9]+$/) {
$warning = $opt_w;
}
($opt_c) || ($opt_c = shift) || ($opt_c = 95);
my $critical = $1 if ($opt_c =~ /([0-9]+)/);
($opt_w) || ($opt_w = shift) || ($opt_w = 80);
my $warning = $1 if ($opt_w =~ /([0-9]+)/);
if ($critical <= $warning){ if ($critical <= $warning){
print "(--crit) must be superior to (--warn)"; print "(--crit) must be superior to (--warn)";
print_usage(); print_usage();
exit $ERRORS{'OK'}; exit $ERRORS{'OK'};
} }
($opt_step) || ($opt_step = shift) || ($opt_step = "300");
$step = $1 if ($opt_step =~ /(\d+)/);
my $name = $0; my $name = $0;
$name =~ s/\.pl.*//g; $name =~ s/\.pl.*//g;
@ -210,6 +225,7 @@ if (($Size =~ /([0-9]+)/) && ($AllocationUnits =~ /([0-9]+)/)){
@test = split (/\./, $pourcent); @test = split (/\./, $pourcent);
$pourcent = $test[0]; $pourcent = $test[0];
} }
my $lastTot = $tot;
$tot = $tot / 1073741824; $tot = $tot / 1073741824;
$Used = ($Used * $AllocationUnits) / 1073741824; $Used = ($Used * $AllocationUnits) / 1073741824;
@ -236,7 +252,7 @@ if (($Size =~ /([0-9]+)/) && ($AllocationUnits =~ /([0-9]+)/)){
my $size_o = $Used * 1073741824; my $size_o = $Used * 1073741824;
my $warn = $opt_w * $size_o; my $warn = $opt_w * $size_o;
my $crit = $opt_c * $size_o; my $crit = $opt_c * $size_o;
print "|size=".$totrrd."o used=".$size_o.";".$warn.";".$crit; print "|size=".$lastTot."o used=".$size_o.";".$warn.";".$crit;
} }
print "\n"; print "\n";
exit $return_code; exit $return_code;

View File

@ -28,12 +28,12 @@ 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 "/srv/nagios/libexec";
use utils qw($TIMEOUT %ERRORS &print_revision &support); use utils qw($TIMEOUT %ERRORS &print_revision &support);
use vars qw($PROGNAME); use vars qw($PROGNAME);
use Getopt::Long; use Getopt::Long;
use vars qw($opt_h $opt_V $opt_D $opt_H $opt_C $opt_v $opt_o $opt_c $opt_w $opt_t); use vars qw($opt_h $opt_V $opt_H $opt_C $opt_v $opt_o $opt_c $opt_w $opt_t);
$PROGNAME = $0; $PROGNAME = $0;
sub print_help (); sub print_help ();
@ -64,14 +64,21 @@ if ($opt_h) {
$opt_H = shift unless ($opt_H); $opt_H = shift unless ($opt_H);
(print_usage() && exit $ERRORS{'OK'}) unless ($opt_H); (print_usage() && exit $ERRORS{'OK'}) unless ($opt_H);
($opt_v) || ($opt_v = shift) || ($opt_v = "1"); my $snmp = "1";
my $snmp = $1 if ($opt_v =~ /(\d)/); if ($opt_v && $opt_v =~ /^[0-9]$/) {
$snmp = $opt_v;
}
($opt_C) || ($opt_C = shift) || ($opt_C = "public"); ($opt_C) || ($opt_C = shift) || ($opt_C = "public");
my $rrd = $pathtorrdbase.$ServiceId.".rrd";
my $DS_type = "GAUGE";
($opt_t) || ($opt_t = shift) || ($opt_t = "GAUGE"); ($opt_t) || ($opt_t = shift) || ($opt_t = "GAUGE");
my $DS_type = $1 if ($opt_t =~ /(GAUGE)/ || $opt_t =~ /(COUNTER)/); $DS_type = $1 if ($opt_t =~ /(GAUGE)/ || $opt_t =~ /(COUNTER)/);
if (!$opt_c || !$opt_w) {
print "You must specify -c and -w options\n";
exit $ERRORS{'OK'};
}
($opt_c) || ($opt_c = shift); ($opt_c) || ($opt_c = shift);
my $critical = $1 if ($opt_c =~ /([0-9]+)/); my $critical = $1 if ($opt_c =~ /([0-9]+)/);
@ -84,6 +91,14 @@ if ($critical <= $warning){
exit $ERRORS{'OK'}; exit $ERRORS{'OK'};
} }
if (!$opt_o) {
print "Option -o needed.\n";
exit $ERRORS{'OK'};
}elsif (!($opt_o =~ /^[0-9\.]+$/)) {
print "Wrong OID format\n";
exit $ERRORS{'OK'};
}
my $name = $0; my $name = $0;
$name =~ s/\.pl.*//g; $name =~ s/\.pl.*//g;
my $day = 0; my $day = 0;
@ -106,15 +121,16 @@ if (!defined($result)) {
my $return_result = $result->{$opt_o}; my $return_result = $result->{$opt_o};
#=== Plugin return code ==== #=== Plugin return code ====
if (defined($return_result)){ if (defined($return_result)){
if ($opt_w && $opt_c && $return_result < $opt_w){ if ($opt_w && $opt_c && $return_result < $opt_w){
print "Ok value : " . $return_result . "|value=".$return_result.";".$opt_w.";".$opt_c.";;\n"; print "Ok value : " . $return_result . "|value=".$return_result.";".$opt_w.";".$opt_c.";;\n";
exit $ERRORS{'OK'}; exit $ERRORS{'OK'};
} elsif ($opt_w && $opt_c && $return_result >= $opt_w && $return_result < $opt_c){ } elsif ($opt_w && $opt_c && $return_result >= $opt_w && $return_result < $opt_c){
print "Warning value : " . $return_result . "|value=$return_result;".$opt_w.";".$opt_c.";;\n";} print "Warning value : " . $return_result . "|value=$return_result;".$opt_w.";".$opt_c.";;\n";
exit $ERRORS{'WARNING'}; exit $ERRORS{'WARNING'};
} elsif ($opt_w && $opt_c && $return_result >= $opt_c){ } elsif ($opt_w && $opt_c && $return_result >= $opt_c){
print "Critical value : " . $return_result."|value=".$return_result.";".$opt_w.";".$opt_c.";;\n";} print "Critical value : " . $return_result."|value=".$return_result.";".$opt_w.";".$opt_c.";;\n";
exit $ERRORS{'CRITICAL'}; exit $ERRORS{'CRITICAL'};
} }
} else { } else {