diff --git a/install.sh b/install.sh old mode 100644 new mode 100755 diff --git a/src/centreon.conf b/src/centreon.conf index 4e983cb3b..f5139218a 100644 --- a/src/centreon.conf +++ b/src/centreon.conf @@ -1,47 +1,47 @@ -[GLOBAL] -DIR_NAGIOS=@INSTALL_DIR_NAGIOS@/ -NAGIOS_PLUGINS=@NAGIOS_PLUGINS@/ -NAGIOS_ETC=@NAGIOS_ETC@/ - -[NT] -CPU=.1.3.6.1.2.1.25.3.3.1.2 -HD_USED=.1.3.6.1.2.1.25.2.3.1.6 -HD_NAME=.1.3.6.1.2.1.25.2.3.1.3 - -[CISCO] -NB_CONNECT=.1.3.6.1.4.1.9.9.147.1.2.2.2.1.5.40.6 - -[UNIX] -CPU_USER=.1.3.6.1.4.1.2021.11.50.0 -CPU_SYSTEM=.1.3.6.1.4.1.2021.11.52.0 -CPU_LOAD_1M =.1.3.6.1.4.1.2021.10.1.3.1 -CPU_LOAD_5M =.1.3.6.1.4.1.2021.10.1.3.2 -CPU_LOAD_15M =.1.3.6.1.4.1.2021.10.1.3.3 - -[DELL] -TEMP=.1.3.6.1.4.1.674.10892.1.700.20.1.6.1 - -[ALTEON] -VIRT=1.3.6.1.4.1.1872.2.1.8.2.7.1.3.1 -FRONT=1.3.6.1.4.1.1872.2.1.8.2.5.1.3.1 - -[MIB2] -SW_RUNNAME=.1.3.6.1.2.1.25.4.2.1.2 -SW_RUNINDEX=.1.3.6.1.2.1.25.4.2.1.1 -SW_RUNSTATUS=.1.3.6.1.2.1.25.4.2.1.7 -HR_STORAGE_DESCR=.1.3.6.1.2.1.25.2.3.1.3 -HR_STORAGE_ALLOCATION_UNITS=.1.3.6.1.2.1.25.2.3.1.4 -HR_STORAGE_SIZE=.1.3.6.1.2.1.25.2.3.1.5 -HR_STORAGE_USED=.1.3.6.1.2.1.25.2.3.1.6 -OBJECTID=.1.3.6.1.2.1.1.1.0 -UPTIME_WINDOWS=.1.3.6.1.2.1.1.3.0 -UPTIME_OTHER=.1.3.6.1.2.1.25.1.1.0 -IF_IN_OCTET=.1.3.6.1.2.1.2.2.1.10 -IF_OUT_OCTET=.1.3.6.1.2.1.2.2.1.16 -IF_SPEED=.1.3.6.1.2.1.2.2.1.5 -IF_DESC=.1.3.6.1.2.1.2.2.1.2 -IF_IN_ERROR=.1.3.6.1.2.1.2.2.1.14 -IF_OUT_ERROR=.1.3.6.1.2.1.2.2.1.20 -IF_OPERSTATUS=.1.3.6.1.2.1.2.2.1.8 - - +[GLOBAL] +DIR_NAGIOS=@INSTALL_DIR_NAGIOS@/ +NAGIOS_PLUGINS=@NAGIOS_PLUGINS@/ +NAGIOS_ETC=@NAGIOS_ETC@/ + +[NT] +CPU=.1.3.6.1.2.1.25.3.3.1.2 +HD_USED=.1.3.6.1.2.1.25.2.3.1.6 +HD_NAME=.1.3.6.1.2.1.25.2.3.1.3 + +[CISCO] +NB_CONNECT=.1.3.6.1.4.1.9.9.147.1.2.2.2.1.5.40.6 + +[UNIX] +CPU_USER=.1.3.6.1.4.1.2021.11.50.0 +CPU_SYSTEM=.1.3.6.1.4.1.2021.11.52.0 +CPU_LOAD_1M =.1.3.6.1.4.1.2021.10.1.3.1 +CPU_LOAD_5M =.1.3.6.1.4.1.2021.10.1.3.2 +CPU_LOAD_15M =.1.3.6.1.4.1.2021.10.1.3.3 + +[DELL] +TEMP=.1.3.6.1.4.1.674.10892.1.700.20.1.6.1 + +[ALTEON] +VIRT=1.3.6.1.4.1.1872.2.1.8.2.7.1.3.1 +FRONT=1.3.6.1.4.1.1872.2.1.8.2.5.1.3.1 + +[MIB2] +SW_RUNNAME=.1.3.6.1.2.1.25.4.2.1.2 +SW_RUNINDEX=.1.3.6.1.2.1.25.4.2.1.1 +SW_RUNSTATUS=.1.3.6.1.2.1.25.4.2.1.7 +HR_STORAGE_DESCR=.1.3.6.1.2.1.25.2.3.1.3 +HR_STORAGE_ALLOCATION_UNITS=.1.3.6.1.2.1.25.2.3.1.4 +HR_STORAGE_SIZE=.1.3.6.1.2.1.25.2.3.1.5 +HR_STORAGE_USED=.1.3.6.1.2.1.25.2.3.1.6 +OBJECTID=.1.3.6.1.2.1.1.1.0 +UPTIME_WINDOWS=.1.3.6.1.2.1.1.3.0 +UPTIME_OTHER=.1.3.6.1.2.1.25.1.1.0 +IF_IN_OCTET=.1.3.6.1.2.1.2.2.1.10 +IF_OUT_OCTET=.1.3.6.1.2.1.2.2.1.16 +IF_SPEED=.1.3.6.1.2.1.2.2.1.5 +IF_DESC=.1.3.6.1.2.1.2.2.1.2 +IF_IN_ERROR=.1.3.6.1.2.1.2.2.1.14 +IF_OUT_ERROR=.1.3.6.1.2.1.2.2.1.20 +IF_OPERSTATUS=.1.3.6.1.2.1.2.2.1.8 + + diff --git a/src/centreon.pm b/src/centreon.pm index eb05edc02..f3bc2c1cd 100644 --- a/src/centreon.pm +++ b/src/centreon.pm @@ -1,102 +1,102 @@ -################################################################### -# Oreon is developped with GPL Licence 2.0 -# -# GPL License: http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt -# -# Developped by : Julien Mathis - Romain Le Merlus -# Mathavarajan Sugumaran -# -################################################################### -# 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 -#################################################################### -# -# Plugin init -# -package centreon; - -use Exporter (); -use FindBin qw($Bin); -use lib "$FindBin::Bin"; -use lib "@NAGIOS_PLUGINS@"; - -use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS); -use utils qw($TIMEOUT %ERRORS &print_revision &support); - -if (eval "require Config::IniFiles" ) { - use Config::IniFiles; -} else { - print "Unable to load Config::IniFiles\n"; - exit $ERRORS{'UNKNOWN'}; -} - -### RRDTOOL Module -use lib qw(@RRDTOOL_PERL_LIB@ ../lib/perl); -if (eval "require RRDs" ) { - use RRDs; -} else { - print "Unable to load RRDs perl module\n"; - exit $ERRORS{'UNKNOWN'}; -} - -# On défini une version pour les vérifications -#$VERSION = do { my @r = (q$Revision: XXX $ =~ /\d+/g); sprintf "%d."."%02d" x $#r, @r }; - -our @ISA = qw(Exporter); -our @EXPORT_OK = qw(get_parameters); -our @EXPORT = @EXPORT_OK; - -my $params_file = "centreon.conf"; -my @ds = ("a","b","c","d","e","f","g","h","i","j","k","l"); - -############################################################################### -# Get all parameters from the ini file -############################################################################### -sub get_parameters { - $params_file = "@NAGIOS_PLUGINS@/$params_file"; - unless (-e $params_file) { - print "Unknown - In centreon.pm :: $params_file :: $!\n"; - exit $ERRORS{'UNKNOWN'}; - } - my %centreon; - tie %centreon, 'Config::IniFiles', ( -file => $params_file ); - return %centreon; -} - -1; - -__END__ - -=head1 NAME - -centreon - shared module for Oreon plugins - -=head1 SYNOPSIS - - use centreon; - centreon::get_parameters() - -=head1 DESCRIPTION - -=head2 Functions - - -=head1 AUTHOR - -Mathieu Chateau Emathieu.chateau@lsafrance.comE -Christophe Coraboeuf Eccoraboeuf@oreon-project.orgE - -=cut - - - - +################################################################### +# Oreon is developped with GPL Licence 2.0 +# +# GPL License: http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt +# +# Developped by : Julien Mathis - Romain Le Merlus +# Mathavarajan Sugumaran +# +################################################################### +# 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 +#################################################################### +# +# Plugin init +# +package centreon; + +use Exporter (); +use FindBin qw($Bin); +use lib "$FindBin::Bin"; +use lib "@NAGIOS_PLUGINS@"; + +use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS); +use utils qw($TIMEOUT %ERRORS &print_revision &support); + +if (eval "require Config::IniFiles" ) { + use Config::IniFiles; +} else { + print "Unable to load Config::IniFiles\n"; + exit $ERRORS{'UNKNOWN'}; +} + +### RRDTOOL Module +use lib qw(@RRDTOOL_PERL_LIB@ ../lib/perl); +if (eval "require RRDs" ) { + use RRDs; +} else { + print "Unable to load RRDs perl module\n"; + exit $ERRORS{'UNKNOWN'}; +} + +# On défini une version pour les vérifications +#$VERSION = do { my @r = (q$Revision: XXX $ =~ /\d+/g); sprintf "%d."."%02d" x $#r, @r }; + +our @ISA = qw(Exporter); +our @EXPORT_OK = qw(get_parameters); +our @EXPORT = @EXPORT_OK; + +my $params_file = "centreon.conf"; +my @ds = ("a","b","c","d","e","f","g","h","i","j","k","l"); + +############################################################################### +# Get all parameters from the ini file +############################################################################### +sub get_parameters { + $params_file = "@NAGIOS_PLUGINS@/$params_file"; + unless (-e $params_file) { + print "Unknown - In centreon.pm :: $params_file :: $!\n"; + exit $ERRORS{'UNKNOWN'}; + } + my %centreon; + tie %centreon, 'Config::IniFiles', ( -file => $params_file ); + return %centreon; +} + +1; + +__END__ + +=head1 NAME + +centreon - shared module for Oreon plugins + +=head1 SYNOPSIS + + use centreon; + centreon::get_parameters() + +=head1 DESCRIPTION + +=head2 Functions + + +=head1 AUTHOR + +Mathieu Chateau Emathieu.chateau@lsafrance.comE +Christophe Coraboeuf Eccoraboeuf@oreon-project.orgE + +=cut + + + + diff --git a/src/check_centreon_snmp_cpu b/src/check_centreon_snmp_cpu index a575fbdae..59846711c 100644 --- a/src/check_centreon_snmp_cpu +++ b/src/check_centreon_snmp_cpu @@ -1,194 +1,194 @@ -#! /usr/bin/perl -w -################################################################### -# Oreon is developped with GPL Licence 2.0 -# -# GPL License: http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt -# -# Developped by : Julien Mathis - Romain Le Merlus -# -################################################################### -# 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); - -if (eval "require centreon" ) { - use centreon qw(get_parameters); - use vars qw($VERSION %centreon); - %centreon = get_parameters(); -} else { - print "Unable to load centreon 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_H $opt_c $opt_w $opt_D $snmp $opt_k $opt_u $opt_p @critical @warning); - -# Plugin var init - -my($return_code); - -$PROGNAME = "$0"; -sub print_help (); -sub print_usage (); - -Getopt::Long::Configure('bundling'); -GetOptions - ("h" => \$opt_h, "help" => \$opt_h, - "u=s" => \$opt_u, "username=s" => \$opt_u, - "p=s" => \$opt_p, "password=s" => \$opt_p, - "k=s" => \$opt_k, "key=s" => \$opt_k, - "V" => \$opt_V, "version" => \$opt_V, - "v=s" => \$opt_v, "snmp=s" => \$opt_v, - "C=s" => \$opt_C, "community=s" => \$opt_C, - "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.2 $'); - exit $ERRORS{'OK'}; -} - -if ($opt_h) { - print_help(); - exit $ERRORS{'OK'}; -} - -if (!$opt_H) { - print_usage(); - exit $ERRORS{'OK'}; -} - -my $snmp = "1"; -$snmp = $opt_v if ($opt_v && $opt_v =~ /^[0-9]$/); - -$opt_c = 95 if (defined($opt_c) || !$opt_c); -$opt_w = 95 if (defined($opt_w) || !$opt_w); - -if ($snmp eq "3") { - if (!$opt_u) { - print "Option -u (--username) is required for snmpV3\n"; - exit $ERRORS{'UNKNOWN'}; - } - if (!$opt_p && !$opt_k) { - print "Option -k (--key) or -p (--password) is required for snmpV3\n"; - exit $ERRORS{'UNKNOWN'}; - } elsif ($opt_p && $opt_k) { - print "Only option -k (--key) or -p (--password) is needed for snmpV3\n"; - exit $ERRORS{'UNKNOWN'}; - } -} - -$opt_C = "public" if (!$opt_C); - -my $name = $0; -$name =~ s/\.pl.*//g; - -# Plugin snmp requests - -my $OID_CPU = "1.3.6.1.2.1.25.3.3.1.2"; - -my ($session, $error); -if ($snmp eq "1" || $snmp eq "2") { - ($session, $error) = Net::SNMP->session(-hostname => $opt_H, -community => $opt_C, -version => $snmp); - if (!defined($session)) { - print("UNKNOWN: SNMP 1 or 2 Session : $error\n"); - exit $ERRORS{'UNKNOWN'}; - } -}elsif ($opt_k) { - ($session, $error) = Net::SNMP->session(-hostname => $opt_H, -version => $snmp, -username => $opt_u, -authkey => $opt_k); - if (!defined($session)) { - print("UNKNOWN: SNMP Session : $error\n"); - 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)) { - print("UNKNOWN: SNMP Session : $error\n"); - exit $ERRORS{'UNKNOWN'}; - } -} - -# Get all datas -my $result = $session->get_table(Baseoid => $OID_CPU); -if (!defined($result)) { - printf("ERROR when getting CPU percentage use values : ProcessorLoad Table : %s.\n", $session->error); - $session->close; - exit $ERRORS{'UNKNOWN'}; -} - -# Get all values and computes average cpu. -my $cpu = 0; -my $i = 0; -my @cpulist; -foreach my $key ( oid_lex_sort(keys %$result)) { - my @oid_list = split (/\./,$key); - my $index = pop (@oid_list); - $cpulist[$i] = $$result{$key}; - $cpu += $$result{$key}; - $i++; -} -undef($result); - -$cpu /= $i; - -# Plugin return code -my $status = "OK"; -if ($opt_w <= $cpu) { - $status = "WARNING"; -} elsif ($opt_c <= $cpu) { - $status = "CRITICAL"; -} - -my $str = "Utilisation moyenne du CPU : ".$cpu."%|avg=".$cpu."%"; -for ($i = 0; defined($cpulist[$i]); $i++){ - $str .= " cpu$i=".$cpulist[$i]."%"; -} -print $str."\n"; -undef($str); -exit $ERRORS{$status}; - -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 " -c (--critical) Three critical tresholds (defaults : 2,4,6)\n"; - print " -w (--warning) Three warning tresholds (defaults : 1,3,5)\n"; - print " -v (--snmp_version) 1 for SNMP v1 (default)\n"; - print " 2 for SNMP v2c\n"; - print " -k (--key) snmp V3 key\n"; - print " -p (--password) snmp V3 password\n"; - print " -u (--username) snmp v3 username \n"; - print " -V (--version) Plugin version\n"; - print " -h (--help) usage help\n"; -} - -sub print_help () { - print "##############################################\n"; - print "# Copyright (c) 2004-2007 Merethis #\n"; - print "# Bugs to http://bugs.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/old-licenses/gpl-2.0.txt +# +# Developped by : Julien Mathis - Romain Le Merlus +# +################################################################### +# 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); + +if (eval "require centreon" ) { + use centreon qw(get_parameters); + use vars qw($VERSION %centreon); + %centreon = get_parameters(); +} else { + print "Unable to load centreon 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_H $opt_c $opt_w $opt_D $snmp $opt_k $opt_u $opt_p @critical @warning); + +# Plugin var init + +my($return_code); + +$PROGNAME = "$0"; +sub print_help (); +sub print_usage (); + +Getopt::Long::Configure('bundling'); +GetOptions + ("h" => \$opt_h, "help" => \$opt_h, + "u=s" => \$opt_u, "username=s" => \$opt_u, + "p=s" => \$opt_p, "password=s" => \$opt_p, + "k=s" => \$opt_k, "key=s" => \$opt_k, + "V" => \$opt_V, "version" => \$opt_V, + "v=s" => \$opt_v, "snmp=s" => \$opt_v, + "C=s" => \$opt_C, "community=s" => \$opt_C, + "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.2 $'); + exit $ERRORS{'OK'}; +} + +if ($opt_h) { + print_help(); + exit $ERRORS{'OK'}; +} + +if (!$opt_H) { + print_usage(); + exit $ERRORS{'OK'}; +} + +my $snmp = "1"; +$snmp = $opt_v if ($opt_v && $opt_v =~ /^[0-9]$/); + +$opt_c = 95 if (defined($opt_c) || !$opt_c); +$opt_w = 95 if (defined($opt_w) || !$opt_w); + +if ($snmp eq "3") { + if (!$opt_u) { + print "Option -u (--username) is required for snmpV3\n"; + exit $ERRORS{'UNKNOWN'}; + } + if (!$opt_p && !$opt_k) { + print "Option -k (--key) or -p (--password) is required for snmpV3\n"; + exit $ERRORS{'UNKNOWN'}; + } elsif ($opt_p && $opt_k) { + print "Only option -k (--key) or -p (--password) is needed for snmpV3\n"; + exit $ERRORS{'UNKNOWN'}; + } +} + +$opt_C = "public" if (!$opt_C); + +my $name = $0; +$name =~ s/\.pl.*//g; + +# Plugin snmp requests + +my $OID_CPU = "1.3.6.1.2.1.25.3.3.1.2"; + +my ($session, $error); +if ($snmp eq "1" || $snmp eq "2") { + ($session, $error) = Net::SNMP->session(-hostname => $opt_H, -community => $opt_C, -version => $snmp); + if (!defined($session)) { + print("UNKNOWN: SNMP 1 or 2 Session : $error\n"); + exit $ERRORS{'UNKNOWN'}; + } +}elsif ($opt_k) { + ($session, $error) = Net::SNMP->session(-hostname => $opt_H, -version => $snmp, -username => $opt_u, -authkey => $opt_k); + if (!defined($session)) { + print("UNKNOWN: SNMP Session : $error\n"); + 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)) { + print("UNKNOWN: SNMP Session : $error\n"); + exit $ERRORS{'UNKNOWN'}; + } +} + +# Get all datas +my $result = $session->get_table(Baseoid => $OID_CPU); +if (!defined($result)) { + printf("ERROR when getting CPU percentage use values : ProcessorLoad Table : %s.\n", $session->error); + $session->close; + exit $ERRORS{'UNKNOWN'}; +} + +# Get all values and computes average cpu. +my $cpu = 0; +my $i = 0; +my @cpulist; +foreach my $key ( oid_lex_sort(keys %$result)) { + my @oid_list = split (/\./,$key); + my $index = pop (@oid_list); + $cpulist[$i] = $$result{$key}; + $cpu += $$result{$key}; + $i++; +} +undef($result); + +$cpu /= $i; + +# Plugin return code +my $status = "OK"; +if ($opt_w <= $cpu) { + $status = "WARNING"; +} elsif ($opt_c <= $cpu) { + $status = "CRITICAL"; +} + +my $str = "Utilisation moyenne du CPU : ".$cpu."%|avg=".$cpu."%"; +for ($i = 0; defined($cpulist[$i]); $i++){ + $str .= " cpu$i=".$cpulist[$i]."%"; +} +print $str."\n"; +undef($str); +exit $ERRORS{$status}; + +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 " -c (--critical) Three critical tresholds (defaults : 2,4,6)\n"; + print " -w (--warning) Three warning tresholds (defaults : 1,3,5)\n"; + print " -v (--snmp_version) 1 for SNMP v1 (default)\n"; + print " 2 for SNMP v2c\n"; + print " -k (--key) snmp V3 key\n"; + print " -p (--password) snmp V3 password\n"; + print " -u (--username) snmp v3 username \n"; + print " -V (--version) Plugin version\n"; + print " -h (--help) usage help\n"; +} + +sub print_help () { + print "##############################################\n"; + print "# Copyright (c) 2004-2007 Merethis #\n"; + print "# Bugs to http://bugs.oreon-project.org/ #\n"; + print "##############################################\n"; + print_usage(); + print "\n"; } \ No newline at end of file diff --git a/src/check_centreon_snmp_loadaverage b/src/check_centreon_snmp_loadaverage index 6765a533e..82be0ac2d 100644 --- a/src/check_centreon_snmp_loadaverage +++ b/src/check_centreon_snmp_loadaverage @@ -1,203 +1,203 @@ -#! /usr/bin/perl -w -################################################################### -# Oreon is developped with GPL Licence 2.0 -# -# GPL License: http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt -# -# Developped by : Julien Mathis - Romain Le Merlus -# Mathavarajan Sugumaran -# -################################################################### -# 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); - -if (eval "require centreon" ) { - use centreon qw(get_parameters); - use vars qw($VERSION %centreon); - %centreon = get_parameters(); -} else { - print "Unable to load centreon 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_H $opt_c $opt_w $opt_D $snmp $opt_k $opt_u $opt_p @critical @warning); - -# Plugin var init - -my($return_code); - -$PROGNAME = "$0"; -sub print_help (); -sub print_usage (); - -Getopt::Long::Configure('bundling'); -GetOptions - ("h" => \$opt_h, "help" => \$opt_h, - "u=s" => \$opt_u, "username=s" => \$opt_u, - "p=s" => \$opt_p, "password=s" => \$opt_p, - "k=s" => \$opt_k, "key=s" => \$opt_k, - "V" => \$opt_V, "version" => \$opt_V, - "v=s" => \$opt_v, "snmp=s" => \$opt_v, - "C=s" => \$opt_C, "community=s" => \$opt_C, - "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.2 $'); - exit $ERRORS{'OK'}; -} - -if ($opt_h) { - print_help(); - exit $ERRORS{'OK'}; -} - -if (!$opt_H) { - print_usage(); - exit $ERRORS{'OK'}; -} - -my $snmp = "1"; -$snmp = $opt_v if ($opt_v && $opt_v =~ /^[0-9]$/); - -if ($opt_c && $opt_c =~ /^([0-9]+),([0-9]+),([0-9]+)$/) { - @critical = ($1,$2,$3); -} elsif (!defined($opt_c) && !$opt_c){ - @critical = ('2', '4', '6'); -} else { - print "Specify three critical treshold separated with a coma\n"; - exit $ERRORS{'OK'}; -} - -if ($opt_w && $opt_w =~ /^([0-9]+),([0-9]+),([0-9]+)$/) { - @warning = ($1,$2,$3); -} elsif (!defined($opt_w) && !$opt_w) { - @warning = ('1', '3', '5'); -} else { - print "Specify three warning treshold separated with a coma\n"; - exit $ERRORS{'OK'}; -} - -for (my $i = 0; $i < scalar(@warning); $i++) { - if ($warning[$i] >= $critical[$i]) { - print "Critical tresholds must be superior to warning tresholds.\n"; - exit $ERRORS{'OK'}; - } -} - -if ($snmp eq "3") { - if (!$opt_u) { - 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"; - exit $ERRORS{'OK'}; - } elsif ($opt_p && $opt_k) { - print "Only option -k (--key) or -p (--password) is needed for snmpV3\n"; - exit $ERRORS{'OK'}; - } -} - -$opt_C = "public" if (!$opt_C); - -my $name = $0; -$name =~ s/\.pl.*//g; - -# Plugin snmp requests - -my $OID_CPULOAD_1 = $centreon{UNIX}{CPU_LOAD_1M}; -my $OID_CPULOAD_5 = $centreon{UNIX}{CPU_LOAD_5M}; -my $OID_CPULOAD_15 =$centreon{UNIX}{CPU_LOAD_15M}; - -my ($session, $error); -if ($snmp eq "1" || $snmp eq "2") { - ($session, $error) = Net::SNMP->session(-hostname => $opt_H, -community => $opt_C, -version => $snmp); - if (!defined($session)) { - print("UNKNOWN: SNMP Session : $error\n"); - exit $ERRORS{'UNKNOWN'}; - } -}elsif ($opt_k) { - ($session, $error) = Net::SNMP->session(-hostname => $opt_H, -version => $snmp, -username => $opt_u, -authkey => $opt_k); - if (!defined($session)) { - print("UNKNOWN: SNMP Session : $error\n"); - 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)) { - print("UNKNOWN: SNMP Session : $error\n"); - exit $ERRORS{'UNKNOWN'}; - } -} - -my $result = $session->get_request( - -varbindlist => [$OID_CPULOAD_1, $OID_CPULOAD_5, $OID_CPULOAD_15 ] - ); -if (!defined($result)) { - printf("UNKNOWN: %s.\n", $session->error); - $session->close; - exit $ERRORS{'UNKNOWN'}; -} - -my $un = $result->{$OID_CPULOAD_1}; -my $cinq = $result->{$OID_CPULOAD_5}; -my $quinze = $result->{$OID_CPULOAD_15}; - -# Plugin return code -my $status = "OK"; - -$status = "WARNING" if ($warning[0] <= $un || $warning[1] <= $cinq || $warning[2] <= $quinze); -$status = "CRITICAL" if ($critical[0] <= $un || $critical[1] <= $cinq || $critical[2] <= $quinze); - -# Print output -print "load average: ".$un.", ".$cinq.", ".$quinze.".|load1=".$un." load5=".$cinq." load15=".$quinze."\n"; -exit $ERRORS{$status}; - -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 " -c (--critical) Three critical tresholds (defaults : 2,4,6)\n"; - print " -w (--warning) Three warning tresholds (defaults : 1,3,5)\n"; - print " -v (--snmp_version) 1 for SNMP v1 (default)\n"; - print " 2 for SNMP v2c\n"; - print " -k (--key) snmp V3 key\n"; - print " -p (--password) snmp V3 password\n"; - print " -u (--username) snmp v3 username \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"; +#! /usr/bin/perl -w +################################################################### +# Oreon is developped with GPL Licence 2.0 +# +# GPL License: http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt +# +# Developped by : Julien Mathis - Romain Le Merlus +# Mathavarajan Sugumaran +# +################################################################### +# 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); + +if (eval "require centreon" ) { + use centreon qw(get_parameters); + use vars qw($VERSION %centreon); + %centreon = get_parameters(); +} else { + print "Unable to load centreon 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_H $opt_c $opt_w $opt_D $snmp $opt_k $opt_u $opt_p @critical @warning); + +# Plugin var init + +my($return_code); + +$PROGNAME = "$0"; +sub print_help (); +sub print_usage (); + +Getopt::Long::Configure('bundling'); +GetOptions + ("h" => \$opt_h, "help" => \$opt_h, + "u=s" => \$opt_u, "username=s" => \$opt_u, + "p=s" => \$opt_p, "password=s" => \$opt_p, + "k=s" => \$opt_k, "key=s" => \$opt_k, + "V" => \$opt_V, "version" => \$opt_V, + "v=s" => \$opt_v, "snmp=s" => \$opt_v, + "C=s" => \$opt_C, "community=s" => \$opt_C, + "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.2 $'); + exit $ERRORS{'OK'}; +} + +if ($opt_h) { + print_help(); + exit $ERRORS{'OK'}; +} + +if (!$opt_H) { + print_usage(); + exit $ERRORS{'OK'}; +} + +my $snmp = "1"; +$snmp = $opt_v if ($opt_v && $opt_v =~ /^[0-9]$/); + +if ($opt_c && $opt_c =~ /^([0-9]+),([0-9]+),([0-9]+)$/) { + @critical = ($1,$2,$3); +} elsif (!defined($opt_c) && !$opt_c){ + @critical = ('2', '4', '6'); +} else { + print "Specify three critical treshold separated with a coma\n"; + exit $ERRORS{'OK'}; +} + +if ($opt_w && $opt_w =~ /^([0-9]+),([0-9]+),([0-9]+)$/) { + @warning = ($1,$2,$3); +} elsif (!defined($opt_w) && !$opt_w) { + @warning = ('1', '3', '5'); +} else { + print "Specify three warning treshold separated with a coma\n"; + exit $ERRORS{'OK'}; +} + +for (my $i = 0; $i < scalar(@warning); $i++) { + if ($warning[$i] >= $critical[$i]) { + print "Critical tresholds must be superior to warning tresholds.\n"; + exit $ERRORS{'OK'}; + } +} + +if ($snmp eq "3") { + if (!$opt_u) { + 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"; + exit $ERRORS{'OK'}; + } elsif ($opt_p && $opt_k) { + print "Only option -k (--key) or -p (--password) is needed for snmpV3\n"; + exit $ERRORS{'OK'}; + } +} + +$opt_C = "public" if (!$opt_C); + +my $name = $0; +$name =~ s/\.pl.*//g; + +# Plugin snmp requests + +my $OID_CPULOAD_1 = $centreon{UNIX}{CPU_LOAD_1M}; +my $OID_CPULOAD_5 = $centreon{UNIX}{CPU_LOAD_5M}; +my $OID_CPULOAD_15 =$centreon{UNIX}{CPU_LOAD_15M}; + +my ($session, $error); +if ($snmp eq "1" || $snmp eq "2") { + ($session, $error) = Net::SNMP->session(-hostname => $opt_H, -community => $opt_C, -version => $snmp); + if (!defined($session)) { + print("UNKNOWN: SNMP Session : $error\n"); + exit $ERRORS{'UNKNOWN'}; + } +}elsif ($opt_k) { + ($session, $error) = Net::SNMP->session(-hostname => $opt_H, -version => $snmp, -username => $opt_u, -authkey => $opt_k); + if (!defined($session)) { + print("UNKNOWN: SNMP Session : $error\n"); + 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)) { + print("UNKNOWN: SNMP Session : $error\n"); + exit $ERRORS{'UNKNOWN'}; + } +} + +my $result = $session->get_request( + -varbindlist => [$OID_CPULOAD_1, $OID_CPULOAD_5, $OID_CPULOAD_15 ] + ); +if (!defined($result)) { + printf("UNKNOWN: %s.\n", $session->error); + $session->close; + exit $ERRORS{'UNKNOWN'}; +} + +my $un = $result->{$OID_CPULOAD_1}; +my $cinq = $result->{$OID_CPULOAD_5}; +my $quinze = $result->{$OID_CPULOAD_15}; + +# Plugin return code +my $status = "OK"; + +$status = "WARNING" if ($warning[0] <= $un || $warning[1] <= $cinq || $warning[2] <= $quinze); +$status = "CRITICAL" if ($critical[0] <= $un || $critical[1] <= $cinq || $critical[2] <= $quinze); + +# Print output +print "load average: ".$un.", ".$cinq.", ".$quinze.".|load1=".$un." load5=".$cinq." load15=".$quinze."\n"; +exit $ERRORS{$status}; + +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 " -c (--critical) Three critical tresholds (defaults : 2,4,6)\n"; + print " -w (--warning) Three warning tresholds (defaults : 1,3,5)\n"; + print " -v (--snmp_version) 1 for SNMP v1 (default)\n"; + print " 2 for SNMP v2c\n"; + print " -k (--key) snmp V3 key\n"; + print " -p (--password) snmp V3 password\n"; + print " -u (--username) snmp v3 username \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"; } \ No newline at end of file diff --git a/src/check_centreon_snmp_memory b/src/check_centreon_snmp_memory index c6e4e5b3e..ee3129f31 100644 --- a/src/check_centreon_snmp_memory +++ b/src/check_centreon_snmp_memory @@ -1,253 +1,253 @@ -#! /usr/bin/perl -w -################################################################### -# Oreon is developped with GPL Licence 2.0 -# -# GPL License: http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt -# -# Developped by : Julien Mathis - Romain Le Merlus -# Mathavarajan Sugumaran -# -################################################################### -# 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); - -if (eval "require centreon" ) { - use centreon qw(get_parameters); - use vars qw($VERSION %centreon); - %centreon=get_parameters(); -} else { - print "Unable to load centreon perl module\n"; - exit $ERRORS{'UNKNOWN'}; -} - -use vars qw($PROGNAME); -use Getopt::Long; -use vars qw($opt_V $opt_h $opt_g $opt_v $opt_C $opt_w $opt_c $opt_s $opt_H @test); -my $pathtorrdbase = $centreon{GLOBAL}{DIR_RRDTOOL}; - -## -## Plugin var init -## - -my ($hrStorageDescr, $hrStorageAllocationUnits, $hrStorageSize, $hrStorageUsed); -my ($AllocationUnits, $Size, $Used); -my ($tot, $used, $pourcent, $return_code); - -$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, - "w=s" => \$opt_w, "warning=s" => \$opt_w, - "c=s" => \$opt_c, "critical=s" => \$opt_c, - "s=s" => \$opt_s, "swap=s" => \$opt_s, - "H=s" => \$opt_H, "hostname=s" => \$opt_H); - - -if ($opt_V) { - print_revision($PROGNAME,'$Revision: 1.2 $'); - 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 = "2"); -my $snmp = $1 if ($opt_v =~ /(\d)/); - -($opt_C) || ($opt_C = shift) || ($opt_C = "public"); - -($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'}; -} - -my $swap_limit; -if ($opt_s) -{ - ($opt_s) || ($opt_s = shift) || ($opt_s = 10); - $swap_limit = $1 if ($opt_s =~ /([0-9]+)/); -} - -my $start=time; -my $name = $0; - -## Plugin snmp requests - -# my $OID_hrStorageDescr = $centreon{MIB2}{HR_STORAGE_DESCR}; -# my $OID_hrStorageAllocationUnits =$centreon{MIB2}{HR_STORAGE_ALLOCATION_UNITS}; -# my $OID_hrStorageSize =$centreon{MIB2}{HR_STORAGE_SIZE}; -# my $OID_hrStorageUsed =$centreon{MIB2}{HR_STORAGE_USED}; - -# create a SNMP session - -my ( $session, $error ) = Net::SNMP->session(-hostname => $opt_H,-community => $opt_C, -version => $snmp); -if ( !defined($session) ) { - print("CRITICAL: SNMP Session : $error"); - exit $ERRORS{'CRITICAL'}; -} - -#################### -#### snmp request -## - -my $OID_descr_storage = ".1.3.6.1.2.1.25.2.3.1.3"; #"1.3.6.1.2.1.25.2.3.1.1"; -my $result = $session->get_table(Baseoid => $OID_descr_storage); -if (!defined($result)) { - printf("ERROR: Description Table hrStorageType : %s.\n", $session->error); - $session->close; - exit $ERRORS{'UNKNOWN'}; -} - -my ($virt_alloc, my $virt_used, my $virt_size); - -my $indexV = 0; -my $indexR = 0; -foreach my $key (oid_lex_sort(keys %$result)) { - if ($result->{$key} =~ m/Swap|Virtual/) { - my @cpt = split /\./,$key; - $indexV = $cpt[scalar(@cpt) - 1];; - } - if ($result->{$key} =~ m/Real|Physical/) { - my @cpt = split /\./,$key; - $indexR = $cpt[scalar(@cpt)-1]; - } -} -if ($indexV == 0 || $indexR == 0) { - printf("ERROR: cannot find ram information"); - exit $ERRORS{'UNKNOWN'}; -} -my $OID_hrStorage_used = ".1.3.6.1.2.1.25.2.3.1.6"; -my $OID_Swap_storage_used = ".1.3.6.1.2.1.25.2.3.1.6.".$indexV; -my $OID_RealM_storage_used = ".1.3.6.1.2.1.25.2.3.1.6.".$indexR; - -my $used_mem = $session->get_table(Baseoid => $OID_hrStorage_used); -if (!defined($used_mem)) { - printf("ERROR: Description Table hrStorageUsed : %s.\n", $session->error); - $session->close; - exit $ERRORS{'UNKNOWN'}; -} - -my $OID_hrStorage_size = ".1.3.6.1.2.1.25.2.3.1.5"; -my $OID_Swap_storage_size = ".1.3.6.1.2.1.25.2.3.1.5.".$indexV; -my $OID_RealM_storage_size = ".1.3.6.1.2.1.25.2.3.1.5.".$indexR; - -my $total_mem = $session->get_table(Baseoid => $OID_hrStorage_size); -if (!defined($total_mem)) { - printf("ERROR: Description Table hrStorageSize : %s.\n", $session->error); - $session->close; - exit $ERRORS{'UNKNOWN'}; -} - -my $OID_storage_allocationUnits = ".1.3.6.1.2.1.25.2.3.1.4"; -my $OID_Swap_storage_allocationUnits = ".1.3.6.1.2.1.25.2.3.1.4.".$indexV; -my $OID_RealM_storage_allocationUnits = ".1.3.6.1.2.1.25.2.3.1.4.".$indexR; -my $alloc_units = $session->get_table(Baseoid => $OID_storage_allocationUnits); -if (!defined($alloc_units)) { - printf("ERROR: Description Table hrStorageUsed : %s.\n", $session->error); - $session->close; - exit $ERRORS{'UNKNOWN'}; -} -my $swap_used = $used_mem->{$OID_Swap_storage_used} * $alloc_units->{$OID_Swap_storage_allocationUnits}; -my $realM_used = $used_mem->{$OID_RealM_storage_used} * $alloc_units->{$OID_RealM_storage_allocationUnits}; - -my $swap_size = $total_mem->{$OID_Swap_storage_size} * $alloc_units->{$OID_Swap_storage_allocationUnits}; -my $realM_size = $total_mem->{$OID_RealM_storage_size} * $alloc_units->{$OID_RealM_storage_allocationUnits}; -my $total_memory_used = $swap_used + $realM_used; -my $total_memory_size = $swap_size + $realM_size; - -# percentage of total, physical and swap memory used - -if ($swap_size eq "0"){ - $swap_size = 1; -} - -my $percent_used = ($total_memory_used/$total_memory_size)*100; -my $percent_swap_used = ($swap_used/$swap_size) * 100; -my $percent_realM_used = ($realM_used/$realM_size) * 100; -$percent_swap_used =~ s/\.[0-9]+//; -$percent_used =~ s/\.[0-9]+//; -$percent_realM_used =~ s/\.[0-9]+//; - -# return - -if(($opt_s) && ($opt_s =~ /([0-9]+)/)) -{ - if(($percent_realM_used >= 99) && ($percent_swap_used > $swap_limit)) - { - print "swap threshold (".$opt_s."%) excedeed : total memory used : ".$percent_used."%, ram used : ".$percent_realM_used."%, swap used : ".$percent_swap_used."% | used=".$total_memory_used."o size=".$total_memory_size."o\n"; - exit $ERRORS{'CRITICAL'}; - } -} - -if ($percent_used >= $opt_c){ - print "threshold (".$opt_c."%) excedeed : total memory used : ".$percent_used."%, ram used : ".$percent_realM_used."%, swap used : ".$percent_swap_used."% | used=".$total_memory_used."o size=".$total_memory_size."o\n"; - exit $ERRORS{'CRITICAL'}; -} elsif ($percent_used >= $opt_w){ - print "threshold (".$opt_w."%) excedeed : total memory used : ".$percent_used."%, ram used : ".$percent_realM_used."%, swap used ".$percent_swap_used."% | used=".$total_memory_used."o size=".$total_memory_size."o\n"; - exit $ERRORS{'WARNING'}; -} else { - print "total memory used : ".$percent_used."% ram used : ".$percent_realM_used."%, swap used ".$percent_swap_used."% | used=".$total_memory_used."o size=".$total_memory_size."o\n"; - exit $ERRORS{'OK'}; -} - -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 " -V (--version) Plugin version\n"; - print " -h (--help) usage help\n"; - print " -c (--critical) percentage of memory used at which a critical message will be generated\n"; - print " -w (--warning) percentage of memory used at which a warning message will be generated\n"; - print " -s (--swap) limit of swap memory can reach before the service turns critical, while phyical memory is near 100%\n"; -} - -sub print_help () { - print "#=========================================\n"; - print "# Copyright (c) 2007 Merethis SARL =\n"; - print "# Developped by Julien Mathis =\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/old-licenses/gpl-2.0.txt +# +# Developped by : Julien Mathis - Romain Le Merlus +# Mathavarajan Sugumaran +# +################################################################### +# 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); + +if (eval "require centreon" ) { + use centreon qw(get_parameters); + use vars qw($VERSION %centreon); + %centreon=get_parameters(); +} else { + print "Unable to load centreon perl module\n"; + exit $ERRORS{'UNKNOWN'}; +} + +use vars qw($PROGNAME); +use Getopt::Long; +use vars qw($opt_V $opt_h $opt_g $opt_v $opt_C $opt_w $opt_c $opt_s $opt_H @test); +my $pathtorrdbase = $centreon{GLOBAL}{DIR_RRDTOOL}; + +## +## Plugin var init +## + +my ($hrStorageDescr, $hrStorageAllocationUnits, $hrStorageSize, $hrStorageUsed); +my ($AllocationUnits, $Size, $Used); +my ($tot, $used, $pourcent, $return_code); + +$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, + "w=s" => \$opt_w, "warning=s" => \$opt_w, + "c=s" => \$opt_c, "critical=s" => \$opt_c, + "s=s" => \$opt_s, "swap=s" => \$opt_s, + "H=s" => \$opt_H, "hostname=s" => \$opt_H); + + +if ($opt_V) { + print_revision($PROGNAME,'$Revision: 1.2 $'); + 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 = "2"); +my $snmp = $1 if ($opt_v =~ /(\d)/); + +($opt_C) || ($opt_C = shift) || ($opt_C = "public"); + +($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'}; +} + +my $swap_limit; +if ($opt_s) +{ + ($opt_s) || ($opt_s = shift) || ($opt_s = 10); + $swap_limit = $1 if ($opt_s =~ /([0-9]+)/); +} + +my $start=time; +my $name = $0; + +## Plugin snmp requests + +# my $OID_hrStorageDescr = $centreon{MIB2}{HR_STORAGE_DESCR}; +# my $OID_hrStorageAllocationUnits =$centreon{MIB2}{HR_STORAGE_ALLOCATION_UNITS}; +# my $OID_hrStorageSize =$centreon{MIB2}{HR_STORAGE_SIZE}; +# my $OID_hrStorageUsed =$centreon{MIB2}{HR_STORAGE_USED}; + +# create a SNMP session + +my ( $session, $error ) = Net::SNMP->session(-hostname => $opt_H,-community => $opt_C, -version => $snmp); +if ( !defined($session) ) { + print("CRITICAL: SNMP Session : $error"); + exit $ERRORS{'CRITICAL'}; +} + +#################### +#### snmp request +## + +my $OID_descr_storage = ".1.3.6.1.2.1.25.2.3.1.3"; #"1.3.6.1.2.1.25.2.3.1.1"; +my $result = $session->get_table(Baseoid => $OID_descr_storage); +if (!defined($result)) { + printf("ERROR: Description Table hrStorageType : %s.\n", $session->error); + $session->close; + exit $ERRORS{'UNKNOWN'}; +} + +my ($virt_alloc, my $virt_used, my $virt_size); + +my $indexV = 0; +my $indexR = 0; +foreach my $key (oid_lex_sort(keys %$result)) { + if ($result->{$key} =~ m/Swap|Virtual/) { + my @cpt = split /\./,$key; + $indexV = $cpt[scalar(@cpt) - 1];; + } + if ($result->{$key} =~ m/Real|Physical/) { + my @cpt = split /\./,$key; + $indexR = $cpt[scalar(@cpt)-1]; + } +} +if ($indexV == 0 || $indexR == 0) { + printf("ERROR: cannot find ram information"); + exit $ERRORS{'UNKNOWN'}; +} +my $OID_hrStorage_used = ".1.3.6.1.2.1.25.2.3.1.6"; +my $OID_Swap_storage_used = ".1.3.6.1.2.1.25.2.3.1.6.".$indexV; +my $OID_RealM_storage_used = ".1.3.6.1.2.1.25.2.3.1.6.".$indexR; + +my $used_mem = $session->get_table(Baseoid => $OID_hrStorage_used); +if (!defined($used_mem)) { + printf("ERROR: Description Table hrStorageUsed : %s.\n", $session->error); + $session->close; + exit $ERRORS{'UNKNOWN'}; +} + +my $OID_hrStorage_size = ".1.3.6.1.2.1.25.2.3.1.5"; +my $OID_Swap_storage_size = ".1.3.6.1.2.1.25.2.3.1.5.".$indexV; +my $OID_RealM_storage_size = ".1.3.6.1.2.1.25.2.3.1.5.".$indexR; + +my $total_mem = $session->get_table(Baseoid => $OID_hrStorage_size); +if (!defined($total_mem)) { + printf("ERROR: Description Table hrStorageSize : %s.\n", $session->error); + $session->close; + exit $ERRORS{'UNKNOWN'}; +} + +my $OID_storage_allocationUnits = ".1.3.6.1.2.1.25.2.3.1.4"; +my $OID_Swap_storage_allocationUnits = ".1.3.6.1.2.1.25.2.3.1.4.".$indexV; +my $OID_RealM_storage_allocationUnits = ".1.3.6.1.2.1.25.2.3.1.4.".$indexR; +my $alloc_units = $session->get_table(Baseoid => $OID_storage_allocationUnits); +if (!defined($alloc_units)) { + printf("ERROR: Description Table hrStorageUsed : %s.\n", $session->error); + $session->close; + exit $ERRORS{'UNKNOWN'}; +} +my $swap_used = $used_mem->{$OID_Swap_storage_used} * $alloc_units->{$OID_Swap_storage_allocationUnits}; +my $realM_used = $used_mem->{$OID_RealM_storage_used} * $alloc_units->{$OID_RealM_storage_allocationUnits}; + +my $swap_size = $total_mem->{$OID_Swap_storage_size} * $alloc_units->{$OID_Swap_storage_allocationUnits}; +my $realM_size = $total_mem->{$OID_RealM_storage_size} * $alloc_units->{$OID_RealM_storage_allocationUnits}; +my $total_memory_used = $swap_used + $realM_used; +my $total_memory_size = $swap_size + $realM_size; + +# percentage of total, physical and swap memory used + +if ($swap_size eq "0"){ + $swap_size = 1; +} + +my $percent_used = ($total_memory_used/$total_memory_size)*100; +my $percent_swap_used = ($swap_used/$swap_size) * 100; +my $percent_realM_used = ($realM_used/$realM_size) * 100; +$percent_swap_used =~ s/\.[0-9]+//; +$percent_used =~ s/\.[0-9]+//; +$percent_realM_used =~ s/\.[0-9]+//; + +# return + +if(($opt_s) && ($opt_s =~ /([0-9]+)/)) +{ + if(($percent_realM_used >= 99) && ($percent_swap_used > $swap_limit)) + { + print "swap threshold (".$opt_s."%) excedeed : total memory used : ".$percent_used."%, ram used : ".$percent_realM_used."%, swap used : ".$percent_swap_used."% | used=".$total_memory_used."o size=".$total_memory_size."o\n"; + exit $ERRORS{'CRITICAL'}; + } +} + +if ($percent_used >= $opt_c){ + print "threshold (".$opt_c."%) excedeed : total memory used : ".$percent_used."%, ram used : ".$percent_realM_used."%, swap used : ".$percent_swap_used."% | used=".$total_memory_used."o size=".$total_memory_size."o\n"; + exit $ERRORS{'CRITICAL'}; +} elsif ($percent_used >= $opt_w){ + print "threshold (".$opt_w."%) excedeed : total memory used : ".$percent_used."%, ram used : ".$percent_realM_used."%, swap used ".$percent_swap_used."% | used=".$total_memory_used."o size=".$total_memory_size."o\n"; + exit $ERRORS{'WARNING'}; +} else { + print "total memory used : ".$percent_used."% ram used : ".$percent_realM_used."%, swap used ".$percent_swap_used."% | used=".$total_memory_used."o size=".$total_memory_size."o\n"; + exit $ERRORS{'OK'}; +} + +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 " -V (--version) Plugin version\n"; + print " -h (--help) usage help\n"; + print " -c (--critical) percentage of memory used at which a critical message will be generated\n"; + print " -w (--warning) percentage of memory used at which a warning message will be generated\n"; + print " -s (--swap) limit of swap memory can reach before the service turns critical, while phyical memory is near 100%\n"; +} + +sub print_help () { + print "#=========================================\n"; + print "# Copyright (c) 2007 Merethis SARL =\n"; + print "# Developped by Julien Mathis =\n"; + print "# Bugs to http://www.oreon-project.org/ =\n"; + print "#=========================================\n"; + print_usage(); + print "\n"; +} diff --git a/src/check_centreon_snmp_packetErrors b/src/check_centreon_snmp_packetErrors index ac19867b4..03df7776a 100644 --- a/src/check_centreon_snmp_packetErrors +++ b/src/check_centreon_snmp_packetErrors @@ -1,244 +1,244 @@ -#! /usr/bin/perl -w -################################################################### -# Oreon is developped with GPL Licence 2.0 -# -# GPL License: http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt -# -# Developped by : Julien Mathis - Romain Le Merlus -# Mathavarajan Sugumaran -# -################################################################### -# 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 -#################################################################### -# -# Plugin init -# - -use strict; -use Net::SNMP qw(:snmp oid_lex_sort); -use FindBin; -use lib "$FindBin::Bin"; -use lib "@NAGIOS_PLUGINS@"; -use utils qw($TIMEOUT %ERRORS &print_revision &support); - -if (eval "require centreon" ) { - use centreon qw(get_parameters); - use vars qw($VERSION %centreon); - %centreon = get_parameters(); -} else { - print "Unable to load centreon perl module\n"; - exit $ERRORS{'UNKNOWN'}; -} - -use vars qw($VERSION %centreon); -use vars qw(%centreon); -$VERSION = '$Revision: 1.2 $'; -$VERSION =~ s/^\$.*:\W(.*)\W.+?$/$1/; - -use vars qw($PROGNAME); -use Getopt::Long; -use vars qw($opt_V $opt_h $opt_v $opt_C $opt_H $opt_w $opt_c); - -# -# Plugin var init -# -$PROGNAME = "$0"; - -my ($row, @flg_created, @last_check_time, @last_in_errors, @last_out_errors, $result_in, $result_out, @nb_out_errors, @nb_in_errors, $update_time, $db_file); -my $pathtolibexecnt = $centreon{NAGIOS_PLUGINS}; - -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, - "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.2 $'); - exit $ERRORS{'OK'}; -} - -if ($opt_h) { - print_help(); - exit $ERRORS{'OK'}; -} - -################################################## -##### Verify Options -## - -$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"); -($opt_c) || ($opt_c = shift) || ($opt_c = 100); -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'}; -} - -my $start=time; - - -################################################# -##### Plugin snmp requests -## - -my $OID_IN_ERRORS = ".1.3.6.1.2.1.2.2.1.14"; -my $OID_OUT_ERRORS = ".1.3.6.1.2.1.2.2.1.20"; - - -# create a SNMP session - -my ($session, $error) = Net::SNMP->session(-hostname => $opt_H, -community => $opt_C, -version => $snmp); -if (!defined($session)) { - print("UNKNOWN: SNMP Session : $error"); - exit $ERRORS{'UNKNOWN'}; -} - -####### Get IN ERRORS - -$result_in = $session->get_table(Baseoid => $OID_IN_ERRORS); -if (!defined($result_in)) { - printf("ERROR: IN_ERRORS : %s.\n", $session->error); - $session->close; - exit $ERRORS{'UNKNOWN'}; -} - -# loop for each interface -foreach my $err (oid_lex_sort(keys %$result_in)) { - $nb_in_errors[scalar(@nb_in_errors)] = $result_in->{$err}; -} -# ####### Get OUT ERRORS - -$result_out = $session->get_table(Baseoid => $OID_OUT_ERRORS); -if (!defined($result_out)) { - printf("ERROR: OUT_ERRORS : %s.\n", $session->error); - $session->close; - exit $ERRORS{'UNKNOWN'}; -} -foreach my $err (oid_lex_sort(keys %$result_out)) { - $nb_out_errors[scalar(@nb_out_errors)] = $result_out->{$err}; -} - -# ############################################# -# ##### read and write in buffer file -# ## - -for (my $i = 0; $i < scalar(@nb_in_errors); $i++) { - if (-e "@CENTPLUGINS_TMP@/packet_errors_if".$i."_".$opt_H.".tmp") { - open(FILE,"<"."@CENTPLUGINS_TMP@/packet_errors_if".$i."_".$opt_H.".tmp"); - while($row = ){ - my @last_values = split(":",$row); - $last_check_time[$i] = $last_values[0]; - $last_in_errors[$i] = $last_values[1]; - $last_out_errors[$i] = $last_values[2]; - $flg_created[$i] = 1; - } - close(FILE); - } else { - $flg_created[$i] = 0; - } - - $update_time = time; - unless (open(FILE,">"."@CENTPLUGINS_TMP@/packet_errors_if".$i."_".$opt_H.".tmp")){ - print "Unknown - @CENTPLUGINS_TMP@/packet_errors_if".$i."_".$opt_H.".tmp!\n"; - exit $ERRORS{"UNKNOWN"}; -} - print FILE "$update_time:$nb_in_errors[$i]:$nb_out_errors[$i]"; - close(FILE); - if ($flg_created[$i] eq 0){ - print "First execution : Buffer in creation.... \n"; - } -} - -# ############################################# -# ##### return result -# ## -my $status = "OK"; -my @msg; -my $diff_test = 0; -for (my $i = 0; $i < scalar(@nb_in_errors); $i++) { - my $interface = $i+1; - if ($flg_created[$i]) { - if (($nb_in_errors[$i] - $last_in_errors[$i] >= $critical) or ($nb_out_errors[$i] - $last_out_errors[$i] >= $critical)){ - $msg[$i] = "$interface:critical "; - $status = "CRITICAL"; - } - if (($nb_in_errors[$i] - $last_in_errors[$i] >= $warning) or ($nb_out_errors[$i] - $last_out_errors[$i] >= $warning)){ - if (!defined($msg[$i])) { - $msg[$i] = "$interface:warning "; - } - if ($status ne "CRITICAL") { - $status = "WARNING"; - } - } - $diff_test = 1; - } -} - -if (!$diff_test) { - exit($ERRORS{'UNKNOWN'}); -} -my $output = ""; -for (my $i = 0; $i < scalar (@msg); $i++) { - if (defined($msg[$i])) { - $output .= $msg[$i]; - } -} -if ($output ne ""){ - print $output."\n"; -} else { - print "Status OK on all interfaces\n"; -} -exit($ERRORS{$status}); - sub print_usage () { - print "\nUsage:\n"; - print "$PROGNAME\n"; - print " -H (--hostname) Hostname to query - (required)\n"; - print " -C (--community) SNMP read community (default 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 " -w (--warn) Signal strength at which a warning message will be generated\n"; - print " (default 80)\n"; - print " -c (--crit) Signal strength at which a critical message will be generated\n"; - print " (default 100)\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"; +#! /usr/bin/perl -w +################################################################### +# Oreon is developped with GPL Licence 2.0 +# +# GPL License: http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt +# +# Developped by : Julien Mathis - Romain Le Merlus +# Mathavarajan Sugumaran +# +################################################################### +# 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 +#################################################################### +# +# Plugin init +# + +use strict; +use Net::SNMP qw(:snmp oid_lex_sort); +use FindBin; +use lib "$FindBin::Bin"; +use lib "@NAGIOS_PLUGINS@"; +use utils qw($TIMEOUT %ERRORS &print_revision &support); + +if (eval "require centreon" ) { + use centreon qw(get_parameters); + use vars qw($VERSION %centreon); + %centreon = get_parameters(); +} else { + print "Unable to load centreon perl module\n"; + exit $ERRORS{'UNKNOWN'}; +} + +use vars qw($VERSION %centreon); +use vars qw(%centreon); +$VERSION = '$Revision: 1.2 $'; +$VERSION =~ s/^\$.*:\W(.*)\W.+?$/$1/; + +use vars qw($PROGNAME); +use Getopt::Long; +use vars qw($opt_V $opt_h $opt_v $opt_C $opt_H $opt_w $opt_c); + +# +# Plugin var init +# +$PROGNAME = "$0"; + +my ($row, @flg_created, @last_check_time, @last_in_errors, @last_out_errors, $result_in, $result_out, @nb_out_errors, @nb_in_errors, $update_time, $db_file); +my $pathtolibexecnt = $centreon{NAGIOS_PLUGINS}; + +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, + "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.2 $'); + exit $ERRORS{'OK'}; +} + +if ($opt_h) { + print_help(); + exit $ERRORS{'OK'}; +} + +################################################## +##### Verify Options +## + +$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"); +($opt_c) || ($opt_c = shift) || ($opt_c = 100); +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'}; +} + +my $start=time; + + +################################################# +##### Plugin snmp requests +## + +my $OID_IN_ERRORS = ".1.3.6.1.2.1.2.2.1.14"; +my $OID_OUT_ERRORS = ".1.3.6.1.2.1.2.2.1.20"; + + +# create a SNMP session + +my ($session, $error) = Net::SNMP->session(-hostname => $opt_H, -community => $opt_C, -version => $snmp); +if (!defined($session)) { + print("UNKNOWN: SNMP Session : $error"); + exit $ERRORS{'UNKNOWN'}; +} + +####### Get IN ERRORS + +$result_in = $session->get_table(Baseoid => $OID_IN_ERRORS); +if (!defined($result_in)) { + printf("ERROR: IN_ERRORS : %s.\n", $session->error); + $session->close; + exit $ERRORS{'UNKNOWN'}; +} + +# loop for each interface +foreach my $err (oid_lex_sort(keys %$result_in)) { + $nb_in_errors[scalar(@nb_in_errors)] = $result_in->{$err}; +} +# ####### Get OUT ERRORS + +$result_out = $session->get_table(Baseoid => $OID_OUT_ERRORS); +if (!defined($result_out)) { + printf("ERROR: OUT_ERRORS : %s.\n", $session->error); + $session->close; + exit $ERRORS{'UNKNOWN'}; +} +foreach my $err (oid_lex_sort(keys %$result_out)) { + $nb_out_errors[scalar(@nb_out_errors)] = $result_out->{$err}; +} + +# ############################################# +# ##### read and write in buffer file +# ## + +for (my $i = 0; $i < scalar(@nb_in_errors); $i++) { + if (-e "@CENTPLUGINS_TMP@/packet_errors_if".$i."_".$opt_H.".tmp") { + open(FILE,"<"."@CENTPLUGINS_TMP@/packet_errors_if".$i."_".$opt_H.".tmp"); + while($row = ){ + my @last_values = split(":",$row); + $last_check_time[$i] = $last_values[0]; + $last_in_errors[$i] = $last_values[1]; + $last_out_errors[$i] = $last_values[2]; + $flg_created[$i] = 1; + } + close(FILE); + } else { + $flg_created[$i] = 0; + } + + $update_time = time; + unless (open(FILE,">"."@CENTPLUGINS_TMP@/packet_errors_if".$i."_".$opt_H.".tmp")){ + print "Unknown - @CENTPLUGINS_TMP@/packet_errors_if".$i."_".$opt_H.".tmp!\n"; + exit $ERRORS{"UNKNOWN"}; +} + print FILE "$update_time:$nb_in_errors[$i]:$nb_out_errors[$i]"; + close(FILE); + if ($flg_created[$i] eq 0){ + print "First execution : Buffer in creation.... \n"; + } +} + +# ############################################# +# ##### return result +# ## +my $status = "OK"; +my @msg; +my $diff_test = 0; +for (my $i = 0; $i < scalar(@nb_in_errors); $i++) { + my $interface = $i+1; + if ($flg_created[$i]) { + if (($nb_in_errors[$i] - $last_in_errors[$i] >= $critical) or ($nb_out_errors[$i] - $last_out_errors[$i] >= $critical)){ + $msg[$i] = "$interface:critical "; + $status = "CRITICAL"; + } + if (($nb_in_errors[$i] - $last_in_errors[$i] >= $warning) or ($nb_out_errors[$i] - $last_out_errors[$i] >= $warning)){ + if (!defined($msg[$i])) { + $msg[$i] = "$interface:warning "; + } + if ($status ne "CRITICAL") { + $status = "WARNING"; + } + } + $diff_test = 1; + } +} + +if (!$diff_test) { + exit($ERRORS{'UNKNOWN'}); +} +my $output = ""; +for (my $i = 0; $i < scalar (@msg); $i++) { + if (defined($msg[$i])) { + $output .= $msg[$i]; + } +} +if ($output ne ""){ + print $output."\n"; +} else { + print "Status OK on all interfaces\n"; +} +exit($ERRORS{$status}); + sub print_usage () { + print "\nUsage:\n"; + print "$PROGNAME\n"; + print " -H (--hostname) Hostname to query - (required)\n"; + print " -C (--community) SNMP read community (default 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 " -w (--warn) Signal strength at which a warning message will be generated\n"; + print " (default 80)\n"; + print " -c (--crit) Signal strength at which a critical message will be generated\n"; + print " (default 100)\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"; } \ No newline at end of file diff --git a/src/check_centreon_snmp_process b/src/check_centreon_snmp_process index bc130b21f..50fb02c14 100644 --- a/src/check_centreon_snmp_process +++ b/src/check_centreon_snmp_process @@ -1,216 +1,216 @@ -#! /usr/bin/perl -w -################################################################### -# Oreon is developped with GPL Licence 2.0 -# -# GPL License: http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt -# -# Developped by : Julien Mathis - Romain Le Merlus -# Christophe Coraboeuf - Sugumaran Mathavarajan -# -################################################################### -# 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 oid_lex_sort); -use FindBin; -use lib "$FindBin::Bin"; -use lib "@NAGIOS_PLUGINS@"; -use utils qw($TIMEOUT %ERRORS &print_revision &support); -if (eval "require centreon" ) { - use centreon qw(get_parameters); - use vars qw($VERSION %centreon); - %centreon = get_parameters(); -} else { - print "Unable to load centreon 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_p $opt_H $opt_n $opt_k $opt_u $opt_x $result @result %process_list %STATUS); - -# Plugin var init - -my($proc, $proc_run); - -$PROGNAME = $0; -sub print_help (); -sub print_usage (); - -%STATUS=(1=>'running',2=>'runnable',3=>'notRunnable',4=>'invalid'); - -Getopt::Long::Configure('bundling'); -GetOptions - ("h" => \$opt_h, "help" => \$opt_h, - "u=s" => \$opt_u, "username=s" => \$opt_u, - "x=s" => \$opt_x, "password=s" => \$opt_x, - "k=s" => \$opt_k, "key=s" => \$opt_k, - "V" => \$opt_V, "version" => \$opt_V, - "n" => \$opt_n, "number" => \$opt_n, - "v=s" => \$opt_v, "snmp=s" => \$opt_v, - "C=s" => \$opt_C, "community=s" => \$opt_C, - "p=s" => \$opt_p, "process=s" => \$opt_p, - "H=s" => \$opt_H, "hostname=s" => \$opt_H); - -if ($opt_V) { - print_revision($PROGNAME,'$Revision: 1.2 $'); - exit $ERRORS{'OK'}; -} - -if ($opt_h) { - print_help(); - exit $ERRORS{'OK'}; -} - -if (!$opt_H) { - print_usage(); - exit $ERRORS{'OK'}; -} -my $snmp = "1"; -$snmp = $opt_v if ($opt_v && $opt_v =~ /^[0-9]$/); - -if ($snmp eq "3") { - if (!$opt_u) { - print "Option -u (--username) is required for snmpV3\n"; - exit $ERRORS{'OK'}; - } - if (!$opt_x && !$opt_k) { - print "Option -k (--key) or -x (--password) is required for snmpV3\n"; - exit $ERRORS{'OK'}; - } elsif ($opt_x && $opt_k) { - print "Only option -k (--key) or -x (--password) is needed for snmpV3\n"; - exit $ERRORS{'OK'}; - } -} - -$opt_C = "public" if (!$opt_C); - -my $process; -if(!$opt_p) { - print_usage(); - exit $ERRORS{'OK'}; -} elsif ($opt_p !~ /([-.A-Za-z0-9]+)/){ - print_usage(); - exit $ERRORS{'OK'}; -} -$process = $opt_p; - -my $name = $0; -$name =~ s/\.pl.*//g; - -# Plugin snmp requests -my $OID_SW_RunName = $centreon{MIB2}{SW_RUNNAME}; -my $OID_SW_RunIndex =$centreon{MIB2}{SW_RUNINDEX}; -my $OID_SW_RunStatus =$centreon{MIB2}{SW_RUNSTATUS}; - -my ($session, $error); -if ($snmp eq "1" || $snmp eq "2") { - ($session, $error) = Net::SNMP->session(-hostname => $opt_H, -community => $opt_C, -version => $snmp); - if (!defined($session)) { - print("UNKNOWN: SNMP Session : $error\n"); - exit $ERRORS{'UNKNOWN'}; - } -} elsif ($opt_k) { - ($session, $error) = Net::SNMP->session(-hostname => $opt_H, -version => $snmp, -username => $opt_u, -authkey => $opt_k); - if (!defined($session)) { - print("UNKNOWN: SNMP Session : $error\n"); - exit $ERRORS{'UNKNOWN'}; - } -} elsif ($opt_x) { - ($session, $error) = Net::SNMP->session(-hostname => $opt_H, -version => $snmp, -username => $opt_u, -authpassword => $opt_x); - if (!defined($session)) { - print("UNKNOWN: SNMP Session : $error\n"); - exit $ERRORS{'UNKNOWN'}; - } -} - -$result = $session->get_table(Baseoid => $OID_SW_RunName); -if (!defined($result)) { - printf("UNKNOWN: %s.\n", $session->error); - $session->close; - exit $ERRORS{'UNKNOWN'}; -} - -$proc = 0; -foreach my $key (oid_lex_sort(keys %$result)) { - my @oid_list = split (/\./,$key); - $process_list{$$result{$key}} = pop (@oid_list) ; - if (defined($opt_p) && $opt_p ne ""){ - $proc++ if ($$result{$key} eq $opt_p); - } else { - $proc++; - } -} - -if (!($opt_n)) { - if ($process_list{$process}) { - $result = $session->get_request(-varbindlist => [$OID_SW_RunStatus . "." . $process_list{$process}]); - if (!defined($result)) { - printf("UNKNOWN: %s.\n", $session->error); - $session->close; - exit $ERRORS{'UNKNOWN'}; - } - $proc_run = $result->{$OID_SW_RunStatus . "." . $process_list{$process} }; - } -} - -# Plugin return code -my $status; -if ($opt_n){ - $status = 'OK'; - if ($proc >= $opt_w){ - $status = 'WARNING'; - } - if ($proc >= $opt_c){ - $status = 'CRITICAL'; - } - print "Number of current processes: $proc|nbproc=$proc\n"; - exit $ERRORS{$status}; -} else { - if ($proc_run){ - print "Process OK - $process: $STATUS{$proc_run}\n"; - exit $ERRORS{'OK'}; - } else { - print "Process CRITICAL - $process not in 'running' state\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 " -n (--number) Return the number of current running processes. \n"; - print " -p (--process) Set the process name ex: by default smbd\n"; - print " -k (--key) snmp V3 key\n"; - print " -x (--password) snmp V3 password\n"; - print " -u (--username) snmp v3 username \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"; +#! /usr/bin/perl -w +################################################################### +# Oreon is developped with GPL Licence 2.0 +# +# GPL License: http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt +# +# Developped by : Julien Mathis - Romain Le Merlus +# Christophe Coraboeuf - Sugumaran Mathavarajan +# +################################################################### +# 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 oid_lex_sort); +use FindBin; +use lib "$FindBin::Bin"; +use lib "@NAGIOS_PLUGINS@"; +use utils qw($TIMEOUT %ERRORS &print_revision &support); +if (eval "require centreon" ) { + use centreon qw(get_parameters); + use vars qw($VERSION %centreon); + %centreon = get_parameters(); +} else { + print "Unable to load centreon 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_p $opt_H $opt_n $opt_k $opt_u $opt_x $result @result %process_list %STATUS); + +# Plugin var init + +my($proc, $proc_run); + +$PROGNAME = $0; +sub print_help (); +sub print_usage (); + +%STATUS=(1=>'running',2=>'runnable',3=>'notRunnable',4=>'invalid'); + +Getopt::Long::Configure('bundling'); +GetOptions + ("h" => \$opt_h, "help" => \$opt_h, + "u=s" => \$opt_u, "username=s" => \$opt_u, + "x=s" => \$opt_x, "password=s" => \$opt_x, + "k=s" => \$opt_k, "key=s" => \$opt_k, + "V" => \$opt_V, "version" => \$opt_V, + "n" => \$opt_n, "number" => \$opt_n, + "v=s" => \$opt_v, "snmp=s" => \$opt_v, + "C=s" => \$opt_C, "community=s" => \$opt_C, + "p=s" => \$opt_p, "process=s" => \$opt_p, + "H=s" => \$opt_H, "hostname=s" => \$opt_H); + +if ($opt_V) { + print_revision($PROGNAME,'$Revision: 1.2 $'); + exit $ERRORS{'OK'}; +} + +if ($opt_h) { + print_help(); + exit $ERRORS{'OK'}; +} + +if (!$opt_H) { + print_usage(); + exit $ERRORS{'OK'}; +} +my $snmp = "1"; +$snmp = $opt_v if ($opt_v && $opt_v =~ /^[0-9]$/); + +if ($snmp eq "3") { + if (!$opt_u) { + print "Option -u (--username) is required for snmpV3\n"; + exit $ERRORS{'OK'}; + } + if (!$opt_x && !$opt_k) { + print "Option -k (--key) or -x (--password) is required for snmpV3\n"; + exit $ERRORS{'OK'}; + } elsif ($opt_x && $opt_k) { + print "Only option -k (--key) or -x (--password) is needed for snmpV3\n"; + exit $ERRORS{'OK'}; + } +} + +$opt_C = "public" if (!$opt_C); + +my $process; +if(!$opt_p) { + print_usage(); + exit $ERRORS{'OK'}; +} elsif ($opt_p !~ /([-.A-Za-z0-9]+)/){ + print_usage(); + exit $ERRORS{'OK'}; +} +$process = $opt_p; + +my $name = $0; +$name =~ s/\.pl.*//g; + +# Plugin snmp requests +my $OID_SW_RunName = $centreon{MIB2}{SW_RUNNAME}; +my $OID_SW_RunIndex =$centreon{MIB2}{SW_RUNINDEX}; +my $OID_SW_RunStatus =$centreon{MIB2}{SW_RUNSTATUS}; + +my ($session, $error); +if ($snmp eq "1" || $snmp eq "2") { + ($session, $error) = Net::SNMP->session(-hostname => $opt_H, -community => $opt_C, -version => $snmp); + if (!defined($session)) { + print("UNKNOWN: SNMP Session : $error\n"); + exit $ERRORS{'UNKNOWN'}; + } +} elsif ($opt_k) { + ($session, $error) = Net::SNMP->session(-hostname => $opt_H, -version => $snmp, -username => $opt_u, -authkey => $opt_k); + if (!defined($session)) { + print("UNKNOWN: SNMP Session : $error\n"); + exit $ERRORS{'UNKNOWN'}; + } +} elsif ($opt_x) { + ($session, $error) = Net::SNMP->session(-hostname => $opt_H, -version => $snmp, -username => $opt_u, -authpassword => $opt_x); + if (!defined($session)) { + print("UNKNOWN: SNMP Session : $error\n"); + exit $ERRORS{'UNKNOWN'}; + } +} + +$result = $session->get_table(Baseoid => $OID_SW_RunName); +if (!defined($result)) { + printf("UNKNOWN: %s.\n", $session->error); + $session->close; + exit $ERRORS{'UNKNOWN'}; +} + +$proc = 0; +foreach my $key (oid_lex_sort(keys %$result)) { + my @oid_list = split (/\./,$key); + $process_list{$$result{$key}} = pop (@oid_list) ; + if (defined($opt_p) && $opt_p ne ""){ + $proc++ if ($$result{$key} eq $opt_p); + } else { + $proc++; + } +} + +if (!($opt_n)) { + if ($process_list{$process}) { + $result = $session->get_request(-varbindlist => [$OID_SW_RunStatus . "." . $process_list{$process}]); + if (!defined($result)) { + printf("UNKNOWN: %s.\n", $session->error); + $session->close; + exit $ERRORS{'UNKNOWN'}; + } + $proc_run = $result->{$OID_SW_RunStatus . "." . $process_list{$process} }; + } +} + +# Plugin return code +my $status; +if ($opt_n){ + $status = 'OK'; + if ($proc >= $opt_w){ + $status = 'WARNING'; + } + if ($proc >= $opt_c){ + $status = 'CRITICAL'; + } + print "Number of current processes: $proc|nbproc=$proc\n"; + exit $ERRORS{$status}; +} else { + if ($proc_run){ + print "Process OK - $process: $STATUS{$proc_run}\n"; + exit $ERRORS{'OK'}; + } else { + print "Process CRITICAL - $process not in 'running' state\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 " -n (--number) Return the number of current running processes. \n"; + print " -p (--process) Set the process name ex: by default smbd\n"; + print " -k (--key) snmp V3 key\n"; + print " -x (--password) snmp V3 password\n"; + print " -u (--username) snmp v3 username \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"; } \ No newline at end of file diff --git a/src/check_centreon_snmp_value b/src/check_centreon_snmp_value index fe57ba70e..c1c13f262 100644 --- a/src/check_centreon_snmp_value +++ b/src/check_centreon_snmp_value @@ -1,204 +1,204 @@ -#! /usr/bin/perl -w -################################################################### -# Oreon is developped with GPL Licence 2.0 -# -# GPL License: http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt -# -# Developped by : Julien Mathis - Romain Le Merlus -# Christophe Coraboeuf - Sugumaran Mathavarajan -# -################################################################### -# 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_H $opt_C $opt_v $opt_o $opt_c $opt_w $opt_t $opt_p $opt_k $opt_u); - -$PROGNAME = $0; -sub print_help (); -sub print_usage (); - -Getopt::Long::Configure('bundling'); -GetOptions - ("h" => \$opt_h, "help" => \$opt_h, - "u=s" => \$opt_u, "username=s" => \$opt_u, - "p=s" => \$opt_p, "password=s" => \$opt_p, - "k=s" => \$opt_k, "key=s" => \$opt_k, - "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; -} - -if ($snmp eq "3") { -if (!$opt_u) { -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"; -exit $ERRORS{'OK'}; -}elsif ($opt_p && $opt_k) { -print "Only option -k (--key) or -p (--password) is needed for snmpV3\n"; -exit $ERRORS{'OK'}; -} -} - -($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); -if ($snmp eq "1" || $snmp eq "2") { -($session, $error) = Net::SNMP->session(-hostname => $opt_H, -community => $opt_C, -version => $snmp); -if (!defined($session)) { - print("UNKNOWN: SNMP Session : $error\n"); - exit $ERRORS{'UNKNOWN'}; -} -}elsif ($opt_k) { - ($session, $error) = Net::SNMP->session(-hostname => $opt_H, -version => $snmp, -username => $opt_u, -authkey => $opt_k); -if (!defined($session)) { - print("UNKNOWN: SNMP Session : $error\n"); - 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)) { - print("UNKNOWN: SNMP Session : $error\n"); - exit $ERRORS{'UNKNOWN'}; -} -} - -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 ($return_result !~ /^[0-9]+$/) { - print "Snmp return value isn't numeric.\n"; - exit $ERRORS{'OK'}; - } - 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 "Usage:"; - 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 " -k (--key) snmp V3 key\n"; - print " -p (--password) snmp V3 password\n"; - print " -u (--username) snmp v3 username \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 Centreon #\n"; - print "# Bugs to http://bugs.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/old-licenses/gpl-2.0.txt +# +# Developped by : Julien Mathis - Romain Le Merlus +# Christophe Coraboeuf - Sugumaran Mathavarajan +# +################################################################### +# 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_H $opt_C $opt_v $opt_o $opt_c $opt_w $opt_t $opt_p $opt_k $opt_u); + +$PROGNAME = $0; +sub print_help (); +sub print_usage (); + +Getopt::Long::Configure('bundling'); +GetOptions + ("h" => \$opt_h, "help" => \$opt_h, + "u=s" => \$opt_u, "username=s" => \$opt_u, + "p=s" => \$opt_p, "password=s" => \$opt_p, + "k=s" => \$opt_k, "key=s" => \$opt_k, + "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; +} + +if ($snmp eq "3") { +if (!$opt_u) { +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"; +exit $ERRORS{'OK'}; +}elsif ($opt_p && $opt_k) { +print "Only option -k (--key) or -p (--password) is needed for snmpV3\n"; +exit $ERRORS{'OK'}; +} +} + +($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); +if ($snmp eq "1" || $snmp eq "2") { +($session, $error) = Net::SNMP->session(-hostname => $opt_H, -community => $opt_C, -version => $snmp); +if (!defined($session)) { + print("UNKNOWN: SNMP Session : $error\n"); + exit $ERRORS{'UNKNOWN'}; +} +}elsif ($opt_k) { + ($session, $error) = Net::SNMP->session(-hostname => $opt_H, -version => $snmp, -username => $opt_u, -authkey => $opt_k); +if (!defined($session)) { + print("UNKNOWN: SNMP Session : $error\n"); + 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)) { + print("UNKNOWN: SNMP Session : $error\n"); + exit $ERRORS{'UNKNOWN'}; +} +} + +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 ($return_result !~ /^[0-9]+$/) { + print "Snmp return value isn't numeric.\n"; + exit $ERRORS{'OK'}; + } + 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 "Usage:"; + 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 " -k (--key) snmp V3 key\n"; + print " -p (--password) snmp V3 password\n"; + print " -u (--username) snmp v3 username \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 Centreon #\n"; + print "# Bugs to http://bugs.oreon-project.org/ #\n"; + print "##############################################\n"; + print_usage(); + print "\n"; +} diff --git a/src/check_meta_service b/src/check_meta_service index 3c2812e4b..8120bd07e 100644 --- a/src/check_meta_service +++ b/src/check_meta_service @@ -1,398 +1,398 @@ -#! /usr/bin/perl -w -################################################################### -# Oreon is developped with GPL Licence 2.0 -# -# GPL License: http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt -# -# Developped by : Julien Mathis - Romain Le Merlus -# Mathavarajan Sugumaran -# -################################################################### -# 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 -#################################################################### -# -# Plugin init -# - -use strict; -use DBI; -use vars qw($PROGNAME); -use Getopt::Long; -use vars qw($opt_V $opt_H $opt_h $opt_i); -use lib "@NAGIOS_PLUGINS@"; -use utils qw($TIMEOUT %ERRORS &print_revision &support); - -## For Debug mode = 1 -my $debug = 0; - -sub print_help (); -sub print_usage (); - -Getopt::Long::Configure('bundling'); -GetOptions - ("h" => \$opt_h, - "help" => \$opt_h, - "V" => \$opt_V, - "i=s" => \$opt_i); - -########################### -## Set Database information -########################### -use vars qw($mysql_database_oreon $mysql_database_ods $mysql_host $mysql_user $mysql_passwd); -require "/usr/local/centreon/etc/conf.pm"; - -my $dbh = DBI->connect("DBI:mysql:database=$mysql_database_oreon;host=$mysql_host","$mysql_user", "$mysql_passwd",{'RaiseError' => 1}); -my $dbh2 = DBI->connect("DBI:mysql:database=$mysql_database_ods;host=$mysql_host","$mysql_user", "$mysql_passwd",{'RaiseError' => 1}); - -if ($opt_V) { - print_revision($PROGNAME,'$Revision: 0.1 $'); - exit $ERRORS{'OK'}; -} - -if ($opt_h) { - print_help(); - exit $ERRORS{'OK'}; -} - -my $result; -my $warning; -my $critical; -my $metric_id; - -sub return_value($$$$){ - - my $sth_output = $dbh->prepare("SELECT meta_display FROM `meta_service` WHERE `meta_id` = '".$_[3]."'"); - if (!$sth_output->execute) {die "Error:" . $sth_output->errstr . "\n";} - my $sth_output_data = $sth_output->fetchrow_hashref(); - my $output = $sth_output_data->{'meta_display'}; - if ($output) { - $output =~ s/\%d/$result/g; - } - if ($warning ne $critical){ - if ($warning < $critical){ # Bon sens - if ($result < $warning){ - if ($output) { - print $output. "|OMS=" . $result . ";".$warning.";".$critical."\n"; - }else { - print "OK result : " . $result . "|OMS=" . $result . ";".$warning.";".$critical."\n"; - } - exit $ERRORS{'OK'}; - } elsif (($result >= $warning) && ($result < $critical)){ - if ($output) { - print $output. "|OMS=" . $result . ";".$warning.";".$critical."\n"; - }else { - print "WARNING result : " . $result . "|OMS=" . $result . ";".$warning.";".$critical."\n"; - } - exit $ERRORS{'WARNING'}; - } elsif ($result >= $critical){ - if ($output) { - print $output. "|OMS=" . $result . ";".$warning.";".$critical."\n"; - }else { - print "CRITICAL result : " . $result . "|OMS=" . $result . ";".$warning.";".$critical."\n"; - } - exit $ERRORS{'CRITICAL'}; - } - } else { # sens inverse - if ($result < $critical){ - if ($output) { - print $output. "|OMS=" . $result . ";".$warning.";".$critical."\n"; - }else { - print "CRITICAL result : " . $result . "|OMS=" . $result . ";".$warning.";".$critical."\n"; - } - exit $ERRORS{'CRITICAL'}; - } elsif ($result >= $critical && $result < $warning){ - if ($output) { - print $output. "|OMS=" . $result . ";".$warning.";".$critical."\n"; - }else { - print "WARNING result : " . $result . "|OMS=" . $result . ";".$warning.";".$critical."\n"; - } - exit $ERRORS{'WARNING'}; - } elsif ($result >= $warning){ - if ($output) { - print $output. "|OMS=" . $result . ";".$warning.";".$critical."\n"; - }else { - print "OK result : " . $result . "|OMS=" . $result . ";".$warning.";".$critical."\n"; - } - exit $ERRORS{'OK'}; - } else{ - if ($output) { - print $output. "|OMS=" . $result . ";".$warning.";".$critical."\n"; - }else { - print "OK result : " . $result . "|OMS=" . $result . ";".$warning.";".$critical."\n"; - } - exit $ERRORS{'OK'}; - } - } - } else { - print "ERROR : warnig level = critical level"; - exit $ERRORS{'CRITICAL'}; - } -} - -my $ref; -my $svc_id; -my $metric; -my $host_id; - -## Get Value by metric Option - -sub get_value_in_database_metric_id($$$$){ - ## Get last entry in perfparse database for this service - my $str = "SELECT value FROM data_bin WHERE id_metric = '".$metric_id."'"; - if ($debug) {print $str . "\n";} - my $sth_deb2 = $dbh2->prepare($str); - if (!$sth_deb2->execute) {die "Error:" . $sth_deb2->errstr . "\n";} - my $sth_deb2_data = $sth_deb2->fetchrow_hashref(); - return $sth_deb2_data->{'value'}; -} - -## Get value For Regexp Options - -sub get_value_in_database($$$$$){ - - my $str; - ## Get hostname and service description for perfparse request - - $str = "SELECT host_name,service_description FROM host,host_service_relation,service WHERE host.host_id = host_service_relation.host_host_id AND -service.service_id = host_service_relation.service_service_id AND service.service_id = '".$svc_id."'"; - - if ($debug) {print $str . "\n";} - my $host_data = $dbh->prepare($str); - if (!$host_data->execute) {die "Error:" . $host_data->errstr . "\n";} - my $data = $host_data->fetchrow_hashref(); - - ## Get last entry in perfparse database for this service - my $sth_deb2 = $dbh2->prepare("SELECT value FROM metrics m, data_bin d, index_data i WHERE i.host_name = '".$data->{'host_name'}."' AND i.service_description = '".$data->{'service_description'}."' AND and m.index_id=i.id AND m.metric_id = d.id_metric AND m.metric_name = '".$metric."'"); - if (!$sth_deb2->execute) {die "Error:" . $sth_deb2->errstr . "\n";} - my $sth_deb2_data = $sth_deb2->fetchrow_hashref(); - return $sth_deb2_data->{'value'}; -} - -sub get_value_in_database_by_host($$$$$){ - - my $str; - - ## Get hostname and service description for perfparse request - - $str = "SELECT host_name,service_description FROM host,host_service_relation,service WHERE host.host_id = host_service_relation.host_host_id AND service.service_id = host_service_relation.service_service_id AND service.service_id = '".$svc_id."'"; - if ($debug) {print $str . "\n";} - my $host_data = $dbh->prepare($str); - if (!$host_data->execute) {die "Error:" . $host_data->errstr . "\n";} - my $data = $host_data->fetchrow_hashref(); - - ## Get last entry in perfparse database for this service - - my $sth_deb2 = $dbh2->prepare("SELECT value FROM metrics m, data_bin d, index_data i WHERE i.host_name = '".$data->{'host_name'}."' AND i.service_description = '".$data->{'service_description'}."' AND m.index_id=i.id AND m.metric_id = d.id_metric AND m.metric_name = '".$metric."'"); - if (!$sth_deb2->execute) {die "Error:" . $sth_deb2->errstr . "\n";} - my $sth_deb2_data = $sth_deb2->fetchrow_hashref(); - return $sth_deb2_data->{'value'}; -} - -sub get_value_in_database_by_hg($$$$$$){ - my $str; - ## Get hostname - $str = "SELECT host_name FROM host WHERE host.host_id = '".$host_id."'"; - if ($debug) {print $str . "\n";} - my $hd = $dbh->prepare($str); - if (!$hd->execute) {die "Error:" . $hd->errstr . "\n";} - my $host_data = $hd->fetchrow_hashref(); - - ## Get service description - - $str = "SELECT service_description FROM service WHERE service.service_id = '".$svc_id."'"; - if ($debug) {print $str . "\n";} - my $sd = $dbh->prepare($str); - if (!$sd->execute) {die "Error:" . $sd->errstr . "\n";} - my $service_data = $sd->fetchrow_hashref(); - - ## Get last entry in perfparse database for this service - - my $sth_deb2 = $dbh2->prepare("SELECT value FROM metrics m, data_bin d, index_data i WHERE i.host_name = '".$host_data->{'host_name'}."' AND i.service_description = '".$service_data->{'service_description'}."' AND m.index_id=i.id AND m.metric_id = d.id_metric AND m.metric_name = '".$metric."'"); - if (!$sth_deb2->execute) {die "Error:" . $sth_deb2->errstr . "\n";} - my $sth_deb2_data = $sth_deb2->fetchrow_hashref(); - return $sth_deb2_data->{'value'}; -} - -my $cpt = 0; -my $total = 0; -my $max = 0; -my $min = 999999999; -my $svc; -my $value = 0; -my $svc_relation2; - -if ($opt_i){ - my $str; - - # get osl info - my $sth = $dbh->prepare("SELECT calcul_type,regexp_str,warning,critical,metric, meta_select_mode FROM meta_service WHERE meta_id = '".$opt_i."'"); - if (!$sth->execute) {die "Error:" . $sth->errstr . "\n";} - $ref = $sth->fetchrow_hashref(); - if (!defined($ref->{'calcul_type'})){ - print "Unvalidate Meta Service\n"; - exit $ERRORS{'CRITICAL'}; - } - - $warning = $ref->{'warning'}; - $critical = $ref->{'critical'}; - - # Get Service List by regexp - if ($ref->{'meta_select_mode'} eq '2'){ - - ############################################### - - $str = "SELECT service_id FROM service WHERE `service_description` LIKE '".$ref->{'regexp_str'}."' AND service_activate = '1' AND service_register = '1'"; - if ($debug) {print $str . "\n";} - $sth = $dbh->prepare($str); - if (!$sth->execute) {die "Error:" . $sth->errstr . "\n";} - while ($svc = $sth->fetchrow_hashref()){ - my $sth2 = $dbh->prepare("SELECT * FROM host_service_relation WHERE service_service_id = '".$svc->{'service_id'}."'"); - if (!$sth2->execute) {die "Error:" . $sth2->errstr . "\n";} - my $svc_relation = $sth2->fetchrow_hashref(); - if (defined($svc_relation->{'host_host_id'}) && $svc_relation->{'host_host_id'}){ - #### Par Host - if (defined($svc->{'service_id'})){$svc_id = $svc->{'service_id'};} else {$svc_id = $svc->{'svc_id'};} - if (defined($ref->{'regexp_str'})){$metric = $ref->{'metric'};} else {$metric = $svc->{'metric'};} - $value = get_value_in_database_by_host($dbh,$dbh2,$svc_id,$metric,$debug); - if ($ref->{'calcul_type'} =~ "AVE"){ - if (defined($value) && $value){$total += $value;} - if ($debug) {print "total = " . $total . " value = ".$value."\n";} - $cpt++; - $result = $total / $cpt; - } elsif ($ref->{'calcul_type'} =~ "SOM"){ - if ($value){$total += $value;} - if ($debug){print "total = " . $total . " value = ".$value."\n";} - $result = $total; - } elsif ($ref->{'calcul_type'} =~ "MIN"){ - if ($debug){print " min : " . $min . " value = ".$value."\n";} - if ($value && $value <= $min){$min = $value;} - $result = $min; - } elsif ($ref->{'calcul_type'} =~ "MAX"){ - if ($debug){print "max = " . $max . " value = ".$value."\n";} - if ($value && $value >= $max){$max = $value;} - $result = $max; - } - } elsif (defined($svc_relation->{'hostgroup_hg_id'}) && $svc_relation->{'hostgroup_hg_id'}) { - ### Par Hostgroup - my $sth3 = $dbh->prepare("SELECT host_host_id FROM hostgroup_relation WHERE hostgroup_hg_id = '".$svc_relation->{'hostgroup_hg_id'}."'"); - if (!$sth3->execute) {die "Error:" . $sth3->errstr . "\n";} - while ($svc_relation2 = $sth3->fetchrow_hashref()){ - if (defined($svc->{'service_id'})){ - $svc_id = $svc->{'service_id'}; - } else { - $svc_id = $svc->{'svc_id'}; - } - if (defined($ref->{'regexp_str'})){ - $metric = $ref->{'metric'}; - } else { - $metric = $svc->{'metric'}; - } - $host_id = $svc_relation2->{'host_host_id'}; - $value = get_value_in_database_by_hg($dbh,$dbh2,$svc_id, $host_id, $metric, $debug); - if ($ref->{'calcul_type'} =~ "AVE"){ - if (defined($value) && $value){ - $total += $value; - } - if ($debug) {print "total = " . $total . " value = ".$value."\n";} - $cpt++; - } elsif ($ref->{'calcul_type'} =~ "SOM"){ - if ($value){ - $total += $value; - } - if ($debug){print "total = " . $total . " value = ".$value."\n";} - } elsif ($ref->{'calcul_type'} =~ "MIN"){ - if ($debug){print " min : " . $min . " value = ".$value."\n";} - if ($value && $value <= $min){ - $min = $value; - } - } elsif ($ref->{'calcul_type'} =~ "MAX"){ - if ($debug){print "max = " . $max . " value = ".$value."\n";} - if ($value && $value >= $max){ - $max = $value; - } - } - } - if ($ref->{'calcul_type'} =~ "AVE"){ - $result = $total / $cpt; - } elsif ($ref->{'calcul_type'} =~ "SOM"){ - $result = $total; - } elsif ($ref->{'calcul_type'} =~ "MIN"){ - $result = $min; - } elsif ($ref->{'calcul_type'} =~ "MAX"){ - $result = $max; - } - } - } - return_value($result, $warning, $critical, $opt_i); - ############################################### - } else { - $sth = $dbh->prepare("SELECT metric_id FROM `meta_service_relation` WHERE meta_id = '".$opt_i."'"); - if (!$sth->execute) {die "Error:" . $sth->errstr . "\n";} - if ($ref->{'calcul_type'} =~ "AVE"){ - if (!$sth->rows) { - print "no result in table meta_service_relation for id $opt_i\n"; - exit $ERRORS{'UNKNOWN'}; - } - while ($svc = $sth->fetchrow_hashref()){ - if (defined($svc->{'metric_id'})){$metric_id = $svc->{'metric_id'};} - $value = get_value_in_database_metric_id($dbh,$dbh2,$metric_id,$debug); - if (defined($value) && $value){$total += $value;} - $cpt++; - } - $result = $total / $cpt; - } elsif ($ref->{'calcul_type'} =~ "SOM"){ - while ($svc = $sth->fetchrow_hashref()){ - if (defined($svc->{'metric_id'})){$metric_id = $svc->{'metric_id'};} - $value = get_value_in_database_metric_id($dbh,$dbh2,$metric_id,$debug); - if ($value){$total += $value;} - if ($debug){print "total = " . $total . " value = ".$value."\n";} - } - $result = $total; - } elsif ($ref->{'calcul_type'} =~ "MIN"){ - while ($svc = $sth->fetchrow_hashref()){ - if (defined($svc->{'metric_id'})){$metric_id = $svc->{'metric_id'};} - $value = get_value_in_database_metric_id($dbh,$dbh2,$metric_id,$debug); - if ($debug){print " min : " . $min . " value = ".$value."\n";} - if ($value && $value <= $min){$min = $value;} - } - $result = $min; - } elsif ($ref->{'calcul_type'} =~ "MAX"){ - while ($svc = $sth->fetchrow_hashref()){ - if (defined($svc->{'metric_id'})){$metric_id = $svc->{'metric_id'};} - $value = get_value_in_database_metric_id($dbh,$dbh2,$metric_id,$debug); - if ($debug){print "max = " . $max . " value = ".$value."\n";} - if ($value && $value >= $max){$max = $value;} - } - $result = $max; - } - return_value($result, $warning, $critical, $opt_i); - } -} - - -sub print_usage () { - print "Usage:\n"; - print " check_meta_service\n"; - print " -i Meta Service id\n"; - print " -V (--version) Plugin version\n"; - print " -h (--help) usage help\n"; -} - -sub print_help () { - print "##############################################\n"; - print "# Copyright (c) 2004-2008 Centreon #\n"; - print "# Bugs to http://bugs.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/old-licenses/gpl-2.0.txt +# +# Developped by : Julien Mathis - Romain Le Merlus +# Mathavarajan Sugumaran +# +################################################################### +# 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 +#################################################################### +# +# Plugin init +# + +use strict; +use DBI; +use vars qw($PROGNAME); +use Getopt::Long; +use vars qw($opt_V $opt_H $opt_h $opt_i); +use lib "@NAGIOS_PLUGINS@"; +use utils qw($TIMEOUT %ERRORS &print_revision &support); + +## For Debug mode = 1 +my $debug = 0; + +sub print_help (); +sub print_usage (); + +Getopt::Long::Configure('bundling'); +GetOptions + ("h" => \$opt_h, + "help" => \$opt_h, + "V" => \$opt_V, + "i=s" => \$opt_i); + +########################### +## Set Database information +########################### +use vars qw($mysql_database_oreon $mysql_database_ods $mysql_host $mysql_user $mysql_passwd); +require "/usr/local/centreon/etc/conf.pm"; + +my $dbh = DBI->connect("DBI:mysql:database=$mysql_database_oreon;host=$mysql_host","$mysql_user", "$mysql_passwd",{'RaiseError' => 1}); +my $dbh2 = DBI->connect("DBI:mysql:database=$mysql_database_ods;host=$mysql_host","$mysql_user", "$mysql_passwd",{'RaiseError' => 1}); + +if ($opt_V) { + print_revision($PROGNAME,'$Revision: 0.1 $'); + exit $ERRORS{'OK'}; +} + +if ($opt_h) { + print_help(); + exit $ERRORS{'OK'}; +} + +my $result; +my $warning; +my $critical; +my $metric_id; + +sub return_value($$$$){ + + my $sth_output = $dbh->prepare("SELECT meta_display FROM `meta_service` WHERE `meta_id` = '".$_[3]."'"); + if (!$sth_output->execute) {die "Error:" . $sth_output->errstr . "\n";} + my $sth_output_data = $sth_output->fetchrow_hashref(); + my $output = $sth_output_data->{'meta_display'}; + if ($output) { + $output =~ s/\%d/$result/g; + } + if ($warning ne $critical){ + if ($warning < $critical){ # Bon sens + if ($result < $warning){ + if ($output) { + print $output. "|OMS=" . $result . ";".$warning.";".$critical."\n"; + }else { + print "OK result : " . $result . "|OMS=" . $result . ";".$warning.";".$critical."\n"; + } + exit $ERRORS{'OK'}; + } elsif (($result >= $warning) && ($result < $critical)){ + if ($output) { + print $output. "|OMS=" . $result . ";".$warning.";".$critical."\n"; + }else { + print "WARNING result : " . $result . "|OMS=" . $result . ";".$warning.";".$critical."\n"; + } + exit $ERRORS{'WARNING'}; + } elsif ($result >= $critical){ + if ($output) { + print $output. "|OMS=" . $result . ";".$warning.";".$critical."\n"; + }else { + print "CRITICAL result : " . $result . "|OMS=" . $result . ";".$warning.";".$critical."\n"; + } + exit $ERRORS{'CRITICAL'}; + } + } else { # sens inverse + if ($result < $critical){ + if ($output) { + print $output. "|OMS=" . $result . ";".$warning.";".$critical."\n"; + }else { + print "CRITICAL result : " . $result . "|OMS=" . $result . ";".$warning.";".$critical."\n"; + } + exit $ERRORS{'CRITICAL'}; + } elsif ($result >= $critical && $result < $warning){ + if ($output) { + print $output. "|OMS=" . $result . ";".$warning.";".$critical."\n"; + }else { + print "WARNING result : " . $result . "|OMS=" . $result . ";".$warning.";".$critical."\n"; + } + exit $ERRORS{'WARNING'}; + } elsif ($result >= $warning){ + if ($output) { + print $output. "|OMS=" . $result . ";".$warning.";".$critical."\n"; + }else { + print "OK result : " . $result . "|OMS=" . $result . ";".$warning.";".$critical."\n"; + } + exit $ERRORS{'OK'}; + } else{ + if ($output) { + print $output. "|OMS=" . $result . ";".$warning.";".$critical."\n"; + }else { + print "OK result : " . $result . "|OMS=" . $result . ";".$warning.";".$critical."\n"; + } + exit $ERRORS{'OK'}; + } + } + } else { + print "ERROR : warnig level = critical level"; + exit $ERRORS{'CRITICAL'}; + } +} + +my $ref; +my $svc_id; +my $metric; +my $host_id; + +## Get Value by metric Option + +sub get_value_in_database_metric_id($$$$){ + ## Get last entry in perfparse database for this service + my $str = "SELECT value FROM data_bin WHERE id_metric = '".$metric_id."'"; + if ($debug) {print $str . "\n";} + my $sth_deb2 = $dbh2->prepare($str); + if (!$sth_deb2->execute) {die "Error:" . $sth_deb2->errstr . "\n";} + my $sth_deb2_data = $sth_deb2->fetchrow_hashref(); + return $sth_deb2_data->{'value'}; +} + +## Get value For Regexp Options + +sub get_value_in_database($$$$$){ + + my $str; + ## Get hostname and service description for perfparse request + + $str = "SELECT host_name,service_description FROM host,host_service_relation,service WHERE host.host_id = host_service_relation.host_host_id AND +service.service_id = host_service_relation.service_service_id AND service.service_id = '".$svc_id."'"; + + if ($debug) {print $str . "\n";} + my $host_data = $dbh->prepare($str); + if (!$host_data->execute) {die "Error:" . $host_data->errstr . "\n";} + my $data = $host_data->fetchrow_hashref(); + + ## Get last entry in perfparse database for this service + my $sth_deb2 = $dbh2->prepare("SELECT value FROM metrics m, data_bin d, index_data i WHERE i.host_name = '".$data->{'host_name'}."' AND i.service_description = '".$data->{'service_description'}."' AND and m.index_id=i.id AND m.metric_id = d.id_metric AND m.metric_name = '".$metric."'"); + if (!$sth_deb2->execute) {die "Error:" . $sth_deb2->errstr . "\n";} + my $sth_deb2_data = $sth_deb2->fetchrow_hashref(); + return $sth_deb2_data->{'value'}; +} + +sub get_value_in_database_by_host($$$$$){ + + my $str; + + ## Get hostname and service description for perfparse request + + $str = "SELECT host_name,service_description FROM host,host_service_relation,service WHERE host.host_id = host_service_relation.host_host_id AND service.service_id = host_service_relation.service_service_id AND service.service_id = '".$svc_id."'"; + if ($debug) {print $str . "\n";} + my $host_data = $dbh->prepare($str); + if (!$host_data->execute) {die "Error:" . $host_data->errstr . "\n";} + my $data = $host_data->fetchrow_hashref(); + + ## Get last entry in perfparse database for this service + + my $sth_deb2 = $dbh2->prepare("SELECT value FROM metrics m, data_bin d, index_data i WHERE i.host_name = '".$data->{'host_name'}."' AND i.service_description = '".$data->{'service_description'}."' AND m.index_id=i.id AND m.metric_id = d.id_metric AND m.metric_name = '".$metric."'"); + if (!$sth_deb2->execute) {die "Error:" . $sth_deb2->errstr . "\n";} + my $sth_deb2_data = $sth_deb2->fetchrow_hashref(); + return $sth_deb2_data->{'value'}; +} + +sub get_value_in_database_by_hg($$$$$$){ + my $str; + ## Get hostname + $str = "SELECT host_name FROM host WHERE host.host_id = '".$host_id."'"; + if ($debug) {print $str . "\n";} + my $hd = $dbh->prepare($str); + if (!$hd->execute) {die "Error:" . $hd->errstr . "\n";} + my $host_data = $hd->fetchrow_hashref(); + + ## Get service description + + $str = "SELECT service_description FROM service WHERE service.service_id = '".$svc_id."'"; + if ($debug) {print $str . "\n";} + my $sd = $dbh->prepare($str); + if (!$sd->execute) {die "Error:" . $sd->errstr . "\n";} + my $service_data = $sd->fetchrow_hashref(); + + ## Get last entry in perfparse database for this service + + my $sth_deb2 = $dbh2->prepare("SELECT value FROM metrics m, data_bin d, index_data i WHERE i.host_name = '".$host_data->{'host_name'}."' AND i.service_description = '".$service_data->{'service_description'}."' AND m.index_id=i.id AND m.metric_id = d.id_metric AND m.metric_name = '".$metric."'"); + if (!$sth_deb2->execute) {die "Error:" . $sth_deb2->errstr . "\n";} + my $sth_deb2_data = $sth_deb2->fetchrow_hashref(); + return $sth_deb2_data->{'value'}; +} + +my $cpt = 0; +my $total = 0; +my $max = 0; +my $min = 999999999; +my $svc; +my $value = 0; +my $svc_relation2; + +if ($opt_i){ + my $str; + + # get osl info + my $sth = $dbh->prepare("SELECT calcul_type,regexp_str,warning,critical,metric, meta_select_mode FROM meta_service WHERE meta_id = '".$opt_i."'"); + if (!$sth->execute) {die "Error:" . $sth->errstr . "\n";} + $ref = $sth->fetchrow_hashref(); + if (!defined($ref->{'calcul_type'})){ + print "Unvalidate Meta Service\n"; + exit $ERRORS{'CRITICAL'}; + } + + $warning = $ref->{'warning'}; + $critical = $ref->{'critical'}; + + # Get Service List by regexp + if ($ref->{'meta_select_mode'} eq '2'){ + + ############################################### + + $str = "SELECT service_id FROM service WHERE `service_description` LIKE '".$ref->{'regexp_str'}."' AND service_activate = '1' AND service_register = '1'"; + if ($debug) {print $str . "\n";} + $sth = $dbh->prepare($str); + if (!$sth->execute) {die "Error:" . $sth->errstr . "\n";} + while ($svc = $sth->fetchrow_hashref()){ + my $sth2 = $dbh->prepare("SELECT * FROM host_service_relation WHERE service_service_id = '".$svc->{'service_id'}."'"); + if (!$sth2->execute) {die "Error:" . $sth2->errstr . "\n";} + my $svc_relation = $sth2->fetchrow_hashref(); + if (defined($svc_relation->{'host_host_id'}) && $svc_relation->{'host_host_id'}){ + #### Par Host + if (defined($svc->{'service_id'})){$svc_id = $svc->{'service_id'};} else {$svc_id = $svc->{'svc_id'};} + if (defined($ref->{'regexp_str'})){$metric = $ref->{'metric'};} else {$metric = $svc->{'metric'};} + $value = get_value_in_database_by_host($dbh,$dbh2,$svc_id,$metric,$debug); + if ($ref->{'calcul_type'} =~ "AVE"){ + if (defined($value) && $value){$total += $value;} + if ($debug) {print "total = " . $total . " value = ".$value."\n";} + $cpt++; + $result = $total / $cpt; + } elsif ($ref->{'calcul_type'} =~ "SOM"){ + if ($value){$total += $value;} + if ($debug){print "total = " . $total . " value = ".$value."\n";} + $result = $total; + } elsif ($ref->{'calcul_type'} =~ "MIN"){ + if ($debug){print " min : " . $min . " value = ".$value."\n";} + if ($value && $value <= $min){$min = $value;} + $result = $min; + } elsif ($ref->{'calcul_type'} =~ "MAX"){ + if ($debug){print "max = " . $max . " value = ".$value."\n";} + if ($value && $value >= $max){$max = $value;} + $result = $max; + } + } elsif (defined($svc_relation->{'hostgroup_hg_id'}) && $svc_relation->{'hostgroup_hg_id'}) { + ### Par Hostgroup + my $sth3 = $dbh->prepare("SELECT host_host_id FROM hostgroup_relation WHERE hostgroup_hg_id = '".$svc_relation->{'hostgroup_hg_id'}."'"); + if (!$sth3->execute) {die "Error:" . $sth3->errstr . "\n";} + while ($svc_relation2 = $sth3->fetchrow_hashref()){ + if (defined($svc->{'service_id'})){ + $svc_id = $svc->{'service_id'}; + } else { + $svc_id = $svc->{'svc_id'}; + } + if (defined($ref->{'regexp_str'})){ + $metric = $ref->{'metric'}; + } else { + $metric = $svc->{'metric'}; + } + $host_id = $svc_relation2->{'host_host_id'}; + $value = get_value_in_database_by_hg($dbh,$dbh2,$svc_id, $host_id, $metric, $debug); + if ($ref->{'calcul_type'} =~ "AVE"){ + if (defined($value) && $value){ + $total += $value; + } + if ($debug) {print "total = " . $total . " value = ".$value."\n";} + $cpt++; + } elsif ($ref->{'calcul_type'} =~ "SOM"){ + if ($value){ + $total += $value; + } + if ($debug){print "total = " . $total . " value = ".$value."\n";} + } elsif ($ref->{'calcul_type'} =~ "MIN"){ + if ($debug){print " min : " . $min . " value = ".$value."\n";} + if ($value && $value <= $min){ + $min = $value; + } + } elsif ($ref->{'calcul_type'} =~ "MAX"){ + if ($debug){print "max = " . $max . " value = ".$value."\n";} + if ($value && $value >= $max){ + $max = $value; + } + } + } + if ($ref->{'calcul_type'} =~ "AVE"){ + $result = $total / $cpt; + } elsif ($ref->{'calcul_type'} =~ "SOM"){ + $result = $total; + } elsif ($ref->{'calcul_type'} =~ "MIN"){ + $result = $min; + } elsif ($ref->{'calcul_type'} =~ "MAX"){ + $result = $max; + } + } + } + return_value($result, $warning, $critical, $opt_i); + ############################################### + } else { + $sth = $dbh->prepare("SELECT metric_id FROM `meta_service_relation` WHERE meta_id = '".$opt_i."'"); + if (!$sth->execute) {die "Error:" . $sth->errstr . "\n";} + if ($ref->{'calcul_type'} =~ "AVE"){ + if (!$sth->rows) { + print "no result in table meta_service_relation for id $opt_i\n"; + exit $ERRORS{'UNKNOWN'}; + } + while ($svc = $sth->fetchrow_hashref()){ + if (defined($svc->{'metric_id'})){$metric_id = $svc->{'metric_id'};} + $value = get_value_in_database_metric_id($dbh,$dbh2,$metric_id,$debug); + if (defined($value) && $value){$total += $value;} + $cpt++; + } + $result = $total / $cpt; + } elsif ($ref->{'calcul_type'} =~ "SOM"){ + while ($svc = $sth->fetchrow_hashref()){ + if (defined($svc->{'metric_id'})){$metric_id = $svc->{'metric_id'};} + $value = get_value_in_database_metric_id($dbh,$dbh2,$metric_id,$debug); + if ($value){$total += $value;} + if ($debug){print "total = " . $total . " value = ".$value."\n";} + } + $result = $total; + } elsif ($ref->{'calcul_type'} =~ "MIN"){ + while ($svc = $sth->fetchrow_hashref()){ + if (defined($svc->{'metric_id'})){$metric_id = $svc->{'metric_id'};} + $value = get_value_in_database_metric_id($dbh,$dbh2,$metric_id,$debug); + if ($debug){print " min : " . $min . " value = ".$value."\n";} + if ($value && $value <= $min){$min = $value;} + } + $result = $min; + } elsif ($ref->{'calcul_type'} =~ "MAX"){ + while ($svc = $sth->fetchrow_hashref()){ + if (defined($svc->{'metric_id'})){$metric_id = $svc->{'metric_id'};} + $value = get_value_in_database_metric_id($dbh,$dbh2,$metric_id,$debug); + if ($debug){print "max = " . $max . " value = ".$value."\n";} + if ($value && $value >= $max){$max = $value;} + } + $result = $max; + } + return_value($result, $warning, $critical, $opt_i); + } +} + + +sub print_usage () { + print "Usage:\n"; + print " check_meta_service\n"; + print " -i Meta Service id\n"; + print " -V (--version) Plugin version\n"; + print " -h (--help) usage help\n"; +} + +sub print_help () { + print "##############################################\n"; + print "# Copyright (c) 2004-2008 Centreon #\n"; + print "# Bugs to http://bugs.oreon-project.org/ #\n"; + print "##############################################\n"; + print_usage(); + print "\n"; } \ No newline at end of file diff --git a/src/check_nt_centreon b/src/check_nt_centreon index 34316e27e..cab83192f 100644 --- a/src/check_nt_centreon +++ b/src/check_nt_centreon @@ -1,348 +1,348 @@ -#! /usr/bin/perl -w -################################################################### -# Oreon is developped with GPL Licence 2.0 -# -# GPL License: http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt -# -# Developped by : Julien Mathis - Romain Le Merlus -# Mathavarajan Sugumaran -# -################################################################### -# 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 -#################################################################### -# -# Plugin init -# - -use strict; -use FindBin; -use lib "$FindBin::Bin"; -use lib "@NAGIOS_PLUGINS@"; -use utils qw($TIMEOUT %ERRORS &print_revision &support); - -if (eval "require centreon" ) { - use centreon qw(get_parameters create_rrd update_rrd &is_valid_serviceid); - use vars qw($VERSION %centreon); - %centreon=get_parameters(); -} else { - print "Unable to load centreon perl module\n"; - exit $ERRORS{'UNKNOWN'}; -} - -use vars qw($PROGNAME); -use Getopt::Long; -use vars qw($opt_H $opt_p $opt_s $opt_v $opt_V $opt_h $opt_w $opt_c $opt_S $opt_g $opt_t $opt_l $opt_d $opt_D $opt_step $step $opt_f); - -## Plugin var init - -my $pathtolibexecnt = $centreon{GLOBAL}{NAGIOS_PLUGINS}."check_nt"; -my($op_v, $op_d, $op_s, $op_t, $op_l, $port, @values, @test, @test2, @test3, @test4, @test5, $warning, $critical, @w, @c, $uptime); -my($warning2, $critical2, $warning3, $critical3, $warning4, $critical4, @output); -$PROGNAME = $0; - -sub print_help (); -sub print_usage (); - -Getopt::Long::Configure('bundling'); -GetOptions - ("h" => \$opt_h, "help" => \$opt_h, - "p=s" => \$opt_p, "port=s" => \$opt_p, - "V" => \$opt_V, "version" => \$opt_V, - "s=s" => \$opt_s, "password=s" => \$opt_s, - "d=s" => \$opt_d, "showall=s" => \$opt_d, - "v=s" => \$opt_v, "variable=s" => \$opt_v, - "D=s" => \$opt_D, "directory=s" => \$opt_D, - "t=s" => \$opt_t, "timeout=s" => \$opt_t, - "l:s" => \$opt_l, "parameter:s" => \$opt_l, - "w=s" => \$opt_w, "warning=s" => \$opt_w, - "c=s" => \$opt_c, "critical=s" => \$opt_c, - "S=s" => \$opt_S, "ServiceId=s" => \$opt_S, - "H=s" => \$opt_H, "hostname=s" => \$opt_H); - -if ($opt_h) { - print_help(); - exit $ERRORS{'OK'}; -} - -if ($opt_V) { - $_ = `$pathtolibexecnt -V`; - print "$_"; - exit $ERRORS{'OK'}; -} - -if ($opt_p) { - if ($opt_p =~ /([0-9]+)/){ - $port = $1; - } else { - print "Unknown -p number expected... or it doesn't exist, try another port - number\n"; - exit $ERRORS{'UNKNOWN'}; - } -} - -$opt_H = shift unless ($opt_H); -(print_usage() && exit $ERRORS{'OK'}) unless ($opt_H); - - -if ($opt_c) { - ($opt_c) || ($opt_c = shift); - $critical = $1 if ($opt_c =~ /([0-9]+)/); -} - -if ($opt_w) { - ($opt_w) || ($opt_w = shift); - $warning = $1 if ($opt_w =~ /([0-9]+)/); -} - -if (($critical && $warning) && ($critical <= $warning)) { - print "(--crit) must be superior to (--warn)"; - print_usage(); - exit $ERRORS{'OK'}; -} - -if ($opt_t) { - ($opt_t) || ($opt_t = shift); - $op_t = $1 if ($opt_t =~ /([-\.,\w]+)/); -} - -if ($opt_l) { - ($opt_l) || ($opt_l = shift); - $op_l = $1 if ($opt_l =~ /(.+)/); -} - -if ($opt_d) { - ($opt_d) || ($opt_d = shift); - $op_d = $1 if ($opt_d =~ /([-.,A-Za-z0-9]+)/); -} - -if ($opt_s) { - ($opt_s) || ($opt_s = shift); - $op_s = $1 if ($opt_s =~ /([\_\-\.\,A-Za-z0-9]+)/); -} - -if ($opt_v) { - ($opt_v) || ($opt_v = shift); - $op_v = $1 if ($opt_v =~ /([-.,A-Za-z0-9]+)/); -} - -my $name = $0; -$name =~ s/\.pl.*//g; -my $return_code; - -## Plugin requests -my $start=time; -if ($op_v) { - if ($op_v) {$op_v = "-v ".$op_v;} - if ($port) {$port = "-p ".$port;} else { $port = " ";} - if ($warning) {$warning = "-w ".$warning;} else { $warning = " ";} - if ($critical) {$critical = "-c ".$critical;} else { $critical = " ";} - if ($op_l) {$op_l = "-l \"".$op_l ."\"";} else { $op_l = " ";} - if ($op_t) {$op_t = "-t ".$op_t;} else { $op_t = " ";} - if ($op_s) {$op_s = "-s ".$op_s;} else { $op_s = " ";} - if ($op_d) {$op_d = "-d ".$op_d;} else { $op_d = " ";} -# print "$pathtolibexecnt -H $opt_H $op_v $port $warning $critical $op_l $op_t $op_s $op_d\n"; - $_ = `$pathtolibexecnt -H $opt_H $op_v $port $warning $critical $op_l $op_t $op_s $op_d `; - my $return = $_; - if (!defined($return) || $return eq "") { - print "Error in command, check your command options\n"; - exit (3); - } - $return =~ s/\\//g; - $return_code = $? / 256; - ## CLIENTVERSION - if ($op_v =~ /CLIENTVERSION/){ - print "CLIENTVERSION impossible to Graph!\n"; - exit $ERRORS{'UNKNOWN'}; - } - - if (($op_v =~ /CPULOAD/) && ($op_l =~ /([-\.,\w]+)/)){ ## CPULOAD - @output = split(/\|/,$_); - @values = $output[0] =~ /(\d*)\%/g ; - $start = time; - ## Print Plugins Output - $return =~ s/\n//g; - my @return_data = split(/\|/,$return); - if (@values){ - if (defined($opt_c) && defined($opt_w)){ - print $return_data[0] . "|cpu=@values%;$opt_w;$opt_c\n"; - } else { - print $return_data[0] . "|cpu=@values%\n"; - } - } else { - print $return . "\n"; - } - exit $return_code; - } elsif ($op_v =~ /UPTIME/){ ## UPTIME - if ($_ =~ /.*[-:]+\s(\d+)\s.*$/ ) { - $uptime = $1; - } else { - print "unable to parse check_nt output: $_\n" ; - exit $ERRORS{'UNKNOWN'}; - } - $_ =~ s/\n/ /g; - if (defined($uptime)){ - print $_ . "|uptime=".$uptime."d\n"; - } else { - print $_ . "\n"; - } - exit $return_code; - } elsif (($op_v =~ /USEDDISKSPACE/) && ($op_l =~ /([-\.,\w]+)/)){ ## USEDDISKSPACE - my @test = split(/ /,$_); - if (defined($test[9]) && defined($test2[1])){ - @test2 = split(/\(/, $test[9]); - @test3 = split(/\%/, $test2[1]); - } - @c = split(/ /, $critical); - $critical = $c[1]; - @w = split(/ /, $warning); - $warning = $w[1]; - ## Print Plugins Output - $return =~ s/\n/ /g; - my @return_part = split(/\|/, $return); - #$return =~ s/%/ pct/g; - ## Put value in octets : Mo -> o - if (defined($test[3]) && defined($test[7]) && defined($test[12])){ - $test[3] =~ s/\,/\./g; - $test[3] = eval($test[3] * 1024 * 1024 * 1024); - $test[7] =~ s/\,/\./g; - $test[7] = eval ($test[7] * 1024 * 1024 * 1024); - print $return_part[0] . "|total=".$test[3]."o used=".$test[7]."o\n"; - } else { - print $return_part[0] . "\n"; - } - exit $return_code; - } elsif ($op_v =~ /MEMUSE/){ ## MEMUSE - $start = time; - my @test = split(/ /,$_); - if (defined($test[2])){ - @test4 = split(/:/, $test[2]); - } - @c = split(/ /, $critical); - $critical = $c[1]; - @w = split(/ /, $warning); - $warning = $w[1]; - ## Print Plugins Output - my @return_data = split(/\|/,$return); - $return =~ s/\n/ /g; - #$return =~ s/%/ pct/g; - if ($test4[1] && $test[6] && $test[11]){ - ## Put value in octets : Mo -> o - $test4[1] =~ s/\,/\./g; - $test4[1] = eval($test4[1] * 1024 * 1024); - $test[6] =~ s/\,/\./g; - $test[6] = eval($test[6] * 1024 * 1024); - print $return_data[0] . "|total=".$test4[1]."o used=".$test[6]."o\n"; - } else { - print $return_data[0] . "\n"; - } - exit $return_code; - } elsif ($op_v =~ /SERVICESTATE/){## SERVICESTATE - my (@tab, $process, $nom, $etat); - @tab = split (' - ',$_); - foreach $process (@tab) { - ($nom,$etat) = split (': ', $process); - if (defined($etat)) { - $etat =~ s/\n//; - } else { - $etat = "Unknown"; - } - if ($etat =~ /Started/) - {$etat=1;} - elsif ($etat =~ /Stopped/) - {$etat=0;} - elsif ($etat =~ /Unknown/) - {$etat=-1;} - else { - print "Unable to get $nom status [$etat]: \n\t$_\n"; - exit $ERRORS{'UNKNOWN'}; - } - } - $return =~ s/%/ pct/g; - print $return; - exit $return_code; - } elsif ($op_v =~ /PROCSTATE/){## PROCSTATE - print "PROCSTATE not graphed\n"; - exit $ERRORS{'UNKNOWN'}; - } elsif (($op_v =~ /COUNTER/) && ($op_l =~ /(.+)/)) { ## COUNTER - @output = split(/\|/,$_); - @values = $output[0] =~ /([,\.\d]*)\s?\%/ ; - if (!@values) {@values = $output[0] =~ /([\d]*)/;} - $start=time; - ## Print Plugins Output - $return =~ s/\n/ /g; - $return =~ s/%/ pct/g; - #print "---".$return ."---\n"; - print $return . "|counter=".@values."\n"; - exit $return_code; - } -} else { - print "Could not parse arguments\n"; - exit $ERRORS{'UNKNOWN'}; -} - -## -## Plugin return code -## - -sub print_usage () { - print "\nUsage:\n"; - print "$PROGNAME\n"; - print " Usage: check_graph_nt -H host -v variable [-p port] [-s password] [-w warning] [-c critical] [-l params] [-d SHOWALL] [-t timeout] [-D rrd directory] -g -S ServiceID\n"; - print " Options:\n"; - print " -H, --hostname=HOST\n"; - print " Name of the host to check\n"; - print " -p, --port=INTEGER\n"; - print " Optional port number (default: 1248)\n"; - print " -s \n"; - print " Password needed for the request\n"; - print " -v, --variable=STRING\n"; - print " Variable to check. Valid variables are:\n"; - print " CLIENTVERSION = Not Graphed. Get the NSClient version\n"; - print " CPULOAD = Average CPU load on last x minutes. Request a -l parameter with the following syntax:\n"; - print " -l ,,. should be less than 24*60.\n"; - print " Thresholds are percentage and up to 10 requests can be done in one shot. ie: -l 60,90,95,120,90,95\n"; - print " and 4 requests can be graphed.\n"; - print " UPTIME = Only Days are graphed. Get the uptime of the machine. No specific parameters. No warning or critical threshold.\n"; - print " USEDDISKSPACE = Size and percentage of disk use. Request a -l parameter containing the drive letter only.\n"; - print " Warning and critical thresholds can be specified with -w and -c.\n"; - print " MEMUSE = Memory use. Warning and critical thresholds can be specified with -w and -c.\n"; - print " SERVICESTATE = Check and graph the state of one service. Request a -l parameters with the following syntax:\n"; - print " -l ... You MUST specify -d SHOWALL in the input command.\n"; - print " 1: Service Started - 0: Service Stopped - -1: Service Unknown.\n"; -# print " SERVICESTATE = Not Graphed. Check the state of one or several services. Request a -l parameters with the following syntax:\n"; -# print " -l ,,,... You can specify -d SHOWALL in case you want to see working services\n"; -# print " in the returned string.\n"; - print " PROCSTATE = Not Graphed. Check if one or several process are running. Same syntax as SERVICESTATE.\n"; - print " COUNTER = Check any performance counter of Windows NT/2000. Request a -l parameters with the following syntax:\n"; - print " -l \"counter\",\"\" The parameter is optional and\n"; - print " is given to a printf output command which require a float parameters. Some examples:\n"; - print " \"Paging file usage is %.2f %%\" or \"%.f %% paging file used.\"\n"; - print " -w, --warning=INTEGER\n"; - print " Threshold which will result in a warning status\n"; - print " -c, --critical=INTEGER\n"; - print " Threshold which will result in a critical status\n"; - print " -t, --timeout=INTEGER\n"; - print " Seconds before connection attempt times out (default: 10)\n"; - print " -h, --help\n"; - print " Print this help screen\n"; - print " -V, --version\n"; - print " Print version information\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"; -} +#! /usr/bin/perl -w +################################################################### +# Oreon is developped with GPL Licence 2.0 +# +# GPL License: http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt +# +# Developped by : Julien Mathis - Romain Le Merlus +# Mathavarajan Sugumaran +# +################################################################### +# 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 +#################################################################### +# +# Plugin init +# + +use strict; +use FindBin; +use lib "$FindBin::Bin"; +use lib "@NAGIOS_PLUGINS@"; +use utils qw($TIMEOUT %ERRORS &print_revision &support); + +if (eval "require centreon" ) { + use centreon qw(get_parameters create_rrd update_rrd &is_valid_serviceid); + use vars qw($VERSION %centreon); + %centreon=get_parameters(); +} else { + print "Unable to load centreon perl module\n"; + exit $ERRORS{'UNKNOWN'}; +} + +use vars qw($PROGNAME); +use Getopt::Long; +use vars qw($opt_H $opt_p $opt_s $opt_v $opt_V $opt_h $opt_w $opt_c $opt_S $opt_g $opt_t $opt_l $opt_d $opt_D $opt_step $step $opt_f); + +## Plugin var init + +my $pathtolibexecnt = $centreon{GLOBAL}{NAGIOS_PLUGINS}."check_nt"; +my($op_v, $op_d, $op_s, $op_t, $op_l, $port, @values, @test, @test2, @test3, @test4, @test5, $warning, $critical, @w, @c, $uptime); +my($warning2, $critical2, $warning3, $critical3, $warning4, $critical4, @output); +$PROGNAME = $0; + +sub print_help (); +sub print_usage (); + +Getopt::Long::Configure('bundling'); +GetOptions + ("h" => \$opt_h, "help" => \$opt_h, + "p=s" => \$opt_p, "port=s" => \$opt_p, + "V" => \$opt_V, "version" => \$opt_V, + "s=s" => \$opt_s, "password=s" => \$opt_s, + "d=s" => \$opt_d, "showall=s" => \$opt_d, + "v=s" => \$opt_v, "variable=s" => \$opt_v, + "D=s" => \$opt_D, "directory=s" => \$opt_D, + "t=s" => \$opt_t, "timeout=s" => \$opt_t, + "l:s" => \$opt_l, "parameter:s" => \$opt_l, + "w=s" => \$opt_w, "warning=s" => \$opt_w, + "c=s" => \$opt_c, "critical=s" => \$opt_c, + "S=s" => \$opt_S, "ServiceId=s" => \$opt_S, + "H=s" => \$opt_H, "hostname=s" => \$opt_H); + +if ($opt_h) { + print_help(); + exit $ERRORS{'OK'}; +} + +if ($opt_V) { + $_ = `$pathtolibexecnt -V`; + print "$_"; + exit $ERRORS{'OK'}; +} + +if ($opt_p) { + if ($opt_p =~ /([0-9]+)/){ + $port = $1; + } else { + print "Unknown -p number expected... or it doesn't exist, try another port - number\n"; + exit $ERRORS{'UNKNOWN'}; + } +} + +$opt_H = shift unless ($opt_H); +(print_usage() && exit $ERRORS{'OK'}) unless ($opt_H); + + +if ($opt_c) { + ($opt_c) || ($opt_c = shift); + $critical = $1 if ($opt_c =~ /([0-9]+)/); +} + +if ($opt_w) { + ($opt_w) || ($opt_w = shift); + $warning = $1 if ($opt_w =~ /([0-9]+)/); +} + +if (($critical && $warning) && ($critical <= $warning)) { + print "(--crit) must be superior to (--warn)"; + print_usage(); + exit $ERRORS{'OK'}; +} + +if ($opt_t) { + ($opt_t) || ($opt_t = shift); + $op_t = $1 if ($opt_t =~ /([-\.,\w]+)/); +} + +if ($opt_l) { + ($opt_l) || ($opt_l = shift); + $op_l = $1 if ($opt_l =~ /(.+)/); +} + +if ($opt_d) { + ($opt_d) || ($opt_d = shift); + $op_d = $1 if ($opt_d =~ /([-.,A-Za-z0-9]+)/); +} + +if ($opt_s) { + ($opt_s) || ($opt_s = shift); + $op_s = $1 if ($opt_s =~ /([\_\-\.\,A-Za-z0-9]+)/); +} + +if ($opt_v) { + ($opt_v) || ($opt_v = shift); + $op_v = $1 if ($opt_v =~ /([-.,A-Za-z0-9]+)/); +} + +my $name = $0; +$name =~ s/\.pl.*//g; +my $return_code; + +## Plugin requests +my $start=time; +if ($op_v) { + if ($op_v) {$op_v = "-v ".$op_v;} + if ($port) {$port = "-p ".$port;} else { $port = " ";} + if ($warning) {$warning = "-w ".$warning;} else { $warning = " ";} + if ($critical) {$critical = "-c ".$critical;} else { $critical = " ";} + if ($op_l) {$op_l = "-l \"".$op_l ."\"";} else { $op_l = " ";} + if ($op_t) {$op_t = "-t ".$op_t;} else { $op_t = " ";} + if ($op_s) {$op_s = "-s ".$op_s;} else { $op_s = " ";} + if ($op_d) {$op_d = "-d ".$op_d;} else { $op_d = " ";} +# print "$pathtolibexecnt -H $opt_H $op_v $port $warning $critical $op_l $op_t $op_s $op_d\n"; + $_ = `$pathtolibexecnt -H $opt_H $op_v $port $warning $critical $op_l $op_t $op_s $op_d `; + my $return = $_; + if (!defined($return) || $return eq "") { + print "Error in command, check your command options\n"; + exit (3); + } + $return =~ s/\\//g; + $return_code = $? / 256; + ## CLIENTVERSION + if ($op_v =~ /CLIENTVERSION/){ + print "CLIENTVERSION impossible to Graph!\n"; + exit $ERRORS{'UNKNOWN'}; + } + + if (($op_v =~ /CPULOAD/) && ($op_l =~ /([-\.,\w]+)/)){ ## CPULOAD + @output = split(/\|/,$_); + @values = $output[0] =~ /(\d*)\%/g ; + $start = time; + ## Print Plugins Output + $return =~ s/\n//g; + my @return_data = split(/\|/,$return); + if (@values){ + if (defined($opt_c) && defined($opt_w)){ + print $return_data[0] . "|cpu=@values%;$opt_w;$opt_c\n"; + } else { + print $return_data[0] . "|cpu=@values%\n"; + } + } else { + print $return . "\n"; + } + exit $return_code; + } elsif ($op_v =~ /UPTIME/){ ## UPTIME + if ($_ =~ /.*[-:]+\s(\d+)\s.*$/ ) { + $uptime = $1; + } else { + print "unable to parse check_nt output: $_\n" ; + exit $ERRORS{'UNKNOWN'}; + } + $_ =~ s/\n/ /g; + if (defined($uptime)){ + print $_ . "|uptime=".$uptime."d\n"; + } else { + print $_ . "\n"; + } + exit $return_code; + } elsif (($op_v =~ /USEDDISKSPACE/) && ($op_l =~ /([-\.,\w]+)/)){ ## USEDDISKSPACE + my @test = split(/ /,$_); + if (defined($test[9]) && defined($test2[1])){ + @test2 = split(/\(/, $test[9]); + @test3 = split(/\%/, $test2[1]); + } + @c = split(/ /, $critical); + $critical = $c[1]; + @w = split(/ /, $warning); + $warning = $w[1]; + ## Print Plugins Output + $return =~ s/\n/ /g; + my @return_part = split(/\|/, $return); + #$return =~ s/%/ pct/g; + ## Put value in octets : Mo -> o + if (defined($test[3]) && defined($test[7]) && defined($test[12])){ + $test[3] =~ s/\,/\./g; + $test[3] = eval($test[3] * 1024 * 1024 * 1024); + $test[7] =~ s/\,/\./g; + $test[7] = eval ($test[7] * 1024 * 1024 * 1024); + print $return_part[0] . "|total=".$test[3]."o used=".$test[7]."o\n"; + } else { + print $return_part[0] . "\n"; + } + exit $return_code; + } elsif ($op_v =~ /MEMUSE/){ ## MEMUSE + $start = time; + my @test = split(/ /,$_); + if (defined($test[2])){ + @test4 = split(/:/, $test[2]); + } + @c = split(/ /, $critical); + $critical = $c[1]; + @w = split(/ /, $warning); + $warning = $w[1]; + ## Print Plugins Output + my @return_data = split(/\|/,$return); + $return =~ s/\n/ /g; + #$return =~ s/%/ pct/g; + if ($test4[1] && $test[6] && $test[11]){ + ## Put value in octets : Mo -> o + $test4[1] =~ s/\,/\./g; + $test4[1] = eval($test4[1] * 1024 * 1024); + $test[6] =~ s/\,/\./g; + $test[6] = eval($test[6] * 1024 * 1024); + print $return_data[0] . "|total=".$test4[1]."o used=".$test[6]."o\n"; + } else { + print $return_data[0] . "\n"; + } + exit $return_code; + } elsif ($op_v =~ /SERVICESTATE/){## SERVICESTATE + my (@tab, $process, $nom, $etat); + @tab = split (' - ',$_); + foreach $process (@tab) { + ($nom,$etat) = split (': ', $process); + if (defined($etat)) { + $etat =~ s/\n//; + } else { + $etat = "Unknown"; + } + if ($etat =~ /Started/) + {$etat=1;} + elsif ($etat =~ /Stopped/) + {$etat=0;} + elsif ($etat =~ /Unknown/) + {$etat=-1;} + else { + print "Unable to get $nom status [$etat]: \n\t$_\n"; + exit $ERRORS{'UNKNOWN'}; + } + } + $return =~ s/%/ pct/g; + print $return; + exit $return_code; + } elsif ($op_v =~ /PROCSTATE/){## PROCSTATE + print "PROCSTATE not graphed\n"; + exit $ERRORS{'UNKNOWN'}; + } elsif (($op_v =~ /COUNTER/) && ($op_l =~ /(.+)/)) { ## COUNTER + @output = split(/\|/,$_); + @values = $output[0] =~ /([,\.\d]*)\s?\%/ ; + if (!@values) {@values = $output[0] =~ /([\d]*)/;} + $start=time; + ## Print Plugins Output + $return =~ s/\n/ /g; + $return =~ s/%/ pct/g; + #print "---".$return ."---\n"; + print $return . "|counter=".@values."\n"; + exit $return_code; + } +} else { + print "Could not parse arguments\n"; + exit $ERRORS{'UNKNOWN'}; +} + +## +## Plugin return code +## + +sub print_usage () { + print "\nUsage:\n"; + print "$PROGNAME\n"; + print " Usage: check_graph_nt -H host -v variable [-p port] [-s password] [-w warning] [-c critical] [-l params] [-d SHOWALL] [-t timeout] [-D rrd directory] -g -S ServiceID\n"; + print " Options:\n"; + print " -H, --hostname=HOST\n"; + print " Name of the host to check\n"; + print " -p, --port=INTEGER\n"; + print " Optional port number (default: 1248)\n"; + print " -s \n"; + print " Password needed for the request\n"; + print " -v, --variable=STRING\n"; + print " Variable to check. Valid variables are:\n"; + print " CLIENTVERSION = Not Graphed. Get the NSClient version\n"; + print " CPULOAD = Average CPU load on last x minutes. Request a -l parameter with the following syntax:\n"; + print " -l ,,. should be less than 24*60.\n"; + print " Thresholds are percentage and up to 10 requests can be done in one shot. ie: -l 60,90,95,120,90,95\n"; + print " and 4 requests can be graphed.\n"; + print " UPTIME = Only Days are graphed. Get the uptime of the machine. No specific parameters. No warning or critical threshold.\n"; + print " USEDDISKSPACE = Size and percentage of disk use. Request a -l parameter containing the drive letter only.\n"; + print " Warning and critical thresholds can be specified with -w and -c.\n"; + print " MEMUSE = Memory use. Warning and critical thresholds can be specified with -w and -c.\n"; + print " SERVICESTATE = Check and graph the state of one service. Request a -l parameters with the following syntax:\n"; + print " -l ... You MUST specify -d SHOWALL in the input command.\n"; + print " 1: Service Started - 0: Service Stopped - -1: Service Unknown.\n"; +# print " SERVICESTATE = Not Graphed. Check the state of one or several services. Request a -l parameters with the following syntax:\n"; +# print " -l ,,,... You can specify -d SHOWALL in case you want to see working services\n"; +# print " in the returned string.\n"; + print " PROCSTATE = Not Graphed. Check if one or several process are running. Same syntax as SERVICESTATE.\n"; + print " COUNTER = Check any performance counter of Windows NT/2000. Request a -l parameters with the following syntax:\n"; + print " -l \"counter\",\"\" The parameter is optional and\n"; + print " is given to a printf output command which require a float parameters. Some examples:\n"; + print " \"Paging file usage is %.2f %%\" or \"%.f %% paging file used.\"\n"; + print " -w, --warning=INTEGER\n"; + print " Threshold which will result in a warning status\n"; + print " -c, --critical=INTEGER\n"; + print " Threshold which will result in a critical status\n"; + print " -t, --timeout=INTEGER\n"; + print " Seconds before connection attempt times out (default: 10)\n"; + print " -h, --help\n"; + print " Print this help screen\n"; + print " -V, --version\n"; + print " Print version information\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"; +} diff --git a/src/check_snmp_processus_loaded.pl b/src/check_snmp_processus_loaded.pl index c23366f71..280911cd1 100644 --- a/src/check_snmp_processus_loaded.pl +++ b/src/check_snmp_processus_loaded.pl @@ -1,177 +1,177 @@ -#! /usr/bin/perl - -# -# $Id: check_graph_remote_storage.pl,v 1.2 2005/07/27 22:21:49 wistof Exp $ -# -# Oreon's plugins are developped with GPL Licence : -# http://www.fsf.org/licenses/gpl.txt -# Developped by : Julien Mathis - Mathieu Mettre - Romain Le Merlus - Yohann Lecarpentier -# -# Modified for Oreon Project by : Mathieu Chateau - Christophe Coraboeuf -# -# tHe Software is provided to you AS IS and WITH ALL FAULTS. -# OREON makes no representation and gives no warranty whatsoever, -# whether express or implied, and without limitation, with regard to the quality, -# safety, contents, performance, merchantability, non-infringement or suitability for -# any particular or intended purpose of the Software found on the OREON web site. -# In no event will OREON be liable for any direct, indirect, punitive, special, -# incidental or consequential damages however they may arise and even if OREON has -# been previously advised of the possibility of such damages. - -# Plugin init - -use strict; -use Net::SNMP qw(:snmp); -use FindBin; -use lib "$FindBin::Bin"; -use lib "/usr/local/nagios/libexec"; -use utils qw($TIMEOUT %ERRORS &print_revision &support); - -if (eval "require centreon" ) { - use centreon qw(get_parameters create_rrd update_rrd &is_valid_serviceid); - use vars qw($VERSION %centreon); - %centreon=get_parameters(); -} else { - print "Unable to load centreon perl module\n"; - exit $ERRORS{'UNKNOWN'}; -} - -use vars qw($PROGNAME); -use Getopt::Long; -use vars qw($opt_V $opt_h $opt_g $opt_v $opt_C $opt_d $opt_n $opt_w $opt_c $opt_H $opt_S $opt_D $opt_s $opt_step $step @test $opt_f); - -# Plugin var init - -my ($hrStorageDescr, $hrStorageAllocationUnits, $hrStorageSize, $hrStorageUsed); -my ($AllocationUnits, $Size, $Used); -my ($tot, $used, $pourcent, $return_code); - -$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, - "s" => \$opt_s, "show" => \$opt_s, - "C=s" => \$opt_C, "community=s" => \$opt_C, - "n=s" => \$opt_n, "name=s" => \$opt_n, - "H=s" => \$opt_H, "hostname=s" => \$opt_H); - - -if ($opt_V) { - print_revision($PROGNAME,'$Revision: 1.2 $'); - 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 = "2"); -my $snmp = $1 if ($opt_v =~ /(\d)/); - -($opt_C) || ($opt_C = shift) || ($opt_C = "public"); - -($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'}; -} - -# Plugin snmp requests - -my $OID_ExecResult = ".1.3.6.1.4.1.2021.8.1.100"; -my $OID_ExecDescr = ".1.3.6.1.4.1.2021.8.1.2"; -my $OID_ExecOutput = ".1.3.6.1.4.1.2021.8.1.101"; - -# create a SNMP session - -my ( $session, $error ) = Net::SNMP->session(-hostname => $opt_H,-community => $opt_C, -version => $snmp); -if ( !defined($session) ) { - print("CRITICAL: SNMP Session : $error"); - exit $ERRORS{'CRITICAL'}; -} - -my $scriptname = ""; - -# getting partition using its name instead of its oid index - -if ($opt_n) { - my $result = $session->get_table(Baseoid => $OID_ExecDescr); - if (!defined($result)) { - printf("ERROR: hr Exec Descr Table : %s.\n", $session->error); - $session->close; - exit $ERRORS{'UNKNOWN'}; - } - foreach my $key ( oid_lex_sort(keys %$result)) { - if ($result->{$key} =~ m/^$opt_n$/) { - my @oid_list = split (/\./,$key); - $scriptname = pop (@oid_list) ; - } - } -} - - -if ($scriptname eq "") { - print "No such process, verify your snmpd configuration\n"; - exit(3); -} - -my $result = $session->get_request(-varbindlist => [$OID_ExecDescr.".".$scriptname, $OID_ExecOutput.".".$scriptname]); - -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"; - $session->close; - exit $ERRORS{'UNKNOWN'}; -} - -my $ExecResult = $result->{$OID_ExecResult.".".$scriptname }; -my $ExecDescr = $result->{$OID_ExecDescr.".".$scriptname }; -my $ExecOutput = $result->{$OID_ExecOutput.".".$scriptname }; -if ($ExecOutput =~ /cannot\ open/) { - $ExecResult = 3; -} -print $ExecOutput . "\n"; -exit($ExecResult); - -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 " -n (--name) Allows to use disk name with option -d instead of disk oid index\n"; - 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 " -w (--warn) Signal strength at which a warning message will be generated\n"; - print " (default 80)\n"; - print " -c (--crit) Signal strength at which a critical message will be generated\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-2006 centreon #\n"; - print "# Bugs to http://www.oreon-project.org/ #\n"; - print "##########################################\n"; - print_usage(); - print "\n"; -} +#! /usr/bin/perl + +# +# $Id: check_graph_remote_storage.pl,v 1.2 2005/07/27 22:21:49 wistof Exp $ +# +# Oreon's plugins are developped with GPL Licence : +# http://www.fsf.org/licenses/gpl.txt +# Developped by : Julien Mathis - Mathieu Mettre - Romain Le Merlus - Yohann Lecarpentier +# +# Modified for Oreon Project by : Mathieu Chateau - Christophe Coraboeuf +# +# tHe Software is provided to you AS IS and WITH ALL FAULTS. +# OREON makes no representation and gives no warranty whatsoever, +# whether express or implied, and without limitation, with regard to the quality, +# safety, contents, performance, merchantability, non-infringement or suitability for +# any particular or intended purpose of the Software found on the OREON web site. +# In no event will OREON be liable for any direct, indirect, punitive, special, +# incidental or consequential damages however they may arise and even if OREON has +# been previously advised of the possibility of such damages. + +# Plugin init + +use strict; +use Net::SNMP qw(:snmp); +use FindBin; +use lib "$FindBin::Bin"; +use lib "/usr/local/nagios/libexec"; +use utils qw($TIMEOUT %ERRORS &print_revision &support); + +if (eval "require centreon" ) { + use centreon qw(get_parameters create_rrd update_rrd &is_valid_serviceid); + use vars qw($VERSION %centreon); + %centreon=get_parameters(); +} else { + print "Unable to load centreon perl module\n"; + exit $ERRORS{'UNKNOWN'}; +} + +use vars qw($PROGNAME); +use Getopt::Long; +use vars qw($opt_V $opt_h $opt_g $opt_v $opt_C $opt_d $opt_n $opt_w $opt_c $opt_H $opt_S $opt_D $opt_s $opt_step $step @test $opt_f); + +# Plugin var init + +my ($hrStorageDescr, $hrStorageAllocationUnits, $hrStorageSize, $hrStorageUsed); +my ($AllocationUnits, $Size, $Used); +my ($tot, $used, $pourcent, $return_code); + +$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, + "s" => \$opt_s, "show" => \$opt_s, + "C=s" => \$opt_C, "community=s" => \$opt_C, + "n=s" => \$opt_n, "name=s" => \$opt_n, + "H=s" => \$opt_H, "hostname=s" => \$opt_H); + + +if ($opt_V) { + print_revision($PROGNAME,'$Revision: 1.2 $'); + 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 = "2"); +my $snmp = $1 if ($opt_v =~ /(\d)/); + +($opt_C) || ($opt_C = shift) || ($opt_C = "public"); + +($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'}; +} + +# Plugin snmp requests + +my $OID_ExecResult = ".1.3.6.1.4.1.2021.8.1.100"; +my $OID_ExecDescr = ".1.3.6.1.4.1.2021.8.1.2"; +my $OID_ExecOutput = ".1.3.6.1.4.1.2021.8.1.101"; + +# create a SNMP session + +my ( $session, $error ) = Net::SNMP->session(-hostname => $opt_H,-community => $opt_C, -version => $snmp); +if ( !defined($session) ) { + print("CRITICAL: SNMP Session : $error"); + exit $ERRORS{'CRITICAL'}; +} + +my $scriptname = ""; + +# getting partition using its name instead of its oid index + +if ($opt_n) { + my $result = $session->get_table(Baseoid => $OID_ExecDescr); + if (!defined($result)) { + printf("ERROR: hr Exec Descr Table : %s.\n", $session->error); + $session->close; + exit $ERRORS{'UNKNOWN'}; + } + foreach my $key ( oid_lex_sort(keys %$result)) { + if ($result->{$key} =~ m/^$opt_n$/) { + my @oid_list = split (/\./,$key); + $scriptname = pop (@oid_list) ; + } + } +} + + +if ($scriptname eq "") { + print "No such process, verify your snmpd configuration\n"; + exit(3); +} + +my $result = $session->get_request(-varbindlist => [$OID_ExecDescr.".".$scriptname, $OID_ExecOutput.".".$scriptname]); + +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"; + $session->close; + exit $ERRORS{'UNKNOWN'}; +} + +my $ExecResult = $result->{$OID_ExecResult.".".$scriptname }; +my $ExecDescr = $result->{$OID_ExecDescr.".".$scriptname }; +my $ExecOutput = $result->{$OID_ExecOutput.".".$scriptname }; +if ($ExecOutput =~ /cannot\ open/) { + $ExecResult = 3; +} +print $ExecOutput . "\n"; +exit($ExecResult); + +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 " -n (--name) Allows to use disk name with option -d instead of disk oid index\n"; + 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 " -w (--warn) Signal strength at which a warning message will be generated\n"; + print " (default 80)\n"; + print " -c (--crit) Signal strength at which a critical message will be generated\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-2006 centreon #\n"; + print "# Bugs to http://www.oreon-project.org/ #\n"; + print "##########################################\n"; + print_usage(); + print "\n"; +} diff --git a/src/check_snmp_script_result.pl b/src/check_snmp_script_result.pl index 0204b58ad..71dfbd00d 100644 --- a/src/check_snmp_script_result.pl +++ b/src/check_snmp_script_result.pl @@ -1,196 +1,196 @@ -#! /usr/bin/perl - -# -# $Id: check_graph_remote_storage.pl,v 1.2 2005/07/27 22:21:49 wistof Exp $ -# -# centreon's plugins are developped with GPL Licence : -# http://www.fsf.org/licenses/gpl.txt -# Developped by : Julien Mathis - Mathieu Mettre - Romain Le Merlus - Yohann Lecarpentier -# -# Modified for centreon Project by : Mathieu Chateau - Christophe Coraboeuf -# -# The Software is provided to you AS IS and WITH ALL FAULTS. -# centreon makes no representation and gives no warranty whatsoever, -# whether express or implied, and without limitation, with regard to the quality, -# safety, contents, performance, merchantability, non-infringement or suitability for -# any particular or intended purpose of the Software found on the centreon web site. -# In no event will centreon be liable for any direct, indirect, punitive, special, -# incidental or consequential damages however they may arise and even if centreon has -# been previously advised of the possibility of such damages. - -# Plugin init - -use strict; -use Net::SNMP qw(:snmp); -use FindBin; -use lib "$FindBin::Bin"; -use lib "/usr/local/nagios/libexec"; -use utils qw($TIMEOUT %ERRORS &print_revision &support); - -if (eval "require centreon" ) { - use centreon qw(get_parameters create_rrd update_rrd &is_valid_serviceid); - use vars qw($VERSION %centreon); - %centreon=get_parameters(); -} else { - print "Unable to load centreon perl module\n"; - exit $ERRORS{'UNKNOWN'}; -} - -use vars qw($PROGNAME); -use Getopt::Long; -use vars qw($opt_V $opt_h $opt_g $opt_v $opt_C $opt_d $opt_n $opt_w $opt_c $opt_H $opt_S $opt_D $opt_s $opt_step $step @test $opt_f); - -# Plugin var init - -my ($hrStorageDescr, $hrStorageAllocationUnits, $hrStorageSize, $hrStorageUsed); -my ($AllocationUnits, $Size, $Used); -my ($tot, $used, $pourcent, $return_code); - -$PROGNAME = "check_snmp_remote_storage"; -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, - "s" => \$opt_s, "show" => \$opt_s, - "C=s" => \$opt_C, "community=s" => \$opt_C, - "n=s" => \$opt_n, "name=s" => \$opt_n, - "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.2 $'); - 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 = "2"); -my $snmp = $1 if ($opt_v =~ /(\d)/); - -($opt_C) || ($opt_C = shift) || ($opt_C = "public"); - -($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'}; -} - -# Plugin snmp requests - -my $OID_ExecDescr = ".1.3.6.1.4.1.2021.8.1.2"; -my $OID_ExecOutput = ".1.3.6.1.4.1.2021.8.1.101"; - -# create a SNMP session - -my ( $session, $error ) = Net::SNMP->session(-hostname => $opt_H,-community => $opt_C, -version => $snmp); -if ( !defined($session) ) { - print("CRITICAL: SNMP Session : $error"); - exit $ERRORS{'CRITICAL'}; -} - -my $scriptname = ""; - -# getting partition using its name instead of its oid index - -if ($opt_n) { - my $result = $session->get_table(Baseoid => $OID_ExecDescr); - if (!defined($result)) { - printf("ERROR: hr Exec Descr Table : %s.\n", $session->error); - $session->close; - exit $ERRORS{'UNKNOWN'}; - } - foreach my $key ( oid_lex_sort(keys %$result)) { - if ($result->{$key} =~ m/$opt_n/) { - my @oid_list = split (/\./,$key); - $scriptname = pop (@oid_list) ; - } - } -} - - -my $result = $session->get_request(-varbindlist => [$OID_ExecDescr.".".$scriptname, $OID_ExecOutput.".".$scriptname]); - -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"; - $session->close; - exit $ERRORS{'UNKNOWN'}; -} - -my $ExecDescr = $result->{$OID_ExecDescr.".".$scriptname }; -my $ExecOutput = $result->{$OID_ExecOutput.".".$scriptname }; - -print "|" . $ExecOutput . "\n"; - -my $return = 5; - -if (!defined($opt_w) && !defined($opt_c)){ - $ExecOutput =~ /([0-9]*)/; - if ($1 eq 1){ - print "OK : Process runnable \n"; - $return = 0; - } else { - print "CRITICAL : Process runnable \n"; - $return = 2; - } -} else { - if ($ExecOutput =~ /([0-9]*)/){ - if ($1 >= $opt_w && $1 < $opt_c){ - print "OK : $1 Process runnable \n"; - $return = 1; - } elsif ($1 > $opt_c) { - print "WARNING : $1 Process runnable \n"; - $return = 2; - } elsif ($1 < $opt_w) { - print "CRITICAL : Process runnable \n"; - $return = 0; - } - } -} -exit($return); - -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 " -n (--name) Allows to use disk name with option -d instead of disk oid index\n"; - 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 " -w (--warn) Signal strength at which a warning message will be generated\n"; - print " (default 80)\n"; - print " -c (--crit) Signal strength at which a critical message will be generated\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-2006 centreon #\n"; - print "# Bugs to http://www.oreon-project.org/ #\n"; - print "##########################################\n"; - print_usage(); - print "\n"; -} +#! /usr/bin/perl + +# +# $Id: check_graph_remote_storage.pl,v 1.2 2005/07/27 22:21:49 wistof Exp $ +# +# centreon's plugins are developped with GPL Licence : +# http://www.fsf.org/licenses/gpl.txt +# Developped by : Julien Mathis - Mathieu Mettre - Romain Le Merlus - Yohann Lecarpentier +# +# Modified for centreon Project by : Mathieu Chateau - Christophe Coraboeuf +# +# The Software is provided to you AS IS and WITH ALL FAULTS. +# centreon makes no representation and gives no warranty whatsoever, +# whether express or implied, and without limitation, with regard to the quality, +# safety, contents, performance, merchantability, non-infringement or suitability for +# any particular or intended purpose of the Software found on the centreon web site. +# In no event will centreon be liable for any direct, indirect, punitive, special, +# incidental or consequential damages however they may arise and even if centreon has +# been previously advised of the possibility of such damages. + +# Plugin init + +use strict; +use Net::SNMP qw(:snmp); +use FindBin; +use lib "$FindBin::Bin"; +use lib "/usr/local/nagios/libexec"; +use utils qw($TIMEOUT %ERRORS &print_revision &support); + +if (eval "require centreon" ) { + use centreon qw(get_parameters create_rrd update_rrd &is_valid_serviceid); + use vars qw($VERSION %centreon); + %centreon=get_parameters(); +} else { + print "Unable to load centreon perl module\n"; + exit $ERRORS{'UNKNOWN'}; +} + +use vars qw($PROGNAME); +use Getopt::Long; +use vars qw($opt_V $opt_h $opt_g $opt_v $opt_C $opt_d $opt_n $opt_w $opt_c $opt_H $opt_S $opt_D $opt_s $opt_step $step @test $opt_f); + +# Plugin var init + +my ($hrStorageDescr, $hrStorageAllocationUnits, $hrStorageSize, $hrStorageUsed); +my ($AllocationUnits, $Size, $Used); +my ($tot, $used, $pourcent, $return_code); + +$PROGNAME = "check_snmp_remote_storage"; +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, + "s" => \$opt_s, "show" => \$opt_s, + "C=s" => \$opt_C, "community=s" => \$opt_C, + "n=s" => \$opt_n, "name=s" => \$opt_n, + "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.2 $'); + 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 = "2"); +my $snmp = $1 if ($opt_v =~ /(\d)/); + +($opt_C) || ($opt_C = shift) || ($opt_C = "public"); + +($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'}; +} + +# Plugin snmp requests + +my $OID_ExecDescr = ".1.3.6.1.4.1.2021.8.1.2"; +my $OID_ExecOutput = ".1.3.6.1.4.1.2021.8.1.101"; + +# create a SNMP session + +my ( $session, $error ) = Net::SNMP->session(-hostname => $opt_H,-community => $opt_C, -version => $snmp); +if ( !defined($session) ) { + print("CRITICAL: SNMP Session : $error"); + exit $ERRORS{'CRITICAL'}; +} + +my $scriptname = ""; + +# getting partition using its name instead of its oid index + +if ($opt_n) { + my $result = $session->get_table(Baseoid => $OID_ExecDescr); + if (!defined($result)) { + printf("ERROR: hr Exec Descr Table : %s.\n", $session->error); + $session->close; + exit $ERRORS{'UNKNOWN'}; + } + foreach my $key ( oid_lex_sort(keys %$result)) { + if ($result->{$key} =~ m/$opt_n/) { + my @oid_list = split (/\./,$key); + $scriptname = pop (@oid_list) ; + } + } +} + + +my $result = $session->get_request(-varbindlist => [$OID_ExecDescr.".".$scriptname, $OID_ExecOutput.".".$scriptname]); + +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"; + $session->close; + exit $ERRORS{'UNKNOWN'}; +} + +my $ExecDescr = $result->{$OID_ExecDescr.".".$scriptname }; +my $ExecOutput = $result->{$OID_ExecOutput.".".$scriptname }; + +print "|" . $ExecOutput . "\n"; + +my $return = 5; + +if (!defined($opt_w) && !defined($opt_c)){ + $ExecOutput =~ /([0-9]*)/; + if ($1 eq 1){ + print "OK : Process runnable \n"; + $return = 0; + } else { + print "CRITICAL : Process runnable \n"; + $return = 2; + } +} else { + if ($ExecOutput =~ /([0-9]*)/){ + if ($1 >= $opt_w && $1 < $opt_c){ + print "OK : $1 Process runnable \n"; + $return = 1; + } elsif ($1 > $opt_c) { + print "WARNING : $1 Process runnable \n"; + $return = 2; + } elsif ($1 < $opt_w) { + print "CRITICAL : Process runnable \n"; + $return = 0; + } + } +} +exit($return); + +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 " -n (--name) Allows to use disk name with option -d instead of disk oid index\n"; + 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 " -w (--warn) Signal strength at which a warning message will be generated\n"; + print " (default 80)\n"; + print " -c (--crit) Signal strength at which a critical message will be generated\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-2006 centreon #\n"; + print "# Bugs to http://www.oreon-project.org/ #\n"; + print "##########################################\n"; + print_usage(); + print "\n"; +} diff --git a/src/process-service-perfdata b/src/process-service-perfdata index 6ee8bb45f..fb3ccf7e6 100644 --- a/src/process-service-perfdata +++ b/src/process-service-perfdata @@ -1,36 +1,36 @@ -#! /bin/sh -################################################################### -# Centreon is developped with GPL Licence 2.0 -# -# GPL License: http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt -# -# Developped by : Julien Mathis - Romain Le Merlus -# Christophe Coraboeuf - Sugumaran Mathavarajan -# -################################################################### -# 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 -# - -# some parameters passed on command line -TIMET=$1 -HOSTNAME=$2 -SERVICEDESC=$3 -OUTPUT=$4 -SERVICESTATE=$5 -PERFDATA=$6 -PERFFILE="@NAGIOS_VAR@/service-perfdata" - -/usr/bin/printf "%b" "$TIMET\t$HOSTNAME\t$SERVICEDESC\t$OUTPUT\t$SERVICESTATE\t$PERFDATA\n" >> $PERFFILE +#! /bin/sh +################################################################### +# Centreon is developped with GPL Licence 2.0 +# +# GPL License: http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt +# +# Developped by : Julien Mathis - Romain Le Merlus +# Christophe Coraboeuf - Sugumaran Mathavarajan +# +################################################################### +# 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 +# + +# some parameters passed on command line +TIMET=$1 +HOSTNAME=$2 +SERVICEDESC=$3 +OUTPUT=$4 +SERVICESTATE=$5 +PERFDATA=$6 +PERFFILE="@NAGIOS_VAR@/service-perfdata" + +/usr/bin/printf "%b" "$TIMET\t$HOSTNAME\t$SERVICEDESC\t$OUTPUT\t$SERVICESTATE\t$PERFDATA\n" >> $PERFFILE diff --git a/src/traps/conf/snmp.conf b/src/traps/conf/snmp.conf index bccd67e0b..a7a43df82 100644 --- a/src/traps/conf/snmp.conf +++ b/src/traps/conf/snmp.conf @@ -1,2 +1,2 @@ -mibs ALL -mibAllowUnderline 1 +mibs ALL +mibAllowUnderline 1 diff --git a/src/traps/conf/snmptt.ini b/src/traps/conf/snmptt.ini index 5b38162a7..45061147a 100644 --- a/src/traps/conf/snmptt.ini +++ b/src/traps/conf/snmptt.ini @@ -1,488 +1,488 @@ -# -# SNMPTT v1.0 Configuration File -# -# Linux / Unix -# - -[General] -# Set to either 'standalone' or 'daemon' -# standalone: snmptt called from snmptrapd.conf -# daemon: snmptrapd.conf calls snmptthandler -# Ignored by Windows. See documentation -mode = standalone - -# Set to 1 to allow multiple trap definitions to be executed for the same trap. -# Set to 0 to have it stop after the first match. -# Note: Wildcard matches are only matched if there are NO exact matches. This takes -# into consideration the NODES list. Therefore, if there is a matching trap, but -# the NODES list prevents it from being considered a match, the wildcard entry will -# only be used if there are no other exact matches. -multiple_event = 1 - -# SNMPTRAPD passes the IP address of device sending the trap, and the IP address of the -# actual SNMP agent. These addresses could differ if the trap was sent on behalf of another -# device (relay, proxy etc). -# If DNS is enabled, the agent IP address is converted to a host name using a DNS lookup -# (which includes the local hosts file, depending on how the OS is configured). This name -# will be used for: NODES entry matches, hostname field in logged traps (file / database), -# and the $A variable. Host names on the NODES line will be resolved and the IP address -# will then be used for comparing. -# Set to 0 to disable DNS resolution -# Set to 1 to enable DNS resolution -dns_enable = 0 - -# Set to 0 to enable the use of FQDN (Fully Qualified Domain Names). If a host name is -# passed to SNMPTT that contains a domain name, it will not be altered in any way by -# SNMPTT. This also affects resolve_value_ip_addresses. -# Set to 1 to have SNMPTT strip the domain name from the host name passed to it. For -# example, server01.domain.com would be changed to server01 -# Set to 2 to have SNMPTT strip the domain name from the host name passed to it -# based on the list of domains in strip_domain_list -strip_domain = 0 - -# List of domain names that should be stripped when strip_domain is set to 2. -# List can contain one or more domains. For example, if the FQDN of a host is -# server01.city.domain.com and the list contains domain.com, the 'host' will be -# set as server01.city. -strip_domain_list = <