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

@ -1,149 +1,165 @@
#! /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/gpl.txt # GPL License: http://www.gnu.org/licenses/gpl.txt
# #
# Developped by : Julien Mathis - Romain Le Merlus # Developped by : Julien Mathis - Romain Le Merlus
# Christophe Coraboeuf # Christophe Coraboeuf
# #
################################################################### ###################################################################
# 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 "/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 ();
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,
"V" => \$opt_V, "version" => \$opt_V, "V" => \$opt_V, "version" => \$opt_V,
"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,
"o=s" => \$opt_o, "oid=s" => \$opt_o, "o=s" => \$opt_o, "oid=s" => \$opt_o,
"t=s" => \$opt_t, "type=s" => \$opt_t, "t=s" => \$opt_t, "type=s" => \$opt_t,
"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);
if ($opt_V) { if ($opt_V) {
print_revision($PROGNAME,'$Revision: 1.0'); print_revision($PROGNAME,'$Revision: 1.0');
exit $ERRORS{'OK'}; exit $ERRORS{'OK'};
} }
if ($opt_h) { if ($opt_h) {
print_help(); print_help();
exit $ERRORS{'OK'}; exit $ERRORS{'OK'};
} }
$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"); }
my $rrd = $pathtorrdbase.$ServiceId.".rrd";
($opt_C) || ($opt_C = shift) || ($opt_C = "public");
($opt_t) || ($opt_t = shift) || ($opt_t = "GAUGE");
my $DS_type = $1 if ($opt_t =~ /(GAUGE)/ || $opt_t =~ /(COUNTER)/); my $DS_type = "GAUGE";
($opt_t) || ($opt_t = shift) || ($opt_t = "GAUGE");
($opt_c) || ($opt_c = shift); $DS_type = $1 if ($opt_t =~ /(GAUGE)/ || $opt_t =~ /(COUNTER)/);
my $critical = $1 if ($opt_c =~ /([0-9]+)/);
if (!$opt_c || !$opt_w) {
($opt_w) || ($opt_w = shift); print "You must specify -c and -w options\n";
my $warning = $1 if ($opt_w =~ /([0-9]+)/); exit $ERRORS{'OK'};
if ($critical <= $warning){ }
print "(--critical) must be superior to (--warning)";
print_usage(); ($opt_c) || ($opt_c = shift);
exit $ERRORS{'OK'}; my $critical = $1 if ($opt_c =~ /([0-9]+)/);
}
($opt_w) || ($opt_w = shift);
my $name = $0; my $warning = $1 if ($opt_w =~ /([0-9]+)/);
$name =~ s/\.pl.*//g; if ($critical <= $warning){
my $day = 0; print "(--critical) must be superior to (--warning)";
print_usage();
#=== create a SNMP session ==== exit $ERRORS{'OK'};
}
my ($session, $error) = Net::SNMP->session(-hostname => $opt_H,-community => $opt_C, -version => $snmp);
if (!defined($session)) { if (!$opt_o) {
print("CRITICAL: $error"); print "Option -o needed.\n";
exit $ERRORS{'CRITICAL'}; exit $ERRORS{'OK'};
} }elsif (!($opt_o =~ /^[0-9\.]+$/)) {
print "Wrong OID format\n";
my $result = $session->get_request(-varbindlist => [$opt_o]); exit $ERRORS{'OK'};
if (!defined($result)) { }
printf("UNKNOWN: %s.\n", $session->error);
$session->close; my $name = $0;
exit $ERRORS{'UNKNOWN'}; $name =~ s/\.pl.*//g;
} my $day = 0;
my $return_result = $result->{$opt_o}; #=== create a SNMP session ====
#=== Plugin return code ==== my ($session, $error) = Net::SNMP->session(-hostname => $opt_H,-community => $opt_C, -version => $snmp);
if (defined($return_result)){ if (!defined($session)) {
if ($opt_w && $opt_c && $return_result < $opt_w){ print("CRITICAL: $error");
print "Ok value : " . $return_result . "|value=".$return_result.";".$opt_w.";".$opt_c.";;\n"; exit $ERRORS{'CRITICAL'};
exit $ERRORS{'OK'}; }
} 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";} my $result = $session->get_request(-varbindlist => [$opt_o]);
exit $ERRORS{'WARNING'}; if (!defined($result)) {
} elsif ($opt_w && $opt_c && $return_result >= $opt_c){ printf("UNKNOWN: %s.\n", $session->error);
print "Critical value : " . $return_result."|value=".$return_result.";".$opt_w.";".$opt_c.";;\n";} $session->close;
exit $ERRORS{'CRITICAL'}; exit $ERRORS{'UNKNOWN'};
} }
} else {
print "CRITICAL Host unavailable\n"; my $return_result = $result->{$opt_o};
exit $ERRORS{'CRITICAL'};
} #=== Plugin return code ====
if (defined($return_result)){
sub print_usage () { if ($opt_w && $opt_c && $return_result < $opt_w){
print "\nUsage:\n"; print "Ok value : " . $return_result . "|value=".$return_result.";".$opt_w.";".$opt_c.";;\n";
print "$PROGNAME\n"; exit $ERRORS{'OK'};
print " -H (--hostname) Hostname to query - (required)\n"; } elsif ($opt_w && $opt_c && $return_result >= $opt_w && $return_result < $opt_c){
print " -C (--community) SNMP read community (defaults to public,\n"; print "Warning value : " . $return_result . "|value=$return_result;".$opt_w.";".$opt_c.";;\n";
print " used with SNMP v1 and v2c\n"; exit $ERRORS{'WARNING'};
print " -v (--snmp_version) 1 for SNMP v1 (default)\n"; } elsif ($opt_w && $opt_c && $return_result >= $opt_c){
print " 2 for SNMP v2c\n"; print "Critical value : " . $return_result."|value=".$return_result.";".$opt_w.";".$opt_c.";;\n";
print " -t (--type) Data Source Type (GAUGE or COUNTER) (GAUGE by default)\n"; exit $ERRORS{'CRITICAL'};
print " -o (--oid) OID to check\n"; }
print " -w (--warning) Warning level\n"; } else {
print " -c (--critical) Critical level\n"; print "CRITICAL Host unavailable\n";
print " -V (--version) Plugin version\n"; exit $ERRORS{'CRITICAL'};
print " -h (--help) usage help\n"; }
}
sub print_help () { sub print_usage () {
print "######################################################\n"; print "\nUsage:\n";
print "# Copyright (c) 2004-2007 Oreon-project #\n"; print "$PROGNAME\n";
print "# Bugs to http://www.oreon-project.org/ #\n"; print " -H (--hostname) Hostname to query - (required)\n";
print "######################################################\n"; print " -C (--community) SNMP read community (defaults to public,\n";
print_usage(); print " used with SNMP v1 and v2c\n";
print "\n"; print " -v (--snmp_version) 1 for SNMP v1 (default)\n";
} print " 2 for SNMP v2c\n";
print " -t (--type) Data Source Type (GAUGE or COUNTER) (GAUGE by default)\n";
print " -o (--oid) OID to check\n";
print " -w (--warning) Warning level\n";
print " -c (--critical) Critical level\n";
print " -V (--version) Plugin version\n";
print " -h (--help) usage help\n";
}
sub print_help () {
print "######################################################\n";
print "# Copyright (c) 2004-2007 Oreon-project #\n";
print "# Bugs to http://www.oreon-project.org/ #\n";
print "######################################################\n";
print_usage();
print "\n";
}