From fd541f24c651fbeb197879e681b6e48f05fc5c64 Mon Sep 17 00:00:00 2001 From: Mat Sugumaran Date: Tue, 22 May 2007 16:12:09 +0000 Subject: [PATCH] bug fix git-svn-id: http://svn.centreon.com/Plugins/Dev@2351 6bcd3966-0018-0410-8128-fd23d134de7e --- .../src/check_oreon_snmp_remote_storage.pl | 54 +-- .../src/check_oreon_snmp_value.pl | 314 +++++++++--------- 2 files changed, 200 insertions(+), 168 deletions(-) diff --git a/centreon-plugins/src/check_oreon_snmp_remote_storage.pl b/centreon-plugins/src/check_oreon_snmp_remote_storage.pl index 54b7c240d..aa69c3cd0 100644 --- a/centreon-plugins/src/check_oreon_snmp_remote_storage.pl +++ b/centreon-plugins/src/check_oreon_snmp_remote_storage.pl @@ -28,12 +28,19 @@ use strict; use Net::SNMP qw(:snmp); use FindBin; use lib "$FindBin::Bin"; -use lib "@NAGIOS_PLUGINS@"; +use lib "/srv/nagios/libexec"; 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 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 @@ -53,6 +60,7 @@ GetOptions "v=s" => \$opt_v, "snmp=s" => \$opt_v, "C=s" => \$opt_C, "community=s" => \$opt_C, "d=s" => \$opt_d, "disk=s" => \$opt_d, + "f" => \$opt_f, "perfparse" => \$opt_f, "n" => \$opt_n, "name" => \$opt_n, "w=s" => \$opt_w, "warning=s" => \$opt_w, "c=s" => \$opt_c, "critical=s" => \$opt_c, @@ -68,20 +76,26 @@ if ($opt_h) { print_help(); exit $ERRORS{'OK'}; } - -$opt_H = shift unless ($opt_H); -(print_usage() && exit $ERRORS{'OK'}) unless ($opt_H); +if (!$opt_H) { +print_usage(); +exit $ERRORS{'OK'}; +} if ($opt_n && !$opt_d) { print "Option -n (--name) need option -d (--disk)\n"; exit $ERRORS{'UNKNOWN'}; } +my $snmp = "1"; +if ($opt_v && $opt_v =~ /(\d)/) { +$snmp = $opt_v; +} -($opt_v) || ($opt_v = shift) || ($opt_v = "2"); -my $snmp = $1 if ($opt_v =~ /(\d)/); - -($opt_C) || ($opt_C = shift) || ($opt_C = "public"); - +if (!$opt_C) { +$opt_C = "public"; +} +if (!$opt_d) { +$opt_d = 2; +} ($opt_d) || ($opt_d = shift) || ($opt_d = 2); 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"; 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){ print "(--crit) must be superior to (--warn)"; print_usage(); exit $ERRORS{'OK'}; } -($opt_step) || ($opt_step = shift) || ($opt_step = "300"); -$step = $1 if ($opt_step =~ /(\d+)/); my $name = $0; $name =~ s/\.pl.*//g; @@ -210,6 +225,7 @@ if (($Size =~ /([0-9]+)/) && ($AllocationUnits =~ /([0-9]+)/)){ @test = split (/\./, $pourcent); $pourcent = $test[0]; } + my $lastTot = $tot; $tot = $tot / 1073741824; $Used = ($Used * $AllocationUnits) / 1073741824; @@ -236,7 +252,7 @@ if (($Size =~ /([0-9]+)/) && ($AllocationUnits =~ /([0-9]+)/)){ my $size_o = $Used * 1073741824; my $warn = $opt_w * $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"; exit $return_code; diff --git a/centreon-plugins/src/check_oreon_snmp_value.pl b/centreon-plugins/src/check_oreon_snmp_value.pl index b73903cd1..b6d6155f3 100644 --- a/centreon-plugins/src/check_oreon_snmp_value.pl +++ b/centreon-plugins/src/check_oreon_snmp_value.pl @@ -1,149 +1,165 @@ -#! /usr/bin/perl -w -################################################################### -# Oreon is developped with GPL Licence 2.0 -# -# GPL License: http://www.gnu.org/licenses/gpl.txt -# -# Developped by : Julien Mathis - Romain Le Merlus -# Christophe Coraboeuf -# -################################################################### -# This program is free software; you can redistribute it and/or -# modify it under the terms of the GNU General Public License -# as published by the Free Software Foundation; either version 2 -# of the License, or (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# For information : contact@merethis.com -#################################################################### -# -# Script init -# - -use strict; -use Net::SNMP qw(:snmp); -use FindBin; -use lib "$FindBin::Bin"; -use lib "@NAGIOS_PLUGINS@"; -use utils qw($TIMEOUT %ERRORS &print_revision &support); - -use vars qw($PROGNAME); -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); - -$PROGNAME = $0; -sub print_help (); -sub print_usage (); - -Getopt::Long::Configure('bundling'); -GetOptions - ("h" => \$opt_h, "help" => \$opt_h, - "V" => \$opt_V, "version" => \$opt_V, - "v=s" => \$opt_v, "snmp=s" => \$opt_v, - "C=s" => \$opt_C, "community=s" => \$opt_C, - "o=s" => \$opt_o, "oid=s" => \$opt_o, - "t=s" => \$opt_t, "type=s" => \$opt_t, - "w=s" => \$opt_w, "warning=s" => \$opt_w, - "c=s" => \$opt_c, "critical=s" => \$opt_c, - "H=s" => \$opt_H, "hostname=s" => \$opt_H); - -if ($opt_V) { - print_revision($PROGNAME,'$Revision: 1.0'); - exit $ERRORS{'OK'}; -} - -if ($opt_h) { - print_help(); - exit $ERRORS{'OK'}; -} - -$opt_H = shift unless ($opt_H); -(print_usage() && exit $ERRORS{'OK'}) unless ($opt_H); - -($opt_v) || ($opt_v = shift) || ($opt_v = "1"); -my $snmp = $1 if ($opt_v =~ /(\d)/); - -($opt_C) || ($opt_C = shift) || ($opt_C = "public"); -my $rrd = $pathtorrdbase.$ServiceId.".rrd"; - -($opt_t) || ($opt_t = shift) || ($opt_t = "GAUGE"); -my $DS_type = $1 if ($opt_t =~ /(GAUGE)/ || $opt_t =~ /(COUNTER)/); - -($opt_c) || ($opt_c = shift); -my $critical = $1 if ($opt_c =~ /([0-9]+)/); - -($opt_w) || ($opt_w = shift); -my $warning = $1 if ($opt_w =~ /([0-9]+)/); -if ($critical <= $warning){ - print "(--critical) must be superior to (--warning)"; - print_usage(); - exit $ERRORS{'OK'}; -} - -my $name = $0; -$name =~ s/\.pl.*//g; -my $day = 0; - -#=== create a SNMP session ==== - -my ($session, $error) = Net::SNMP->session(-hostname => $opt_H,-community => $opt_C, -version => $snmp); -if (!defined($session)) { - print("CRITICAL: $error"); - exit $ERRORS{'CRITICAL'}; -} - -my $result = $session->get_request(-varbindlist => [$opt_o]); -if (!defined($result)) { - printf("UNKNOWN: %s.\n", $session->error); - $session->close; - exit $ERRORS{'UNKNOWN'}; -} - -my $return_result = $result->{$opt_o}; - -#=== Plugin return code ==== -if (defined($return_result)){ - if ($opt_w && $opt_c && $return_result < $opt_w){ - print "Ok value : " . $return_result . "|value=".$return_result.";".$opt_w.";".$opt_c.";;\n"; - 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";} - exit $ERRORS{'WARNING'}; - } elsif ($opt_w && $opt_c && $return_result >= $opt_c){ - print "Critical value : " . $return_result."|value=".$return_result.";".$opt_w.";".$opt_c.";;\n";} - exit $ERRORS{'CRITICAL'}; - } -} else { - print "CRITICAL Host unavailable\n"; - exit $ERRORS{'CRITICAL'}; -} - - -sub print_usage () { - print "\nUsage:\n"; - print "$PROGNAME\n"; - print " -H (--hostname) Hostname to query - (required)\n"; - print " -C (--community) SNMP read community (defaults to public,\n"; - print " used with SNMP v1 and v2c\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"; -} +#! /usr/bin/perl -w +################################################################### +# Oreon is developped with GPL Licence 2.0 +# +# GPL License: http://www.gnu.org/licenses/gpl.txt +# +# Developped by : Julien Mathis - Romain Le Merlus +# Christophe Coraboeuf +# +################################################################### +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License +# as published by the Free Software Foundation; either version 2 +# of the License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# For information : contact@merethis.com +#################################################################### +# +# Script init +# + +use strict; +use Net::SNMP qw(:snmp); +use FindBin; +use lib "$FindBin::Bin"; +use lib "/srv/nagios/libexec"; +use utils qw($TIMEOUT %ERRORS &print_revision &support); + +use vars qw($PROGNAME); +use Getopt::Long; +use vars qw($opt_h $opt_V $opt_H $opt_C $opt_v $opt_o $opt_c $opt_w $opt_t); + +$PROGNAME = $0; +sub print_help (); +sub print_usage (); + +Getopt::Long::Configure('bundling'); +GetOptions + ("h" => \$opt_h, "help" => \$opt_h, + "V" => \$opt_V, "version" => \$opt_V, + "v=s" => \$opt_v, "snmp=s" => \$opt_v, + "C=s" => \$opt_C, "community=s" => \$opt_C, + "o=s" => \$opt_o, "oid=s" => \$opt_o, + "t=s" => \$opt_t, "type=s" => \$opt_t, + "w=s" => \$opt_w, "warning=s" => \$opt_w, + "c=s" => \$opt_c, "critical=s" => \$opt_c, + "H=s" => \$opt_H, "hostname=s" => \$opt_H); + +if ($opt_V) { + print_revision($PROGNAME,'$Revision: 1.0'); + exit $ERRORS{'OK'}; +} + +if ($opt_h) { + print_help(); + exit $ERRORS{'OK'}; +} + +$opt_H = shift unless ($opt_H); +(print_usage() && exit $ERRORS{'OK'}) unless ($opt_H); + +my $snmp = "1"; +if ($opt_v && $opt_v =~ /^[0-9]$/) { + $snmp = $opt_v; +} + +($opt_C) || ($opt_C = shift) || ($opt_C = "public"); + +my $DS_type = "GAUGE"; +($opt_t) || ($opt_t = shift) || ($opt_t = "GAUGE"); +$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); +my $critical = $1 if ($opt_c =~ /([0-9]+)/); + +($opt_w) || ($opt_w = shift); +my $warning = $1 if ($opt_w =~ /([0-9]+)/); +if ($critical <= $warning){ + print "(--critical) must be superior to (--warning)"; + print_usage(); + 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; +$name =~ s/\.pl.*//g; +my $day = 0; + +#=== create a SNMP session ==== + +my ($session, $error) = Net::SNMP->session(-hostname => $opt_H,-community => $opt_C, -version => $snmp); +if (!defined($session)) { + print("CRITICAL: $error"); + exit $ERRORS{'CRITICAL'}; +} + +my $result = $session->get_request(-varbindlist => [$opt_o]); +if (!defined($result)) { + printf("UNKNOWN: %s.\n", $session->error); + $session->close; + exit $ERRORS{'UNKNOWN'}; +} + +my $return_result = $result->{$opt_o}; + +#=== Plugin return code ==== + +if (defined($return_result)){ + if ($opt_w && $opt_c && $return_result < $opt_w){ + print "Ok value : " . $return_result . "|value=".$return_result.";".$opt_w.";".$opt_c.";;\n"; + 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"; + exit $ERRORS{'WARNING'}; + } elsif ($opt_w && $opt_c && $return_result >= $opt_c){ + print "Critical value : " . $return_result."|value=".$return_result.";".$opt_w.";".$opt_c.";;\n"; + exit $ERRORS{'CRITICAL'}; + } +} else { + print "CRITICAL Host unavailable\n"; + exit $ERRORS{'CRITICAL'}; +} + + +sub print_usage () { + print "\nUsage:\n"; + print "$PROGNAME\n"; + print " -H (--hostname) Hostname to query - (required)\n"; + print " -C (--community) SNMP read community (defaults to public,\n"; + print " used with SNMP v1 and v2c\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"; +}