From 7d2aeed93afe507f785f4faa171b5c4fd04fd750 Mon Sep 17 00:00:00 2001 From: Mat Sugumaran Date: Tue, 13 Mar 2007 15:27:55 +0000 Subject: [PATCH] git-svn-id: http://svn.centreon.com/Plugins/Dev@1705 6bcd3966-0018-0410-8128-fd23d134de7e --- .../src/check_graph_dell_temperature.pl | 218 ++++++ centreon-plugins/src/check_graph_http.pl | 218 ++++++ .../src/check_graph_load_average.pl | 185 +++++ centreon-plugins/src/check_graph_nt.pl | 404 +++++++++++ centreon-plugins/src/check_graph_ping.pl | 215 ++++++ centreon-plugins/src/check_graph_process.pl | 232 ++++++ .../src/check_graph_remote_storage.pl | 333 +++++++++ .../src/check_graph_snmp_value.pl | 195 ++++++ centreon-plugins/src/check_graph_tcp.pl | 135 ++++ centreon-plugins/src/check_graph_traffic.pl | 451 ++++++++++++ .../src/check_graph_traffic_rrd.pl | 316 +++++++++ centreon-plugins/src/check_graph_uptime.pl | 212 ++++++ centreon-plugins/src/check_meta_service.pl | 369 ++++++++++ centreon-plugins/src/check_nt_oreon.pl | 337 +++++++++ centreon-plugins/src/check_snmp_cpfw.pl | 534 ++++++++++++++ centreon-plugins/src/check_snmp_load.pl | 593 ++++++++++++++++ centreon-plugins/src/check_snmp_mem.pl | 543 ++++++++++++++ centreon-plugins/src/check_snmp_process.pl | 602 ++++++++++++++++ centreon-plugins/src/check_snmp_storage.pl | 662 ++++++++++++++++++ centreon-plugins/src/check_snmp_win.pl | 381 ++++++++++ centreon-plugins/src/oreon.conf | 49 ++ centreon-plugins/src/oreon.pm | 218 ++++++ centreon-plugins/src/process-service-perfdata | 10 + centreon-plugins/src/submit_host_check_result | 34 + .../src/submit_service_check_result | 38 + centreon-plugins/src/traps/trap_common.pm | 128 ++++ centreon-plugins/src/traps/trap_handler.sh | 37 + centreon-plugins/src/traps/trap_link.pl | 61 ++ 28 files changed, 7710 insertions(+) create mode 100644 centreon-plugins/src/check_graph_dell_temperature.pl create mode 100644 centreon-plugins/src/check_graph_http.pl create mode 100644 centreon-plugins/src/check_graph_load_average.pl create mode 100644 centreon-plugins/src/check_graph_nt.pl create mode 100644 centreon-plugins/src/check_graph_ping.pl create mode 100644 centreon-plugins/src/check_graph_process.pl create mode 100644 centreon-plugins/src/check_graph_remote_storage.pl create mode 100644 centreon-plugins/src/check_graph_snmp_value.pl create mode 100644 centreon-plugins/src/check_graph_tcp.pl create mode 100644 centreon-plugins/src/check_graph_traffic.pl create mode 100644 centreon-plugins/src/check_graph_traffic_rrd.pl create mode 100644 centreon-plugins/src/check_graph_uptime.pl create mode 100644 centreon-plugins/src/check_meta_service.pl create mode 100644 centreon-plugins/src/check_nt_oreon.pl create mode 100644 centreon-plugins/src/check_snmp_cpfw.pl create mode 100644 centreon-plugins/src/check_snmp_load.pl create mode 100644 centreon-plugins/src/check_snmp_mem.pl create mode 100644 centreon-plugins/src/check_snmp_process.pl create mode 100644 centreon-plugins/src/check_snmp_storage.pl create mode 100644 centreon-plugins/src/check_snmp_win.pl create mode 100644 centreon-plugins/src/oreon.conf create mode 100644 centreon-plugins/src/oreon.pm create mode 100644 centreon-plugins/src/process-service-perfdata create mode 100644 centreon-plugins/src/submit_host_check_result create mode 100644 centreon-plugins/src/submit_service_check_result create mode 100644 centreon-plugins/src/traps/trap_common.pm create mode 100644 centreon-plugins/src/traps/trap_handler.sh create mode 100644 centreon-plugins/src/traps/trap_link.pl diff --git a/centreon-plugins/src/check_graph_dell_temperature.pl b/centreon-plugins/src/check_graph_dell_temperature.pl new file mode 100644 index 000000000..bc6e51e6c --- /dev/null +++ b/centreon-plugins/src/check_graph_dell_temperature.pl @@ -0,0 +1,218 @@ +#! /usr/bin/perl -w +# +# $Id: check_graph_dell_temperature.pl,v 1.1 2005/07/27 22:22:48 wistof Exp $ +# +# Oreon's plugins are developped with GPL Licence : +# http://www.fsf.org/licenses/gpl.txt +# Developped by : Wistof +# +# 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. + +# based on "graph plugins" developped by Oreon Team. See http://www.oreon.org. +## +## 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 oreon" ) { + use oreon qw(get_parameters create_rrd update_rrd &is_valid_serviceid); + use vars qw($VERSION %oreon); + %oreon=get_parameters(); +} else { + print "Unable to load oreon perl module\n"; + exit $ERRORS{'UNKNOWN'}; +} + +use vars qw($PROGNAME $VERSION); +use Getopt::Long; +use vars qw($opt_h $opt_V $opt_g $opt_D $opt_S $opt_H $opt_C $opt_v $opt_s $opt_t $opt_step $step $sensor $OID $OID_DESC); + +## +## Plugin var init +## + + +$VERSION = '$Revision: 1.1 $'; +$VERSION =~ s/^\$.*:\W(.*)\W.+?$/$1/; + +my $pathtorrdbase = $oreon{GLOBAL}{DIR_RRDTOOL}; +$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, + "g" => \$opt_g, "rrdgraph" => \$opt_g, + "rrd_step=s" => \$opt_step, + "v=s" => \$opt_v, "snmp=s" => \$opt_v, + "C=s" => \$opt_C, "community=s" => \$opt_C, + "S=s" => \$opt_S, "ServiceId=s" => \$opt_S, + "s" => \$opt_s, "show" => \$opt_s, + "t=s" => \$opt_t, "sensor=s" => \$opt_t, + "H=s" => \$opt_H, "hostname=s" => \$opt_H); + +if ($opt_V) { + print_revision($PROGNAME,'$Revision: 1.1 $'); + exit $ERRORS{'OK'}; +} + +if ($opt_h) { + print_help(); + exit $ERRORS{'OK'}; +} + +$opt_H = shift unless ($opt_H); +(print_usage() && exit $ERRORS{'OK'}) unless ($opt_H); + +($opt_v) || ($opt_v = shift) || ($opt_v = "1"); +my $snmp = $1 if ($opt_v =~ /(\d)/); + +($opt_t) || ($opt_t = shift) || ($opt_t = "1"); +my $sensor = $1 if ($opt_t =~ /(\d)/); + +($opt_S) || ($opt_S = shift) || ($opt_S = "1_1"); +my $ServiceId = is_valid_serviceid($opt_S); + +($opt_C) || ($opt_C = shift) || ($opt_C = "public"); + +($opt_step) || ($opt_step = shift) || ($opt_step = "300"); +$step = $1 if ($opt_step =~ /(\d+)/); + + +my $rrd = $pathtorrdbase.$ServiceId.".rrd"; + +my $start=time; +my $name = $0; +$name =~ s/\.pl.*//g; + +## +## RRDTools create rrd +## +if ($opt_g) { + if (! -e $rrd) { + oreon::create_rrd ($rrd,1,$start,$step,"U","U","GAUGE"); + } +} + +## +## Plugin snmp requests +## +my $OID = ".1.3.6.1.4.1.674.10892.1.700.20.1.6.1"; +my $OID_DESC = ".1.3.6.1.4.1.674.10892.1.700.20.1.8.1"; + + +# create a SNMP session +my ( $session, $error ) = Net::SNMP->session(-hostname => $opt_H,-community => $opt_C, -version => $snmp); +if ( !defined($session) ) { + print("UNKNOWN: $error"); + exit $ERRORS{'UNKNOWN'}; +} + +if ($opt_s) { + # Get desctiption table + my $result = $session->get_table( + Baseoid => $OID_DESC + ); + + if (!defined($result)) { + printf("ERROR: Description Table : %s.\n", $session->error); + $session->close; + exit $ERRORS{'UNKNOWN'}; + } + + foreach my $key ( oid_lex_sort(keys %$result)) { + my @oid_list = split (/\./,$key); + my $index = pop (@oid_list) ; + print "Temperature Sensor $index :: $$result{$key}\n"; + } +exit $ERRORS{'OK'}; +} + + +my $result = $session->get_request( + -varbindlist => [$OID.".".$sensor, + $OID_DESC.".".$sensor] + ); +if (!defined($result)) { + printf("UNKNOWN: %s.\n", $session->error); + $session->close; + exit $ERRORS{'UNKNOWN'}; +} + +my $return_result = $result->{$OID.".".$sensor}; +my $un = 0; +if ($return_result =~ /(\d+)/ ) { + $un = $1; +} else { + printf("UNKNOWN: Unable to parse SNMP Output :: %s", $return_result ); + $session->close; + exit $ERRORS{'UNKNOWN'}; +} + +$un = sprintf("%02.2f", $un / 10); + +## +## RRDtools update +## +if ($opt_g) { + $start=time; + oreon::update_rrd ($rrd,$start,$un); +} + +## +## Plugin return code +## +if ($un || ( $un == 0) ){ + print "OK - ". $result->{$OID_DESC.".".$sensor} ." : $un\n"; + exit $ERRORS{'OK'}; +} +else{ + print "CRITICAL Host unavailable\n"; + exit $ERRORS{'CRITICAL'}; +} + + +sub print_usage () { + print "\nUsage:\n"; + print "$PROGNAME\n"; + print " -H (--hostname) Hostname to query - (required)\n"; + print " -C (--community) SNMP read community (defaults to public,\n"; + print " used with SNMP v1 and v2c\n"; + print " -v (--snmp_version) 1 for SNMP v1 (default)\n"; + print " 2 for SNMP v2c\n"; + print " -g (--rrdgraph) create a rrd base and add datas into this one\n"; + print " --rrd_step Specifies the base interval in seconds with which data will be fed into the RRD (300 by default)\n"; + print " -D (--directory) Path to rrdatabase (or create the .rrd in this directory)\n"; + print " by default: ".$pathtorrdbase."\n"; + print " (The path is valid with spaces '/my\ path/...')\n"; + print " -S (--ServiceId) Oreon Service Id\n"; + print " -t (--sensor) Set the sensor number (1 by default)\n"; + print " -s (--show) Describes all sensors \n"; + print " -V (--version) Plugin version\n"; + print " -h (--help) usage help\n"; + +} + +sub print_help () { + print "Copyright (c) 2005 Oreon\n"; + print "Bugs to http://www.oreon.org/\n"; + print "\n"; + print_usage(); + print "\n"; +} diff --git a/centreon-plugins/src/check_graph_http.pl b/centreon-plugins/src/check_graph_http.pl new file mode 100644 index 000000000..e9c066fb7 --- /dev/null +++ b/centreon-plugins/src/check_graph_http.pl @@ -0,0 +1,218 @@ +#! /usr/bin/perl -w +# +# $Id: check_graph_http.pl,v 1.3 2005/08/01 18:03:52 gollum123 Exp $ +# +# This plugin is developped under GPL Licence: +# http://www.fsf.org/licenses/gpl.txt + +# Developped by Linagora SA: http://www.linagora.com + +# Modified for Oreon Project by : Mathieu Chateau - Christophe Coraboeuf + +# The Software is provided to you AS IS and WITH ALL FAULTS. +# LINAGORA 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 LINAGORA web site. +# In no event will LINAGORA be liable for any direct, indirect, punitive, special, +# incidental or consequential damages however they may arise and even if LINAGORA has +# been previously advised of the possibility of such damages. + +# based on "graph plugins" developped by Oreon Team. See http://www.oreon.org. + +## +## 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 oreon" ) { + use oreon qw(get_parameters create_rrd update_rrd &is_valid_serviceid); + use vars qw($VERSION %oreon); + %oreon=get_parameters(); +} else { + print "Unable to load oreon perl module\n"; + exit $ERRORS{'UNKNOWN'}; +} + +use Getopt::Long; +use vars qw($opt_h $opt_V $opt_g $opt_D $opt_S $opt_H $opt_I $opt_e $opt_s $opt_u $opt_p $opt_P $opt_w $opt_c + $opt_t $opt_a $opt_L $opt_f $opt_l $opt_r $opt_R $opt_z $opt_C $opt_step $step); +use vars qw($PROGNAME); + +## +## Plugin var init +## +my $pathtorrdbase = $oreon{GLOBAL}{DIR_RRDTOOL}; +my $pathtolibexechttp = $oreon{GLOBAL}{ NAGIOS_LIBEXEC}."check_http"; + +$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, + "g" => \$opt_g, "rrdgraph" => \$opt_g, + "rrd_step=s" => \$opt_step, + "S=s" => \$opt_S, "ServiceId=s" => \$opt_S, + "H=s" => \$opt_H, "hostname=s" => \$opt_H, + "I=s" => \$opt_I, "IP-address=s" => \$opt_I, + "e=s" => \$opt_e, "expect=s" => \$opt_e, + "s=s" => \$opt_s, "string=s" => \$opt_s, + "u=s" => \$opt_u, "url=s" => \$opt_u, + "p=s" => \$opt_p, "port=s" => \$opt_p, + "P=s" => \$opt_P, "post=s" => \$opt_P, + "w=s" => \$opt_w, "warning=s" => \$opt_w, + "c=s" => \$opt_c, "critical=s" => \$opt_c, + "t=s" => \$opt_t, "timeout=s" => \$opt_t, + "a=s" => \$opt_a, "authorization=s" => \$opt_a, + "L=s" => \$opt_L, "link=s" => \$opt_L, + "f=s" => \$opt_f, "onredirect=s" => \$opt_f, + "l=s" => \$opt_l, "linespan=s" => \$opt_l, + "r=s" => \$opt_r, "regex=s" => \$opt_r, + "R=s" => \$opt_R, "eregi=s" => \$opt_R, + "C=s" => \$opt_C, "certificate=s" => \$opt_C, + "z" => \$opt_R, "ssl" => \$opt_z + + ); + +if ($opt_V) { + print_revision($PROGNAME,'$Revision: 1.3 $'); + 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_S) || ($opt_S = shift) || ($opt_S = "1_1"); +my $ServiceId = is_valid_serviceid($opt_S); + +($opt_step) || ($opt_step = shift) || ($opt_step = "300"); +$step = $1 if ($opt_step =~ /(\d+)/); + +my $args_check_http = ""; +if ( $opt_H ) { + $args_check_http .= " -H $opt_H"; +} +if ( $opt_I ) { + $args_check_http .= " -I $opt_I"; +} +if ( $opt_e ) { + $args_check_http .= " -e $opt_e"; +} +if ( $opt_s ) { + $args_check_http .= " -s $opt_s"; +} +if ( $opt_u ) { + $args_check_http .= " -u $opt_u"; +} +if ( $opt_p ) { + $args_check_http .= " -p $opt_p"; +} +if ( $opt_P ) { + $args_check_http .= " -P $opt_P"; +} +if ( $opt_I ) { + $args_check_http .= " -I $opt_I"; +} +if ( $opt_e ) { + $args_check_http .= " -e $opt_e"; +} +if ( $opt_w ) { + $args_check_http .= " -w $opt_w"; +} +if ( $opt_c ) { + $args_check_http .= " -c $opt_c"; +} +if ( $opt_t ) { + $args_check_http .= " -t $opt_t"; +} +if ( $opt_a ) { + $args_check_http .= " -a $opt_a"; +} +if ( $opt_L ) { + $args_check_http .= " -L $opt_L"; +} +if ( $opt_f ) { + $args_check_http .= " -f $opt_f"; +} +if ( $opt_l ) { + $args_check_http .= " -l $opt_l"; +} +if ( $opt_r ) { + $args_check_http .= " -r $opt_r"; +} +if ( $opt_R ) { + $args_check_http .= " -R $opt_R"; +} +if ( $opt_C ) { + $args_check_http .= " -C $opt_C"; +} +if ( $opt_z ) { + $args_check_http .= " --ssl"; +} + + +my $rrd = $pathtorrdbase.$ServiceId.".rrd"; + +my $start=time; +my $name = $0; +$name =~ s/\.pl.*//g; + +## +## RRDTools create rrd +## +if ($opt_g) { + if (! -e $rrd) { + create_rrd ($rrd,1,$start,$step,"U","U","GAUGE"); + } +} +## +## Plugin requests +## +# print "args: $args_check_http \n"; +my $result = `$pathtolibexechttp $args_check_http`; +my $return_code = $? / 256; + +$_ = $result; +m/time=\s*(\d*\.\d*)/; +my $time = $1; + +## +## RRDtools update +## +if ($opt_g && $time ) { + $start=time; + update_rrd ($rrd,$start,$time); +} + +print "$result"; +exit $return_code; + +## +## Plugin return code +## +sub print_usage () { + my $screen = `$pathtolibexechttp -h`; + $screen =~ s/check_http/check_graph_http/g; + $screen =~ s/-S/-Z/; + print $screen; +} + +sub print_help () { + print "Copyright (c) 2005 LINAGORA SA\n"; + print "Bugs to http://www.linagora.com/\n"; + print "\n"; + print_usage(); + print "\n"; +} diff --git a/centreon-plugins/src/check_graph_load_average.pl b/centreon-plugins/src/check_graph_load_average.pl new file mode 100644 index 000000000..a17014e29 --- /dev/null +++ b/centreon-plugins/src/check_graph_load_average.pl @@ -0,0 +1,185 @@ +#! /usr/bin/perl -w +# +# $Id: check_graph_load_average.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 - Romain Le Merlus +# +# 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 "@NAGIOS_PLUGINS@"; +use lib "/usr/local/nagios/libexec/"; +use utils qw($TIMEOUT %ERRORS &print_revision &support); + +if (eval "require oreon" ) { + use oreon qw(get_parameters create_rrd update_rrd &is_valid_serviceid); + use vars qw($VERSION %oreon); + %oreon=get_parameters(); +} else { + print "Unable to load oreon perl module\n"; + exit $ERRORS{'UNKNOWN'}; +} + +use vars qw($PROGNAME); +use Getopt::Long; +use vars qw($opt_V $opt_h $opt_g $opt_v $opt_C $opt_H $opt_D $opt_S $opt_step $step $snmp $opt_f); + + +## +## Plugin var init +## +my($return_code); + +my $pathtorrdbase = $oreon{GLOBAL}{DIR_RRDTOOL}; + +$PROGNAME = "check_graph_load_average"; +sub print_help (); +sub print_usage (); + +Getopt::Long::Configure('bundling'); +GetOptions + ("h" => \$opt_h, "help" => \$opt_h, + "V" => \$opt_V, "version" => \$opt_V, + "g" => \$opt_g, "rrdgraph" => \$opt_g, + "rrd_step=s" => \$opt_step, + "v=s" => \$opt_v, "snmp=s" => \$opt_v, + "C=s" => \$opt_C, "community=s" => \$opt_C, + "S=s" => \$opt_S, "ServiceId=s" => \$opt_S, + "H=s" => \$opt_H, "hostname=s" => \$opt_H, + "f" => \$opt_f); + +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_S) || ($opt_S = shift) || ($opt_S = "1_1"); +my $ServiceId = is_valid_serviceid($opt_S); + +($opt_v) || ($opt_v = shift) || ($opt_v = "2"); +$snmp = $1 if ($opt_v =~ /(\d)/); + +($opt_C) || ($opt_C = shift) || ($opt_C = "public"); + +($opt_step) || ($opt_step = shift) || ($opt_step = "300"); +$step = $1 if ($opt_step =~ /(\d+)/); + +my $rrd = $pathtorrdbase.$ServiceId.".rrd"; + +my $start=time; +my $name = $0; +$name =~ s/\.pl.*//g; + +## +## RRDTools create rrd +## +if ($opt_g) { + if (! -e $rrd) { + create_rrd ($rrd,3,$start,$step,"U","U","GAUGE"); + } +} + +## +## Plugin snmp requests +## +$return_code = 0; + +my $OID_CPULOAD_1 =$oreon{UNIX}{CPU_LOAD_1M}; +my $OID_CPULOAD_5 =$oreon{UNIX}{CPU_LOAD_5M}; +my $OID_CPULOAD_15 =$oreon{UNIX}{CPU_LOAD_15M}; + +my ( $session, $error ) = Net::SNMP->session(-hostname => $opt_H,-community => $opt_C, -version => $snmp); +if ( !defined($session) ) { + print("UNKNOWN: $error"); + 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}; + +## +## RRDtools update +## +if ($opt_g && ( $return_code == 0) ) { + $start=time; + update_rrd ($rrd,$start,$un,$cinq,$quinze); +} + +## +## Plugin return code +## + +my $PERFPARSE = ""; + +if ($return_code == 0){ + if ($opt_f){ + $PERFPARSE = "|load1=".$un."%;;;0;100 load5=".$cinq."%;;;0;100 load15=".$quinze."%;;;0;100"; + } + print "load average: $un, $cinq, $quinze".$PERFPARSE."\n"; + exit $ERRORS{'OK'}; +} else { + print "Load Average CRITICAL\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 " -g (--rrdgraph) create à rrd base and add datas into this one\n"; + print " --rrd_step Specifies the base interval in seconds with which data will be fed into the RRD (300 by default)\n"; + print " -D (--directory) Path to rrdatabase (or create the .rrd in this directory)\n"; + print " by default: ".$pathtorrdbase."\n"; + print " (The path is valid with spaces '/my\ path/...')\n"; + print " -S (--ServiceId) Oreon Service Id\n"; + print " -V (--version) Plugin version\n"; + print " -h (--help) usage help\n"; + print " -f Perfparse Compatible\n"; +} + +sub print_help () { + print "Copyright (c) 2004-2005 OREON\n"; + print "Bugs to http://bugs.oreon-project.org/\n"; + print "\n"; + print_usage(); + print "\n"; +} diff --git a/centreon-plugins/src/check_graph_nt.pl b/centreon-plugins/src/check_graph_nt.pl new file mode 100644 index 000000000..8de220040 --- /dev/null +++ b/centreon-plugins/src/check_graph_nt.pl @@ -0,0 +1,404 @@ +#! /usr/bin/perl -w +# +# $Id: check_graph_nt.pl,v 1.3 2005/08/01 18:04:00 gollum123 Exp $ +# +# Oreon's plugins are developped with GPL Licence : +# http://www.fsf.org/licenses/gpl.txt +# Developped by : Julien Mathis - Mathieu Mettre +# Under control of Flavien Astraud, Jerome Landrieu for Epitech. +# Oreon's plugins are developped in partnership with Linagora company. +# +# 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 FindBin; +use lib "$FindBin::Bin"; +use lib "@NAGIOS_PLUGINS@"; +use utils qw($TIMEOUT %ERRORS &print_revision &support); + + +if (eval "require oreon" ) { + use oreon qw(get_parameters create_rrd update_rrd &is_valid_serviceid); + use vars qw($VERSION %oreon); + %oreon=get_parameters(); +} else { + print "Unable to load oreon perl module\n"; + exit $ERRORS{'UNKNOWN'}; +} + +use vars qw($PROGNAME); +use Getopt::Long; +use vars qw($opt_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 $pathtorrdbase = $oreon{GLOBAL}{DIR_RRDTOOL}; +my $pathtolibexecnt = $oreon{GLOBAL}{NAGIOS_LIBEXEC}."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 = "check_graph_nt"; +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, + "g" => \$opt_g, "rrdgraph" => \$opt_g, + "rrd_step=s" => \$opt_step, + "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_s) { + ($opt_s) || ($opt_s = shift); + $op_s = $1 if ($opt_s =~ /([-.,A-Za-z0-9]+)/); +} + +if ($opt_d) { + ($opt_d) || ($opt_d = shift); + $op_d = $1 if ($opt_d =~ /([-.,A-Za-z0-9]+)/); +} + +if ($opt_v) { + ($opt_v) || ($opt_v = shift); + $op_v = $1 if ($opt_v =~ /([-.,A-Za-z0-9]+)/); +} + +($opt_step) || ($opt_step = shift) || ($opt_step = 300); +$step = $1 if ($opt_step =~ /(\d+)/); + +($opt_S) || ($opt_S = shift) || ($opt_S = "1_1"); +my $ServiceId = is_valid_serviceid($opt_S); + +## +## RRDTool var init +## + +my $rrd = $pathtorrdbase.$ServiceId.".rrd"; +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 2>/dev/null`; + my $return = $_; + $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; + if ($opt_g) { + unless (-e $rrd) { + create_rrd ($rrd,$#values +1,$start,$step,"U","U","GAUGE"); + } + update_rrd ($rrd,$start,@values); + } + ## Print Plugins Output + $return =~ s/\n/ /g; + if (@values){ + if (defined($opt_c) && defined($opt_w)){ + print $return . "|cpu=@values;$opt_w;$opt_c\n"; + } else { + print $return . "|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'}; + } + if ($opt_g) { + if (! -e $rrd) { + create_rrd ($rrd,1,$start,$step,"U","U","GAUGE"); + } else { + update_rrd ($rrd,$start,$uptime); + } + } + $_ =~ 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]; + if ($opt_g) { + unless (-e $rrd) { + create_rrd ($rrd,3,$start,$step,"U","U","GAUGE"); + } + if (defined($test[3]) && defined($test[7]) && defined($test[12])){ + $test[3] =~ s/,/\./ ; + $test[7] =~ s/,/\./ ; + $test[12] =~ s/,/\./ ; + update_rrd ($rrd,$start,$test[3],$test[7],$test[12]); + } + } + ## Print Plugins Output + $return =~ s/\n/ /g; + $return =~ s/%/ pct/g; + if (defined($test[3]) && defined($test[7]) && defined($test[12])){ + print $return . "|total=".$test[3]."Mo used=".$test[7]."Mo free=".$test[12]."Mo\n"; + } else { + print $return . "\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]; + if ($opt_g) { + unless (-e $rrd) { + create_rrd ($rrd,3,$start,$step,"U","U","GAUGE"); + } + if (defined($test4[1]) && defined($test[6]) && defined($test[11])){ + # Replace , by . to convert in real float number (for rrdtool) + $test4[1] =~ s/,/\./ ; + $test[6] =~ s/,/\./ ; + $test[11] =~ s/,/\./ ; + update_rrd ($rrd,$start,$test4[1],$test[6],$test[11]); + } + } + ## Print Plugins Output + $return =~ s/\n/ /g; + $return =~ s/%/ pct/g; + if ($test4[1] && $test[6] && $test[11]){ + print $return . "|total=".$test4[1]." used=".$test[6]." free=".$test[11]."\n"; + } else { + print $return . "\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 = "Unknow"; + } + 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'}; + } + } + if ($opt_g) { + if (! -e $rrd) { + create_rrd ($rrd,1,$start,$step,"U","U","GAUGE"); + } else { + update_rrd ($rrd,$start,$etat); + } + } + $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; + if ($opt_g) { + unless (-e $rrd) { + create_rrd ($rrd,$#values +1,$start,$step,"U","U","GAUGE"); + } + update_rrd ($rrd,$start,@values); + } + ## Print Plugins Output + $return =~ s/\n/ /g; + $return =~ s/%/ pct/g; + 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"; + print " -g (--rrdgraph) create à rrd base and add datas into this one\n"; + print " --rrd_step Specifies the base interval in seconds with which data will be fed into the RRD (300 by default)\n"; + print " -D (--directory) Path to rrdatabase (or create the .rrd in this directory)\n"; + print " by default: ".$pathtorrdbase."\n"; + print " (The path is valid with spaces '/my\ path/...')\n"; + print " -S (--ServiceId) Oreon Service Id\n"; +} + +sub print_help () { + print "Copyright (c) 2004 OREON\n"; + print "Bugs to http://www.oreon.org/\n"; + print "\n"; + print_usage(); + print "\n"; +} diff --git a/centreon-plugins/src/check_graph_ping.pl b/centreon-plugins/src/check_graph_ping.pl new file mode 100644 index 000000000..a6c0d9b2d --- /dev/null +++ b/centreon-plugins/src/check_graph_ping.pl @@ -0,0 +1,215 @@ +#! /usr/bin/perl -w +# +# $Id: check_graph_ping.pl,v 1.2 2006/04/28 10:21:49 Julien Mathis $ +# +# Oreon's plugins are developped with GPL Licence : +# http://www.fsf.org/licenses/gpl.txt +# Developped by : Julien Mathis - Mathieu Mettre - Romain Le Merlus +# +# Modified for Oreon Project by : Mathieu Chateau - Christophe Coraboeuf +# Modified By Julien Mathis For Merethis Company +# +# 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 FindBin; +use lib "$FindBin::Bin"; +use lib "@NAGIOS_PLUGINS@"; +use utils qw($TIMEOUT %ERRORS &print_revision &support); + +if (eval "require oreon" ) { + use oreon qw(get_parameters create_rrd update_rrd &is_valid_serviceid); + use vars qw($VERSION %oreon); + %oreon=get_parameters(); +} else { + print "Unable to load oreon perl module\n"; + exit $ERRORS{'UNKNOWN'}; +} + +use vars qw($PROGNAME); +use Getopt::Long; +use vars qw($opt_V $opt_h $opt_g $opt_H $opt_D $opt_w $opt_c $opt_n $opt_f $opt_S $rta_critical $rta_warning $pl_critical $pl_warning $opt_s $opt_step $step ); + +# +# Plugin var init +# + +my $pathtorrdbase = $oreon{GLOBAL}{DIR_RRDTOOL}; + +my $ping = `whereis -b ping`; +$ping =~ /^.*:\s(.*)$/; +$ping = $1; + +$PROGNAME = "check_graph_ping"; +sub print_help (); +sub print_usage (); + +Getopt::Long::Configure('bundling'); +GetOptions + ("h" => \$opt_h, "help" => \$opt_h, + "V" => \$opt_V, "version" => \$opt_V, + "rrd_step=s" => \$opt_step,"f" => \$opt_f, + "g" => \$opt_g, "rrdgraph" => \$opt_g, + "w=s" => \$opt_w, "warning=s" => \$opt_w, + "c=s" => \$opt_c, "critical=s" => \$opt_c, + "n=s" => \$opt_n, "number=s" => \$opt_n, + "S=s" => \$opt_S, "ServiceId=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_c) || ($opt_c = shift) || ($opt_c = "500,40%"); +if ($opt_c =~ /([0-9]+),([0-9]+)%/) { + $rta_critical = $1; + $pl_critical = $2; +} + +($opt_w) || ($opt_w = shift) || ($opt_w = "200,20%"); +if ($opt_w =~ /([0-9]+),([0-9]+)%/) { + $rta_warning = $1; + $pl_warning = $2; +} + +if ( ($rta_critical <= $rta_warning) || ($pl_critical <= $pl_warning) ) { + print "critical must be superior to warning\n"; + print_usage(); + exit $ERRORS{'OK'}; +} + +($opt_n) || ($opt_n = shift) || ($opt_n = 1); +my $NbPing; +if ($opt_n =~ /([0-9]+)/){ + $NbPing = $1; +} else{ + print "Unknown ping number\n"; + exit $ERRORS{'UNKNOWN'}; +} + +($opt_S) || ($opt_S = shift) || ($opt_S = 1); +my $rrd = $pathtorrdbase.is_valid_serviceid($opt_S).".rrd"; + + +($opt_step) || ($opt_step = shift) || ($opt_step = "300"); +$step = $1 if ($opt_step =~ /(\d+)/); + + +my $start=time; + +# +# RRDTools create rrd +# + +if ($opt_g) { + create_rrd($rrd,1,$start,$step,0,"U","GAUGE") if (! -e $rrd);} + +# +# Plugin requests +# + +$_ = `$ping -n -c $NbPing $opt_H 2>/dev/null`; +my $return = $? / 256; + +# +# Get Data From Ping Result +# + +my $ping_result = $_; +my @ping_result_array = split(/\n/,$ping_result); +my @ping_subresult1_array; +my @ping_subresult2_array; +my $rta = 0; +my $pl; +my $time_answer; + +if( ( $return != 0 ) || $ping_result_array[@ping_result_array -2 ] =~ /100% packet loss/) { + $rta = -1; + $time_answer = 0; +} else { + @ping_subresult1_array = split(/=/,$ping_result_array[@ping_result_array -1 ]); + @ping_subresult2_array = split(/,/,$ping_result_array[@ping_result_array -2 ]); + @ping_subresult1_array = split(/\//,$ping_subresult1_array[1]); + @ping_subresult2_array = split(/ /,$ping_subresult2_array[2]); + $rta = $ping_subresult1_array[1]; + $pl = $ping_subresult2_array[1]; + $time_answer = $ping_subresult1_array[1]; + $pl =~ /([0-9]+)\%/; + $pl = $1; +} + +# +# Update RRDTool Database. +# + +update_rrd($rrd,$start,$rta) if ($opt_g); + +# +# Plugin return code +# + +my $result_str = ""; + +if( $rta == -1 ) { + $ping_result_array[@ping_result_array -2 ] =~ s/\%/percent/g; + print "GPING CRITICAL - ".$ping_result_array[@ping_result_array -2 ]."|time=0 ok=0\n"; + exit $ERRORS{'CRITICAL'}; +} elsif ( ($pl >= $pl_critical) || ($rta >= $rta_critical) ) { + $ping_result_array[@ping_result_array -1 ] =~ s/\%/percent/g; + my @tab = split(/,/,$ping_result_array[@ping_result_array -1 ]); + print "GPING CRITICAL - ". $tab[1] ."|time=".$time_answer."ms;$pl_warning;$pl_critical;; ok=1\n"; + exit $ERRORS{'CRITICAL'}; +} elsif ( ($pl >= $pl_warning) || ($rta >= $rta_warning) ) { + $ping_result_array[@ping_result_array -1 ] =~ s/\%/percent/g; + my @tab = split(/,/,$ping_result_array[@ping_result_array -1 ]); + print "GPING WARNING - ".$tab[0]."|time=".$time_answer."ms;$pl_warning;$pl_critical;; ok=1\n"; + exit $ERRORS{'WARNING'}; +} else { + $ping_result_array[@ping_result_array -1 ] =~ s/\%/percent/g; + my @tab = split(/,/,$ping_result_array[@ping_result_array -1 ]); + print "GPING OK - ".$tab[0]."|time=".$time_answer."ms;$pl_warning;$pl_critical;; ok=1\n"; + exit $ERRORS{'OK'}; +} + +sub print_usage () { + print "Usage:\n"; + print "$PROGNAME\n"; + print " -H (--hostname) Hostname to query (Required)\n"; + print " -g (--rrdgraph) Create a rrd base if necessary and add datas into this one\n"; + print " --rrd_step Specifies the base interval in seconds with which data will be fed into the RRD (300 by default)\n"; + print " -S (--ServiceId) Oreon Service Id\n"; + print " -w (--warning) Threshold pair (Default: 200,20%)\n"; + print " -c (--critical) Threshold pair (Default: 500,40%)\n"; + print " -n (--number) number of ICMP ECHO packets to send (Default: 1)\n"; + print " -V (--version) Plugin version\n"; + print " -h (--help) usage help\n"; +} + +sub print_help () { + print "######################################################\n"; + print "# Copyright (c) 2004-2006 Oreon-project #\n"; + print "# Bugs to http://www.oreon-project.org/ #\n"; + print "######################################################\n"; + print_usage(); + print "\n"; +} diff --git a/centreon-plugins/src/check_graph_process.pl b/centreon-plugins/src/check_graph_process.pl new file mode 100644 index 000000000..cc65ea000 --- /dev/null +++ b/centreon-plugins/src/check_graph_process.pl @@ -0,0 +1,232 @@ +#! /usr/bin/perl -w +# +# $Id: check_graph_process.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 +# +# 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 oid_lex_sort); +use FindBin; +use lib "$FindBin::Bin"; +use lib "@NAGIOS_PLUGINS@"; +use utils qw($TIMEOUT %ERRORS &print_revision &support); + +if (eval "require oreon" ) { + use oreon qw(get_parameters create_rrd update_rrd &is_valid_serviceid); + use vars qw($VERSION %oreon); + %oreon=get_parameters(); +} else { + print "Unable to load oreon perl module\n"; + exit $ERRORS{'UNKNOWN'}; +} + +use vars qw($PROGNAME); +use Getopt::Long; +use vars qw($opt_V $opt_h $opt_g $opt_v $opt_C $opt_p $opt_H $opt_D $opt_n $opt_S $opt_step $step $result @result %process_list %STATUS $opt_f); +my $pathtorrdbase = $oreon{GLOBAL}{DIR_RRDTOOL}; + +## +## Plugin var init +## + +my($proc, $proc_run); + +$PROGNAME = "check_graph_process"; +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, + "V" => \$opt_V, "version" => \$opt_V, + "g" => \$opt_g, "rrdgraph" => \$opt_g, + "rrd_step=s" => \$opt_step, "f" => \$opt_f, + "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, + "S=s" => \$opt_S, "ServiceId=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 = "1"); +my $snmp = $1 if ($opt_v =~ /(\d)/); + +($opt_S) || ($opt_S = shift) || ($opt_S = 1); +my $ServiceId = is_valid_serviceid($opt_S); + +($opt_C) || ($opt_C = shift) || ($opt_C = "public"); + +my $process = ""; +if ($opt_p){ + $process = $1 if ($opt_p =~ /([-.A-Za-z0-9]+)/); +} + +($opt_step) || ($opt_step = shift) || ($opt_step = "300"); +$step = $1 if ($opt_step =~ /(\d+)/); + + +my $rrd = $pathtorrdbase.$ServiceId.".rrd"; +my $start=time; +my $name = $0; +$name =~ s/\.pl.*//g; + +## +## RRDTools create rrd +## + +if ( $opt_g && $opt_n && (! -e $rrd)) { + create_rrd ($rrd,1,$start,$step,"U","U","GAUGE"); +} + +## +## Plugin snmp requests +## +my $OID_SW_RunName = $oreon{MIB2}{SW_RUNNAME}; +my $OID_SW_RunIndex =$oreon{MIB2}{SW_RUNINDEX}; +my $OID_SW_RunStatus =$oreon{MIB2}{SW_RUNSTATUS}; + +my ( $session, $error ) = Net::SNMP->session(-hostname => $opt_H,-community => $opt_C, -version => $snmp); +if ( !defined($session) ) { + print("UNKNOWN: $error"); + 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 ""){ + if ($$result{$key} eq $opt_p){ + $proc++; + } + } 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} }; + print $proc_run; + } +} + +## +## RRDtools update +## + +if ( $opt_g && $opt_n) { + $start=time; + my $totrrd; + if ($opt_n){$totrrd = $proc;} + else{ + if ( ($proc_run == "3") || ($proc_run == "4") ){$totrrd = 0;} + else{$totrrd = 1;} + } + update_rrd ($rrd,$start,$totrrd); +} + +## +## Plugin return code +## + +my $PERFPARSE = ""; + +if ($opt_n){ + if ($opt_f){ + $PERFPARSE = "|nbproc=$proc"; + } + print "Processes OK - Number of current processes: $proc".$PERFPARSE."\n"; + exit $ERRORS{'OK'}; +} else { + if ($proc_run){ + if ($opt_f){ + $PERFPARSE = "|procstatus=$proc_run"; + } + print "Process OK - $process: $STATUS{$proc_run}".$PERFPARSE."\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 " -g (--rrdgraph) create à rrd base and add datas into this one\n"; + print " --rrd_step Specifies the base interval in seconds with which data will be fed into the RRD (300 by default)\n"; + print " -D (--directory) Path to rrdatabase (or create the .rrd in this directory)\n"; + print " by default: ".$pathtorrdbase."\n"; + print " (The path is valid with spaces '/my\ path/...')\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 " -S (--ServiceId) Oreon Service Id\n"; + print " -V (--version) Plugin version\n"; + print " -h (--help) usage help\n"; + print " -f Perfparse Compatible\n"; +} + + +sub print_help () { + print "##########################################\n"; + print "# Copyright (c) 2004-2006 Oreon #\n"; + print "# Bugs to http://www.oreon-project.org/ #\n"; + print "##########################################\n"; + print_usage(); + print "\n"; +} + diff --git a/centreon-plugins/src/check_graph_remote_storage.pl b/centreon-plugins/src/check_graph_remote_storage.pl new file mode 100644 index 000000000..5fbabd930 --- /dev/null +++ b/centreon-plugins/src/check_graph_remote_storage.pl @@ -0,0 +1,333 @@ +#! /usr/bin/perl -w +# +# $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 "/srv/nagios/libexec"; +#use lib "/usr/lib/nagios/plugins/"; +use utils qw($TIMEOUT %ERRORS &print_revision &support); + +if (eval "require oreon" ) { + use oreon qw(get_parameters create_rrd update_rrd &is_valid_serviceid); + use vars qw($VERSION %oreon); + %oreon=get_parameters(); +} else { + print "Unable to load oreon perl module\n"; + exit $ERRORS{'UNKNOWN'}; +} + +use vars qw($PROGNAME); +use Getopt::Long; +use vars qw($opt_V $opt_h $opt_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); +my $pathtorrdbase = $oreon{GLOBAL}{DIR_RRDTOOL}; + +## +## 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, + "s" => \$opt_s, "show" => \$opt_s, + "g" => \$opt_g, "rrdgraph" => \$opt_g, + "rrd_step=s" => \$opt_step, "f" => \$opt_f, + "v=s" => \$opt_v, "snmp=s" => \$opt_v, + "C=s" => \$opt_C, "community=s" => \$opt_C, + "d=s" => \$opt_d, "disk=s" => \$opt_d, + "n" => \$opt_n, "name" => \$opt_n, + "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_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); + +if ($opt_n && !$opt_d) { + print "Option -n (--name) need option -d (--disk)\n"; + exit $ERRORS{'UNKNOWN'}; +} + +($opt_v) || ($opt_v = shift) || ($opt_v = "2"); +my $snmp = $1 if ($opt_v =~ /(\d)/); + +($opt_C) || ($opt_C = shift) || ($opt_C = "public"); + +($opt_d) || ($opt_d = shift) || ($opt_d = 2); + +my $partition = 0; +if ($opt_d =~ /([0-9]+)/ && !$opt_n){ + $partition = $1; +} +elsif (!$opt_n){ + print "Unknown -d number expected... or it doesn't exist, try another disk - number\n"; + exit $ERRORS{'UNKNOWN'}; +} + +($opt_S) || ($opt_S = shift) || ($opt_S = "1_1"); +my $ServiceId = is_valid_serviceid($opt_S); + +($opt_c) || ($opt_c = shift) || ($opt_c = 95); +my $critical = $1 if ($opt_c =~ /([0-9]+)/); + +($opt_w) || ($opt_w = shift) || ($opt_w = 80); +my $warning = $1 if ($opt_w =~ /([0-9]+)/); +if ($critical <= $warning){ + print "(--crit) must be superior to (--warn)"; + print_usage(); + exit $ERRORS{'OK'}; +} + +($opt_step) || ($opt_step = shift) || ($opt_step = "300"); +$step = $1 if ($opt_step =~ /(\d+)/); + +my $rrd = $pathtorrdbase.$ServiceId.".rrd"; +my $start=time; +my $name = $0; +$name =~ s/\.pl.*//g; + +## +## RRDTools create rrd +## +if ($opt_g) { + if (! -e $rrd) { + create_rrd ($rrd,2,$start,$step,"U","U","GAUGE"); + } +} + +## +## Plugin snmp requests +## + + +my $OID_hrStorageDescr =$oreon{MIB2}{HR_STORAGE_DESCR}; +my $OID_hrStorageAllocationUnits =$oreon{MIB2}{HR_STORAGE_ALLOCATION_UNITS}; +my $OID_hrStorageSize =$oreon{MIB2}{HR_STORAGE_SIZE}; +my $OID_hrStorageUsed =$oreon{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'}; +} + +#getting partition using its name instead of its oid index +if ($opt_n) { + my $result = $session->get_table(Baseoid => $OID_hrStorageDescr); + if (!defined($result)) { + printf("ERROR: hrStorageDescr Table : %s.\n", $session->error); + $session->close; + exit $ERRORS{'UNKNOWN'}; + } + my $expr = ""; + if ($opt_d =~ m/^[A-Za-z]:/) { + $opt_d =~ s/\\/\\\\/g; + $expr = "^$opt_d"; + }elsif ($opt_d =~ m/^\//) { + $expr = "$opt_d\$"; + }else { + $expr = "$opt_d"; + } + foreach my $key ( oid_lex_sort(keys %$result)) { + if ($result->{$key} =~ m/$expr/) { + my @oid_list = split (/\./,$key); + $partition = pop (@oid_list) ; + } + } +} +if ($opt_s) { + # Get description table + my $result = $session->get_table( + Baseoid => $OID_hrStorageDescr + ); + + if (!defined($result)) { + printf("ERROR: hrStorageDescr Table : %s.\n", $session->error); + $session->close; + exit $ERRORS{'UNKNOWN'}; + } + + foreach my $key ( oid_lex_sort(keys %$result)) { + my @oid_list = split (/\./,$key); + my $index = pop (@oid_list) ; + print "hrStorage $index :: $$result{$key}\n"; + } +exit $ERRORS{'OK'}; +} + +my $result = $session->get_request( + -varbindlist => [$OID_hrStorageDescr.".".$partition , + $OID_hrStorageAllocationUnits.".".$partition , + $OID_hrStorageSize.".".$partition, + $OID_hrStorageUsed.".".$partition + ] + ); +if (!defined($result)) { + printf("ERROR: %s", $session->error); + if ($opt_n) { print(" - You must specify the disk name when option -n is used");} + print ".\n"; + $session->close; + exit $ERRORS{'UNKNOWN'}; +} +$hrStorageDescr = $result->{$OID_hrStorageDescr.".".$partition }; +$AllocationUnits = $result->{$OID_hrStorageAllocationUnits.".".$partition }; +$Size = $result->{$OID_hrStorageSize.".".$partition }; +$Used = $result->{$OID_hrStorageUsed.".".$partition }; + + +## +## Plugins var treatment +## +if (!$Size){ + print "Disk CRITICAL - no output (-p number expected... it doesn't exist, try another disk - number\n"; + exit $ERRORS{'CRITICAL'}; +} +if (($Size =~ /([0-9]+)/) && ($AllocationUnits =~ /([0-9]+)/)){ + if (!$Size){ + print "The number of the option -p is not a hard drive\n"; + exit $ERRORS{'CRITICAL'}; + } + $tot = 1; + $tot = $Size * $AllocationUnits; + if (!$tot){$tot = 1;} + $used = $Used * $AllocationUnits; + $pourcent = ($used * 100) / $tot; + + if (length($pourcent) > 2){ + @test = split (/\./, $pourcent); + $pourcent = $test[0]; + } + $tot = $tot / 1073741824; + $Used = ($Used * $AllocationUnits) / 1073741824; + + ## + ## RRDtools update + ## + + $start=time; + my $totrrd = $tot * 1073741824; + + if ($opt_g) { + update_rrd ($rrd,$start,$totrrd,$used); + } + + ## + ## Plugin return code + ## + if ($pourcent >= $critical){ + print "Disk CRITICAL - "; + $return_code = 2; + } elsif ($pourcent >= $warning){ + print "Disk WARNING - "; + $return_code = 1; + } else { + print "Disk OK - "; + $return_code = 0; + } + + if ($hrStorageDescr){ + print $hrStorageDescr . " TOTAL: "; + printf("%.3f", $tot); + print " Go USED: " . $pourcent . "% : "; + printf("%.3f", $Used); + print " Go"; + if ($opt_f){ + my $size_o = $Used * 1073741824; + my $warn = $opt_w * $size_o; + my $crit = $opt_c * $size_o; + print "|size=".$totrrd."o used=".$size_o.";".$warn.";".$crit; + } + print "\n"; + exit $return_code; + } else { + print "TOTAL: "; + printf("%.3f", $tot); + print " Go USED: " . $pourcent . "% : "; + printf("%.3f", $Used); + print " Go\n"; + exit $return_code; + } +} else { + print "Disk CRITICAL - no output (-d number expected... it doesn't exist, try another disk - number\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 " -d (--disk) Set the disk (number expected) ex: 1, 2,... (defaults to 2 )\n"; + print " -n (--name) Allows to use disk name with option -d instead of disk oid index\n"; + print " (ex: -d \"C:\" -n, -d \"E:\" -n, -d \"Swap Memory\" -n, -d \"Real Memory\" -n\n"; + print " (choose an unique expression for each disk)\n"; + print " -s (--show) Describes all disk (debug mode)\n"; + print " -g (--rrdgraph) create a rrd base and add datas into this one\n"; + print " --rrd_step Specifies the base interval in seconds with which data will be fed into the RRD (300 by default)\n"; + print " -D (--directory) Path to rrdatabase (or create the .rrd in this directory)\n"; + print " by default: ".$pathtorrdbase."\n"; + print " (The path is valid with spaces '/my\ path/...')\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 " -f Perfparse Compatible\n"; + print " -S (--ServiceId) Oreon Service Id\n"; + print " -V (--version) Plugin version\n"; + print " -h (--help) usage help\n"; + +} + +sub print_help () { + print "##########################################\n"; + print "# Copyright (c) 2004-2006 Oreon #\n"; + print "# Bugs to http://www.oreon-project.org/ #\n"; + print "##########################################\n"; + print_usage(); + print "\n"; + } diff --git a/centreon-plugins/src/check_graph_snmp_value.pl b/centreon-plugins/src/check_graph_snmp_value.pl new file mode 100644 index 000000000..b46c801cf --- /dev/null +++ b/centreon-plugins/src/check_graph_snmp_value.pl @@ -0,0 +1,195 @@ +#! /usr/bin/perl -w +# +# $Id: check_snmp_value.pl,v 1.2 2005/11/17 10:21:49 Julien Mathis $ +# +# This plugin is developped under GPL Licence: +# http://www.fsf.org/licenses/gpl.txt +# +# Developped by Merethis SARL : http://www.merethis.com +# +# The Software is provided to you AS IS and WITH ALL FAULTS. +# MERETHIS 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 LINAGORA web site. +# In no event will MERETHIS be liable for any direct, indirect, punitive, special, +# incidental or consequential damages however they may arise and even if MERETHIS 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 "@NAGIOS_PLUGINS@"; +use utils qw($TIMEOUT %ERRORS &print_revision &support); + +if (eval "require oreon" ) { + use oreon qw(get_parameters create_rrd update_rrd &is_valid_serviceid); + use vars qw($VERSION %oreon); + %oreon=get_parameters(); +} else { + print "Unable to load oreon perl module\n"; + exit $ERRORS{'UNKNOWN'}; +} + +use vars qw($PROGNAME); +use Getopt::Long; +use vars qw($opt_h $opt_V $opt_g $opt_D $opt_S $opt_H $opt_C $opt_v $opt_o $opt_c $opt_w $opt_f $opt_t); +use vars qw($ServiceId $rrd $snmp $DS_type); +my $pathtorrdbase = $oreon{GLOBAL}{DIR_RRDTOOL}; + +$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, + "g" => \$opt_g, "rrdgraph" => \$opt_g, + "f" => \$opt_f, + "v=s" => \$opt_v, "snmp=s" => \$opt_v, + "C=s" => \$opt_C, "community=s" => \$opt_C, + "S=s" => \$opt_S, "ServiceId=s" => \$opt_S, + "o=s" => \$opt_o, "oid=s" => \$opt_o, + "t=s" => \$opt_t, "type=s" => \$opt_t, + "w=s" => \$opt_w, "warning=s" => \$opt_w, + "c=s" => \$opt_c, "critical=s" => \$opt_c, + "H=s" => \$opt_H, "hostname=s" => \$opt_H); + +if ($opt_V) { + print_revision($PROGNAME,'$Revision: 1.0'); + exit $ERRORS{'OK'}; +} + +if ($opt_h) { + print_help(); + exit $ERRORS{'OK'}; +} + +$opt_H = shift unless ($opt_H); +(print_usage() && exit $ERRORS{'OK'}) unless ($opt_H); + +($opt_v) || ($opt_v = shift) || ($opt_v = "1"); +my $snmp = $1 if ($opt_v =~ /(\d)/); + +($opt_S) || ($opt_S = shift) || ($opt_S = "1_1"); +my $ServiceId = is_valid_serviceid($opt_S); + +($opt_C) || ($opt_C = shift) || ($opt_C = "public"); +my $rrd = $pathtorrdbase.$ServiceId.".rrd"; + +($opt_t) || ($opt_t = shift) || ($opt_t = "GAUGE"); +my $DS_type = $1 if ($opt_t =~ /(GAUGE)/ || $opt_t =~ /(COUNTER)/); + +($opt_c) || ($opt_c = shift); +my $critical = $1 if ($opt_c =~ /([0-9]+)/); + +($opt_w) || ($opt_w = shift); +my $warning = $1 if ($opt_w =~ /([0-9]+)/); +if ($critical <= $warning){ + print "(--critical) must be superior to (--warning)"; + print_usage(); + exit $ERRORS{'OK'}; +} + + + +my $start=time; +my $name = $0; +$name =~ s/\.pl.*//g; +my $day = 0; + + +#=== RRDTools create rrd ==== + + +if ($opt_g) { + if (! -e $rrd) { + create_rrd($rrd,1,$start,300,"U","U",$DS_type); + } +} + +#=== create a SNMP session ==== + +my ($session, $error) = Net::SNMP->session(-hostname => $opt_H,-community => $opt_C, -version => $snmp); +if (!defined($session)) { + print("CRITICAL: $error"); + exit $ERRORS{'CRITICAL'}; +} + +my $result = $session->get_request(-varbindlist => [$opt_o]); +if (!defined($result)) { + printf("UNKNOWN: %s.\n", $session->error); + $session->close; + exit $ERRORS{'UNKNOWN'}; +} + +my $return_result = $result->{$opt_o}; + +#=== RRDtools update ==== + +if ($opt_g) { + $start=time; + update_rrd($rrd,$start,$return_result); +} + +#=== Plugin return code ==== +if (defined($return_result)){ + if ($opt_w && $opt_c && $return_result < $opt_w){ + print "Ok value : " . $return_result; + if ($opt_f){ print "|value=".$return_result.";".$opt_w.";".$opt_c.";;";} + print "\n"; + exit $ERRORS{'OK'}; + } elsif ($opt_w && $opt_c && $return_result >= $opt_w && $return_result < $opt_c){ + print "Warning value : " . $return_result; + if ($opt_f){ print "|value=$return_result;".$opt_w.";".$opt_c.";;";} + print "\n"; + exit $ERRORS{'WARNING'}; + } elsif ($opt_w && $opt_c && $return_result >= $opt_c){ + print "Critical value : " . $return_result; + if ($opt_f){ print "|value=".$return_result.";".$opt_w.";".$opt_c.";;";} + print "\n"; + exit $ERRORS{'CRITICAL'}; + } +} else { + print "CRITICAL Host unavailable\n"; + exit $ERRORS{'CRITICAL'}; +} + + +sub print_usage () { + print "\nUsage:\n"; + print "$PROGNAME\n"; + print " -H (--hostname) Hostname to query - (required)\n"; + print " -C (--community) SNMP read community (defaults to public,\n"; + print " used with SNMP v1 and v2c\n"; + print " -v (--snmp_version) 1 for SNMP v1 (default)\n"; + print " 2 for SNMP v2c\n"; + print " -t (--type) Data Source Type (GAUGE or COUNTER) (GAUGE by default)\n"; + print " -g (--rrdgraph) create a rrd base and add datas into this one\n"; + print " -D (--directory) Path to rrdatabase (or create the .rrd in this directory)\n"; + print " by default: ".$pathtorrdbase."\n"; + print " (The path is valid with spaces '/my\ path/...')\n"; + print " -S (--ServiceId) Oreon Service Id\n"; + print " -o (--oid) OID to check\n"; + print " -w (--warning) Warning level\n"; + print " -c (--critical) Critical level\n"; + print " -V (--version) Plugin version\n"; + print " -h (--help) usage help\n"; + print " -f Perfparse Compatible\n"; +} + +sub print_help () { + print "#=========================================\n"; + print "# Copyright (c) 2005 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/centreon-plugins/src/check_graph_tcp.pl b/centreon-plugins/src/check_graph_tcp.pl new file mode 100644 index 000000000..9a9d60d2c --- /dev/null +++ b/centreon-plugins/src/check_graph_tcp.pl @@ -0,0 +1,135 @@ +#! /usr/bin/perl -w +# $Id: check_graph_tcp.pl,v 1.2 2005/08/01 17:50:50 gollum123 Exp $ +# +# Oreon's plugins are developped with GPL Licence : +# http://www.fsf.org/licenses/gpl.txt +# Developped by : Julien Mathis - Romain Le Merlus +# +# Modified for Oreon Project by : Mathieu Chateau - Christophe Coraboeuf +# Modified By Julien Mathis For Merethis Company +# +# 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. + +use strict; +use FindBin; +use lib "$FindBin::Bin"; +#use lib "@NAGIOS_PLUGINS@"; +use lib "/usr/lib/nagios/plugins"; +use utils qw($TIMEOUT %ERRORS &print_revision &support); + +if (eval "require oreon" ) { + use oreon qw(get_parameters create_rrd update_rrd &is_valid_serviceid); + use vars qw($VERSION %oreon); + %oreon=get_parameters(); +} else { + print "Unable to load oreon perl module\n"; + exit $ERRORS{'UNKNOWN'}; +} + +use Getopt::Long; +use vars qw($opt_V $opt_h $opt_p $opt_c $opt_w $opt_H $opt_S $opt_g $opt_D $opt_step); +use vars qw($PROGNAME); + +my $pathtorrdbase = $oreon{GLOBAL}{DIR_RRDTOOL}; +my $pathtolibexectcp = $oreon{GLOBAL}{NAGIOS_LIBEXEC}."check_tcp"; + +sub print_help (); +sub print_usage (); +$PROGNAME = "check_graph_tcp"; + +# +# get options +# + +Getopt::Long::Configure('bundling'); +GetOptions + ("h|help" => \$opt_h, + "V|version" => \$opt_V, + "H|hostname=s" => \$opt_H, + "p|port=s" => \$opt_p, + "w|warning=s" => \$opt_w, + "c|critical=s" => \$opt_c, + "S|ServiceId=s" => \$opt_S, + "rrd_step=s" => \$opt_step, + "g|rrdgraph" => \$opt_g); + +if (defined($opt_h)) { + print_help(); + exit $ERRORS{'OK'}; +} + +$opt_H = shift unless ($opt_H); +(print_usage() && exit $ERRORS{'OK'}) unless ($opt_H); + +($opt_S) || ($opt_S = shift) || ($opt_S = "1_1"); +my $ServiceId = is_valid_serviceid($opt_S); + +($opt_step) || ($opt_step = shift) || ($opt_step = "300"); +my $step = $1 if ($opt_step =~ /(\d+)/); + +################################################## +#### Create Command line +# + +my $args_check_tcp = "-H $opt_H -p $opt_p"; +$args_check_tcp .= " -w $opt_w -c $opt_c" if ($opt_w && $opt_c); + +my $start=time; + + +## +## RRDTools create rrd +## +if ($opt_g) { + create_rrd ($pathtorrdbase.$ServiceId.".rrd",1,$start,$step,"U","U","GAUGE") if (! -e $pathtorrdbase.$ServiceId.".rrd"); +} + +my $result = `$pathtolibexectcp $args_check_tcp`; +my $return_code = $? / 256; +$_ = $result; +m/(\d*\.\d*) second/; +my $time = $1; + +# +# RRDtools update +# + +update_rrd ($pathtorrdbase.$ServiceId.".rrd",$start,$time) if ($opt_g && $time ); + +print "$result"; +exit $return_code; + +sub print_usage () { + print "\nUsage:\n"; + print $0."\n"; + print "\t-H (--hostname)\t\tHostname to query (required)\n"; + print "\t-p, --port\t\tPort number (required)\n"; + print "\t-w, --warning\t\tResponse time to result in warning status (seconds) - optional\n"; + print "\t-c, --critical\t\tResponse time to result in critical status (seconds) - optional\n"; + print "\t--rrd_step\t\tSpecifies the base interval in seconds with which data will be fed into the RRD (300 by default)\n"; + print "\t-V (--version)\t\tVieuw plugin version\n"; + print "\t-h (--help)\t\tusage help\n"; + +} + +sub print_help () { + print "################################################\n"; + print "# Bugs to http://bugs.oreon-project.org/ #\n"; + print "################################################\n"; + print "\n"; + print_usage(); + print "\n"; +} + + + + + + diff --git a/centreon-plugins/src/check_graph_traffic.pl b/centreon-plugins/src/check_graph_traffic.pl new file mode 100644 index 000000000..8745ee306 --- /dev/null +++ b/centreon-plugins/src/check_graph_traffic.pl @@ -0,0 +1,451 @@ +#! /usr/bin/perl -w +# +# $Id: check_graph_traffic.pl,v 1.2 2005/07/27 22:21:49 Julio $ +# +# Oreon's plugins are developped with GPL Licence : +# http://www.fsf.org/licenses/gpl.txt +# Developped by : Julien Mathis - Romain Le Merlus +# +# Modified for Oreon Project by : Mathieu Chateau - Christophe Coraboeuf +# Modified By Julien Mathis For Merethis Company +# +# 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 oid_lex_sort); +use FindBin; +use lib "$FindBin::Bin"; +use lib "/srv/nagios/libexec"; +use utils qw($TIMEOUT %ERRORS &print_revision &support); + +if (eval "require oreon" ) { + use oreon qw(get_parameters create_rrd update_rrd &is_valid_serviceid); + use vars qw($VERSION %oreon); + %oreon=get_parameters(); +} else { + print "Unable to load oreon perl module\n"; + exit $ERRORS{'UNKNOWN'}; +} + +use vars qw($VERSION %oreon); +use vars qw(%oreon); +$VERSION = '$Revision: 1.2 $'; +$VERSION =~ s/^\$.*:\W(.*)\W.+?$/$1/; + +use vars qw($PROGNAME); +use Getopt::Long; +use vars qw($opt_V $opt_h $opt_g $opt_v $opt_C $opt_b $opt_H $opt_D $opt_i $opt_n $opt_w $opt_c $opt_s $opt_S $opt_T $opt_step $step); + +my $pathtorrdbase = $oreon{GLOBAL}{DIR_RRDTOOL}; + +# +# Plugin var init +# + +my($proc, $proc_run, @test, $row, @laste_values, $last_check_time, $last_in_bits, $last_out_bits, @last_values, $update_time, $db_file, $in_traffic, $out_traffic, $in_usage, $out_usage); +my $pathtolibexecnt = $oreon{NAGIOS_LIBEXEC}; + +$PROGNAME = "check_graph_traffic"; +sub print_help (); +sub print_usage (); + +Getopt::Long::Configure('bundling'); +GetOptions + ("h" => \$opt_h, "help" => \$opt_h, + "s" => \$opt_s, "show" => \$opt_s, + "V" => \$opt_V, "version" => \$opt_V, + "g" => \$opt_g, "rrdgraph" => \$opt_g, + "rrd_step=s" => \$opt_step, + "i=s" => \$opt_i, "interface=s" => \$opt_i, + "n" => \$opt_n, "name" => \$opt_n, + "v=s" => \$opt_v, "snmp=s" => \$opt_v, + "C=s" => \$opt_C, "community=s" => \$opt_C, + "b=s" => \$opt_b, "bps=s" => \$opt_b, + "w=s" => \$opt_w, "warning=s" => \$opt_w, + "c=s" => \$opt_c, "critical=s" => \$opt_c, + "S=s" => \$opt_S, "ServiceId=s" => \$opt_S, + "T=s" => \$opt_T, + "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)/); + +if ($opt_n && !$opt_i) { + print "Option -n (--name) need option -i (--interface)\n"; + exit $ERRORS{'UNKNOWN'}; +} + +($opt_C) || ($opt_C = shift) || ($opt_C = "public"); +($opt_i) || ($opt_i = shift) || ($opt_i = 2); +($opt_S) || ($opt_S = shift) || ($opt_S = 1); +my $ServiceId = is_valid_serviceid($opt_S); + +($opt_b) || ($opt_b = shift) || ($opt_b = 95); +my $bps = $1 if ($opt_b =~ /([0-9]+)/); + +($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]+)/); + +my $interface = 0; +if ($opt_i =~ /([0-9]+)/ && !$opt_n){ + $interface = $1; +} elsif (!$opt_n) { + print "Unknown -i number expected... or it doesn't exist, try another interface - number\n"; + exit $ERRORS{'UNKNOWN'}; +} + +if ($critical <= $warning){ + print "(--crit) must be superior to (--warn)"; + print_usage(); + exit $ERRORS{'OK'}; +} + +($opt_step) || ($opt_step = shift) || ($opt_step = "300"); +$step = $1 if ($opt_step =~ /(\d+)/); + +################################################## +##### RRDTool var init +## + +my $rrd = $pathtorrdbase.$ServiceId.".rrd"; +my $start=time; + +################################################## +##### RRDTool create rrd +## + +if ($opt_g) { + if (! -e $rrd) { + create_rrd ($rrd,2,$start,$step,"U","U","GAUGE"); + } +} + +################################################# +##### Plugin snmp requests +## + +my $OID_DESC =$oreon{MIB2}{IF_DESC}; + +# 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'}; +} + +#getting interface using its name instead of its oid index + +if ($opt_n) { + my $result = $session->get_table(Baseoid => $OID_DESC); + if (!defined($result)) { + printf("ERROR: Description Table : %s.\n", $session->error); + $session->close; + exit $ERRORS{'UNKNOWN'}; + } + foreach my $key ( oid_lex_sort(keys %$result)) { + if ($result->{$key} =~ m/$opt_i/) { + my @oid_list = split (/\./,$key); + $interface = pop (@oid_list) ; + } + } +} + +my $OID_IN =$oreon{MIB2}{IF_IN_OCTET}.".".$interface; +my $OID_OUT = $oreon{MIB2}{IF_OUT_OCTET}.".".$interface; +my $OID_SPEED = $oreon{MIB2}{IF_SPEED}.".".$interface; + +# Get desctiption table + +if ($opt_s) { + my $result = $session->get_table(Baseoid => $OID_DESC); + if (!defined($result)) { + printf("ERROR: Description Table : %s.\n", $session->error); + $session->close; + exit $ERRORS{'UNKNOWN'}; + } + foreach my $key ( oid_lex_sort(keys %$result)) { + my @oid_list = split (/\./,$key); + my $index = pop (@oid_list) ; + print "Interface $index :: $$result{$key}\n"; + } + exit $ERRORS{'OK'}; +} + + +####### Get IN bytes + +my $in_bits; +my $result = $session->get_request(-varbindlist => [$OID_IN]); +if (!defined($result)) { + printf("ERROR: IN Bits : %s", $session->error); + if ($opt_n) { print " - You must specify interface name when option -n is used";} + print ".\n"; + $session->close; + exit $ERRORS{'UNKNOWN'}; +} +$in_bits = $result->{$OID_IN} * 8; + + +####### Get OUT bytes + +my $out_bits; +$result = $session->get_request(-varbindlist => [$OID_OUT]); +if (!defined($result)) { + printf("ERROR: Out Bits : %s", $session->error); + if ($opt_n) { print " - You must specify interface name when option -n is used";} + print ".\n"; + $session->close; + exit $ERRORS{'UNKNOWN'}; +} +$out_bits = $result->{$OID_OUT} * 8; + + +####### Get SPEED of interface + +my $speed_card; +$result = $session->get_request(-varbindlist => [$OID_SPEED]); +if (!defined($result)) { + printf("ERROR: Interface Speed : %s", $session->error); + if ($opt_n) { print " - You must specify interface name when option -n is used";} + print ".\n"; + $session->close; + exit $ERRORS{'UNKNOWN'}; +} + +if (defined($opt_T)){ + $speed_card = $opt_T * 1000000; +} else { + $speed_card = $result->{$OID_SPEED}; +} +############################################# +##### Plugin return code +## + +$last_in_bits = 0; +$last_out_bits = 0; + +my $flg_created; + +if (-e "/tmp/traffic_if".$interface."_".$opt_H) { + open(FILE,"<"."/tmp/traffic_if".$interface."_".$opt_H); + while($row = ){ + @last_values = split(":",$row); + $last_check_time = $last_values[0]; + $last_in_bits = $last_values[1]; + $last_out_bits = $last_values[2]; + $flg_created = 1; + } + close(FILE); +} else { + $flg_created = 0; +} + +$update_time = time; + +unless (open(FILE,">"."/tmp/traffic_if".$interface."_".$opt_H)){ + print "Unknown - /tmp/traffic_if".$interface."_".$opt_H. " !\n"; + exit $ERRORS{"UNKNOWN"}; +} +print FILE "$update_time:$in_bits:$out_bits"; +close(FILE); + +if ($flg_created eq 0){ + print "First execution : Buffer in creation.... \n"; + exit($ERRORS{"UNKNOWN"}); +} + + +## Bandwith = IN + OUT / Delta(T) = 6 Mb/s +## (100 * Bandwith) / (2(si full duplex) * Ispeed) +## Count must round at 4294967296 +## + +if (($in_bits - $last_in_bits > 0) && defined($last_in_bits)) { + my $total = 0; + if ($in_bits - $last_in_bits < 0){ + $total = 4294967296 - $last_in_bits + $in_bits; + } else { + $total = $in_bits - $last_in_bits; + } + my $pct_in_traffic = $in_traffic = abs($total / (time - $last_check_time)); +} else { + $in_traffic = 0; +} + +if ($out_bits - $last_out_bits > 0 && defined($last_out_bits)) { + my $total = 0; + if ($out_bits - $last_out_bits < 0){ + $total = 4294967296 - $last_out_bits + $out_bits; + } else { + $total = $out_bits - $last_out_bits; + } + my $pct_out_traffic = $out_traffic = abs($total / (time - $last_check_time)); +} else { + $out_traffic = 0; +} + +if ( $speed_card != 0 ) { + $in_usage = sprintf("%.1f",($in_traffic*100) / $speed_card); + $out_usage = sprintf("%.1f",($out_traffic*100) / $speed_card); + ## RRDtools update + if ($opt_g) { + $start = time; + update_rrd($rrd,$start, sprintf("%.1f",abs($in_traffic)), sprintf("%.1f",abs($out_traffic))); + } +} + +my $in_prefix = ""; +my $out_prefix = ""; + +my $in_perfparse_traffic = $in_traffic; +my $out_perfparse_traffic = $out_traffic; + +if ($in_traffic > 1000) { + $in_traffic = $in_traffic / 1000; + $in_prefix = "k"; + if($in_traffic > 1000){ + $in_traffic = $in_traffic / 1000; + $in_prefix = "M"; + } + if($in_traffic > 1000){ + $in_traffic = $in_traffic / 1000; + $in_prefix = "G"; + } +} + +if ($out_traffic > 1000){ + $out_traffic = $out_traffic / 1000; + $out_prefix = "k"; + if ($out_traffic > 1000){ + $out_traffic = $out_traffic / 1000; + $out_prefix = "M"; + } + if ($out_traffic > 1000){ + $out_traffic = $out_traffic / 1000; + $out_prefix = "G"; + } +} + +my $in_bits_unit = ""; +$in_bits = $in_bits/1048576; +if ($in_bits > 1000){ + $in_bits = $in_bits / 1000; + $in_bits_unit = "G"; +} else { + $in_bits_unit = "M"; +} + +my $out_bits_unit = ""; +$out_bits = $out_bits/1048576; +if ($out_bits > 1000){ + $out_bits = $out_bits / 1000; + $out_bits_unit = "G"; +} else { + $out_bits_unit = "M"; +} + + +if ( $speed_card == 0 ) { + print "CRITICAL: Interface speed equal 0! Interface must be down.|traffic_in=0B/s traffic_out=0B/s\n"; + exit($ERRORS{"CRITICAL"}); +} + +##################################### +##### Display result +## + + +my $in_perfparse_traffic_str = sprintf("%.1f",abs($in_perfparse_traffic)); +my $out_perfparse_traffic_str = sprintf("%.1f",abs($out_perfparse_traffic)); + +$in_perfparse_traffic_str =~ s/\./,/g; +$out_perfparse_traffic_str =~ s/\./,/g; + +my $status = "OK"; + +if (($in_usage > $critical) or ($out_usage > $critical)){ + $status = "CRITICAL"; +} + +if(($in_usage > $warning) or ($out_usage > $warning)){ + $status = "WARNING"; +} + + +printf("Traffic In : %.2f ".$in_prefix."b/s (".$in_usage." %%), Out : %.2f ".$out_prefix."b/s (".$out_usage." %%) - ", $in_traffic, $out_traffic); +printf("Total RX Bits In : %.2f ".$in_bits_unit."B, Out : %.2f ".$out_bits_unit."b", $in_bits, $out_bits); +printf("|traffic_in=".$in_perfparse_traffic_str."Bits/s traffic_out=".$out_perfparse_traffic_str."Bits/s\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 " used with SNMP v1 and v2c\n"; + print " -v (--snmp_version) 1 for SNMP v1 (default)\n"; + print " 2 for SNMP v2c\n"; + print " -g (--rrdgraph) create a rrd base and add datas into this one\n"; + print " --rrd_step Specifies the base interval in seconds with which data will be fed into the RRD (300 by default)\n"; + print " -D (--directory) Path to rrdatabase (or create the .rrd in this directory)\n"; + print " by default: ".$pathtorrdbase."\n"; + print " (The path is valid with spaces '/my\ path/...')\n"; + print " (The path is valid with spaces '/my\ path/...')\n"; + print " -s (--show) Describes all interfaces number (debug mode)\n"; + print " -i (--interface) Set the interface number (2 by default)\n"; + print " -n (--name) Allows to use interface name with option -d instead of interface oid index\n"; + print " (ex: -i \"eth0\" -n, -i \"VMware Virtual Ethernet Adapter for VMnet8\" -n\n"; + print " (choose an unique expression for each interface)\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 " -T Max Banwidth\n"; + print " (default 95)\n"; + print " -S (--ServiceId) Oreon Service Id\n"; + print " -V (--version) Plugin version\n"; + print " -h (--help) usage help\n"; +} + +sub print_help () { + print "##########################################\n"; + print "# Copyright (c) 2004-2006 Oreon #\n"; + print "# Bugs to http://www.oreon-project.org/ #\n"; + print "##########################################\n"; + print_usage(); + print "\n"; +} diff --git a/centreon-plugins/src/check_graph_traffic_rrd.pl b/centreon-plugins/src/check_graph_traffic_rrd.pl new file mode 100644 index 000000000..6344de2a1 --- /dev/null +++ b/centreon-plugins/src/check_graph_traffic_rrd.pl @@ -0,0 +1,316 @@ +#! /usr/bin/perl -w +# +# $Id: check_graph_traffic,v 1.1 2004/10/21 17:00:00 projectOREON $ +# +# Oreon's plugins are developped with GPL Licence : +# http://www.fsf.org/licenses/gpl.txt +# Last Developpement by : Jean Baptiste Gouret - Julien Mathis - Mathieu Mettre - Romain Le Merlus - Yohann Lecarpentier +# +# REVISED BY CVF 6/05/05 +# Modified for Oreon Project by : Christophe Coraboeuf + +## +## 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 oreon" ) { + use oreon qw(get_parameters create_rrd update_rrd fetch_rrd &is_valid_serviceid); + use vars qw($VERSION %oreon); + %oreon=get_parameters(); +} else { + print "Unable to load oreon perl module\n"; + exit $ERRORS{'UNKNOWN'}; +} + +use vars qw($VERSION %oreon); + +use Getopt::Long; +use vars qw($opt_V $opt_h $opt_g $opt_v $opt_C $opt_H $opt_D $opt_step $opt_i $opt_w $opt_c $opt_s $opt_S $opt_T $opt_Y); +use Data::Dumper; + +Getopt::Long::Configure('bundling'); + GetOptions ("h" => \$opt_h, "help" => \$opt_h, + "s" => \$opt_s, "show" => \$opt_s, + "V" => \$opt_V, "version" => \$opt_V, + "g" => \$opt_g, "rrdgraph" => \$opt_g, + "D=s" => \$opt_D, "directory=s" => \$opt_D, + "i=s" => \$opt_i, "interface=s" => \$opt_i, + "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, "ServiceId=s" => \$opt_S, + "H=s" => \$opt_H, "hostname=s" => \$opt_H, + "T=s" => \$opt_T, "Speed=s" => \$opt_T, + "rrd_step=s" => \$opt_step, + ); + +my $PROGNAME = "check_graph_traffic_rrd"; +my $pathtorrdbase = $oreon{GLOBAL}{DIR_RRDTOOL}; + + +sub print_help () { + print "\n"; + print_revision($PROGNAME,'Revision: 1.1 '); + print "\n"; + print_usage(); + print "\n"; + support(); + print "\n"; +} + +sub main () { + +## +## Plugin var init +## + my ($in_usage, $out_usage, $in_prefix, $out_prefix, $in_traffic, $out_traffic); + my ($host, $snmp, $community); + my ($interface, $ServiceId, $critical, $warning, $rrd, $start, $name); + my $ERROR; + my $result; + my ($in_bits, $out_bits, $speed, $ds_names, $step, $data); + my @valeur; + my $i = 0; + my ($line, $update_time, $rrdstep, $rrdheartbeat, $bitcounter); + my $not_traffic = 1; + + my $OID_IN =$oreon{MIB2}{IF_IN_OCTET}; + my $OID_OUT = $oreon{MIB2}{IF_OUT_OCTET}; + my $OID_SPEED = $oreon{MIB2}{IF_SPEED}; + my $OID_DESC = $oreon{MIB2}{IF_DESC}; + + if ($opt_V) { print_revision ($PROGNAME, "Revision: 1.1 "); exit $ERRORS{'OK'}; } + if ($opt_h) { print_help(); exit $ERRORS{'OK'}; } + if (defined($opt_H) && $opt_H =~ m/^([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)/) { $host = $1; } else { print_usage(); exit $ERRORS{'UNKNOWN'}; } + if ($opt_v) { $snmp = $opt_v; } else { $snmp = "2c"; } + if ($opt_C) { $community = $opt_C; } else { $community = "public"; } + if ($opt_s || (defined($opt_i) && $opt_i =~ /([0-9]+)/)) { $interface = $1;} else { print "\nUnknown -i number expected... or it doesn't exist, try another interface - number\n"; } + if ($opt_g) { + ($opt_S) || ($opt_S = shift) || ($opt_S = "1_1"); + $ServiceId = is_valid_serviceid($opt_S); + } + if (defined($opt_step) && $opt_step =~ /([0-9]+)/) { $rrdstep = $1; $rrdheartbeat = $rrdstep * 2; } else { $rrdstep = 300; $rrdheartbeat = $rrdstep * 2; } + if (defined($opt_c) && $opt_c =~ /([0-9]+)/) { $critical = $1; } else { $critical = 95; } + if (defined($opt_w) && $opt_w =~ /([0-9]+)/) { $warning = $1; } else { $warning = 80; } + if (defined($opt_c) && defined($opt_w) && $critical <= $warning){ print "(--crit) must be superior to (--warn)"; print_usage(); exit $ERRORS{'OK'}; } + if (defined($opt_D) && $opt_D =~ /([-.\/\_\ A-Za-z0-9]+)/) { $pathtorrdbase = $1; } + + ($opt_v) || ($opt_v = shift) || ($opt_v = "1"); + $snmp = $1 if ($opt_v =~ /(\d)/); + +## +## RRDTool var init +## + if ($opt_i) { + $OID_IN .= ".".$interface; + $OID_OUT .= ".".$interface; + $OID_SPEED .= ".".$interface; + } + + if ($opt_g && $opt_S) { + $rrd = $pathtorrdbase.$ServiceId.".rrd"; + $start = time; + $name = $0; + $name =~ s/\.pl.*//g; + + ## + ## RRDTool create rrd + ## + + if (!(-e $rrd)) { + $_ = `/usr/bin/snmpwalk $host -c $community -v $snmp $OID_IN 2>/dev/null`; + if ($_ =~ m/Counter(\d+)/) { $bitcounter = $1; } else { $bitcounter = 32; } + $bitcounter = 2 ** $bitcounter; + create_rrd ($rrd,2,$start,$rrdstep,0,$bitcounter,"COUNTER"); + } + } + + +## +## Plugin snmp requests +## + + # if ($opt_s) { $_ = `/usr/bin/snmpwalk $host -c $community -v $snmp $OID_DESC 2>/dev/null`; print $_; exit $ERRORS{'OK'}; } + + +# create a SNMP session # + my ( $session, $error ) = Net::SNMP->session(-hostname => $host,-community => $community, -version => $snmp); + if ( !defined($session) ) { print("UNKNOWN: $error"); exit $ERRORS{'UNKNOWN'}; } + + +if ($opt_s) { + # Get desctiption table + my $result = $session->get_table( + Baseoid => $OID_DESC + ); + + if (!defined($result)) { + printf("ERROR: Description Table : %s.\n", $session->error); + $session->close; + exit $ERRORS{'UNKNOWN'}; + } + + foreach my $key ( oid_lex_sort(keys %$result)) { + my @oid_list = split (/\./,$key); + my $index = pop (@oid_list) ; + print "Interface $index :: $$result{$key}\n"; + } +exit $ERRORS{'OK'}; +} + +# get IN bits # + $result = $session->get_request( -varbindlist => [$OID_IN] ); + if (!defined($result)) { printf("ERROR : IN : %s.\n", $session->error); $session->close; exit($ERRORS{"CRITICAL"}); } + $in_bits = $result->{$OID_IN} * 8; + + +# get OUT bits # + $result = $session->get_request( -varbindlist => [$OID_OUT] ); + if (!defined($result)) { printf("ERROR : OUT : %s.\n", $session->error); $session->close; exit($ERRORS{"CRITICAL"}); } + $out_bits = $result->{$OID_OUT} * 8; + + +# Get SPEED of interface # + if (!defined($opt_T) || $opt_T == 0) { + $result = $session->get_request( -varbindlist => [$OID_SPEED] ); + if (!defined($result)) { printf("ERROR: %s.\n", $session->error); $session->close; exit($ERRORS{"CRITICAL"}); } + $speed = $result->{$OID_SPEED}; + } + else { + $speed = $opt_T * 1000000; + } + + +## +## RRDtools update +## + + if ($opt_g) { + $start=time; + update_rrd ($rrd,$start,$in_bits,$out_bits); + + ## + ## Get the real value in rrdfile + ## + # ($update_time,$step,$ds_names,$data) = RRDs::fetch($rrd, "--resolution=300","--start=now-5min","--end=now","AVERAGE"); + # foreach $line (@$data) { + # foreach $val (@$line) { + # if ( defined $val ) { $valeur[$i]=$val; } else { $valeur[$i]="undef"; } + # $i++; + # } + # }*/ + @valeur = fetch_rrd($rrd,"AVERAGE"); + $in_traffic = $valeur[0]; + $out_traffic = $valeur[1]; + } + + if (!(defined($in_traffic)) && !(defined($out_traffic))) { + $not_traffic = 0; + } else { + $in_prefix = " "; + $out_prefix = " "; + + if (!($in_traffic eq "undef")) { + if ($in_traffic > 1000000) { + $in_usage = sprintf("%.2f",($in_traffic/($speed))*100); + $in_traffic = sprintf("%.2f",$in_traffic/1000000); + $in_prefix = "M"; + } + elsif ($in_traffic > 1000) { + $in_usage = sprintf("%.2f",($in_traffic/($speed))*100); + $in_traffic = sprintf("%.2f",$in_traffic/1000); + $in_prefix = "K"; + } + elsif ($in_traffic < 1000) { + $in_usage = sprintf("%.2f",($in_traffic/($speed))*100); + $in_traffic = sprintf("%.2f",$in_traffic); + $in_prefix = " "; + } + else { + print "ERROR\n"; exit 1; + } + + } else { + $in_usage = 0 ; + } + + if (!($out_traffic eq "undef")) { + if ($out_traffic > 1000000) { + $out_usage = sprintf("%.2f",($out_traffic/($speed))*100); + $out_traffic = sprintf("%.2f",$out_traffic/1000000); + $out_prefix = "M"; + } + elsif ($out_traffic > 1000) { + $out_usage = sprintf("%.2f",($out_traffic/($speed))*100); + $out_traffic = sprintf("%.2f",$out_traffic/1000); + $out_prefix = "K"; + } + elsif ($out_traffic < 1000) { + $out_usage = sprintf("%.2f",($out_traffic/($speed))*100); + $out_traffic = sprintf("%.2f",$out_traffic); + $out_prefix = " "; + } + } else { + $out_usage = 0 ; + } + } + +## +## Plugin return code && Status +## + + if ( $speed == 0 ) { + print "CRITICAL: Interface speed equal 0! Interface must be down.\n"; + exit($ERRORS{"CRITICAL"}); + } + else { + $speed = sprintf("%.2f",($speed/1000000)); + } + + if ($not_traffic != 1) { + print "Counter: IN = $in_bits bits and OUT = $out_bits bits - Traffic cannot be calculated when the last value from the rrdfile is `undef' (check if the `-g' option is enabled)\n"; exit($ERRORS{"OK"}); + } else { + if(($in_usage > $critical) || ($out_usage > $critical)) { + print "CRITICAL: (".$critical."%) depassed threshold. Traffic: $in_traffic ".$in_prefix."b/s (".$in_usage."%) in, $out_traffic ".$out_prefix."b/s (".$out_usage."%) out - Speed Interface = ".$speed." Mb/s \n"; + exit($ERRORS{"CRITICAL"}); + } + if(($in_usage > $warning) || ($out_usage > $warning)) { + print "WARNING: (".$warning."%) depassed threshold. Traffic: $in_traffic ".$in_prefix."b/s (".$in_usage."%) in, $out_traffic ".$out_prefix."b/s (".$out_usage."%) out - Speed Interface = ".$speed." Mb/s\n"; + exit($ERRORS{"WARNING"}); + } + print "OK: Traffic: $in_traffic ".$in_prefix."b/s (".$in_usage."%) in, $out_traffic ".$out_prefix."b/s (".$out_usage."%) out - Speed Interface = ".$speed." Mb/s\n $opt_g"; 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 " -g (--rrdgraph) create à rrd base and add datas into this one\n"; + print " -D (--directory) Path to rrdatabase (or create the .rrd in this directory)\n"; + print " by default: ".$pathtorrdbase."\n"; + print " (The path is valid with spaces '/my\ path/...')\n"; + print " -s (--show) Describes all interfaces number (debug mode)\n"; + print " -i (--interface) Set the interface number (2 by default)\n"; + print " -T (--speed) Set the speed interface in Mbit/s (by default speed interface capacity)\n"; + print " --rrdstep Set the rrdstep in second (5 minuntes by default)\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 " -S (--ServiceId) Oreon Service Id\n"; + print " -V (--version) Plugin version\n"; + print " -h (--help) usage help\n\n"; +} + +main (); diff --git a/centreon-plugins/src/check_graph_uptime.pl b/centreon-plugins/src/check_graph_uptime.pl new file mode 100644 index 000000000..07c8ef47f --- /dev/null +++ b/centreon-plugins/src/check_graph_uptime.pl @@ -0,0 +1,212 @@ +#! /usr/bin/perl -w +# +# $Id: check_graph_uptime.pl,v 1.2 2005/07/27 22:21:49 wistof Exp $ +# +# This plugin is developped under GPL Licence: +# http://www.fsf.org/licenses/gpl.txt + +# Developped by Linagora SA: http://www.linagora.com + +# Modified for Oreon Project by : Mathieu Chateau - Christophe Coraboeuf +# Modified For Oreon compatibility by Julien Mathis For Merethis +# +# The Software is provided to you AS IS and WITH ALL FAULTS. +# LINAGORA 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 LINAGORA web site. +# In no event will LINAGORA be liable for any direct, indirect, punitive, special, +# incidental or consequential damages however they may arise and even if LINAGORA has +# been previously advised of the possibility of such damages. + +# based on "graph plugins" developped by Oreon Team. See http://www.oreon.org. +## +## Plugin 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 oreon" ) { + use oreon qw(get_parameters create_rrd update_rrd &is_valid_serviceid); + use vars qw($VERSION %oreon); + %oreon=get_parameters(); +} else { + print "Unable to load oreon perl module\n"; + exit $ERRORS{'UNKNOWN'}; +} + +use vars qw($PROGNAME); +use Getopt::Long; +use vars qw($opt_h $opt_V $opt_g $opt_D $opt_S $opt_H $opt_C $opt_v $opt_d $day $opt_step); +my $pathtorrdbase = $oreon{GLOBAL}{DIR_RRDTOOL}; + +$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, + "g" => \$opt_g, "rrdgraph" => \$opt_g, + "rrd_step=s" => \$opt_step, + "v=s" => \$opt_v, "snmp=s" => \$opt_v, + "C=s" => \$opt_C, "community=s" => \$opt_C, + "S=s" => \$opt_S, "ServiceId=s" => \$opt_S, + "d" => \$opt_d, "day" => \$opt_d, + "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 = "1"); +my $snmp = $1 if ($opt_v =~ /(\d)/); + +($opt_S) || ($opt_S = shift) || ($opt_S = "1_1"); +my $ServiceId = is_valid_serviceid($opt_S); + +($opt_C) || ($opt_C = shift) || ($opt_C = "public"); + +my $rrd = $pathtorrdbase.$ServiceId.".rrd"; + +my $start=time; +my $name = $0; +$name =~ s/\.pl.*//g; +my $day = 0; + +## +## RRDTools create rrd +## +if ($opt_g) { + if (! -e $rrd) { + create_rrd($rrd,1,$start,300,"U","U","GAUGE"); + } +} + +## +## Plugin snmp requests +## + +my $OID_OBJECTID =$oreon{MIB2}{OBJECTID}; +my $OID_UPTIME_WINDOWS =$oreon{MIB2}{UPTIME_WINDOWS}; +my $OID_UPTIME_OTHER =$oreon{MIB2}{UPTIME_OTHER}; + +# create a SNMP session +my ( $session, $error ) = Net::SNMP->session(-hostname => $opt_H,-community => $opt_C, -version => $snmp); +if ( !defined($session) ) { + print("CRITICAL: $error"); + exit $ERRORS{'CRITICAL'}; +} + +my $result = $session->get_request( + -varbindlist => [$OID_OBJECTID] + ); +if (!defined($result)) { + printf("UNKNOWN: %s.\n", $session->error); + $session->close; + exit $ERRORS{'UNKNOWN'}; +} + +my $return_result = $result->{$OID_OBJECTID}; +my $OID = ""; +if ($return_result =~ /.*Windows.*/i ) { + $OID = $OID_UPTIME_WINDOWS; +} else { + $OID = $OID_UPTIME_OTHER; +} + +$result = $session->get_request( + -varbindlist => [$OID] + ); +if (!defined($result)) { + printf("UNKNOWN: %s.\n", $session->error); + $session->close; + exit $ERRORS{'UNKNOWN'}; +} + +my $un = 0; + +$return_result = $result->{$OID}; +if ( $return_result =~ m/(\d*) day[s]?,\s*(\d*):(\d*):(\d*).(\d*)/ ) { + $un = $5 + $4 * 100 + $3 * 100 * 60 + $2 * 100 * 60 * 60 + $1 * 100 * 60 * 60 * 24; + $day = $1; +} + +if ( $return_result =~ m/(\d*) hour.*(\d*):(\d*).(\d*)/ ) { + $un = $4 + $3 * 100 + $3 * 100 * 60 + $1 * 100 * 60 * 60 ; +} + +if ($opt_d) { + $un = $day; +} + +#print "un : $un\n"; + +## +## RRDtools update +## +if ($opt_g) { + $start=time; + update_rrd($rrd,$start,$un); +} + +## +## Plugin return code +## + +if ($un || ( $un == 0) ){ + if ($opt_d) { + print "OK - Uptime (in day): $un|uptime=".$un."hs\n"; + } else { + print "OK - Uptime (in hundredths of a second): $un|uptime=".$un."hs\n"; + } + exit $ERRORS{'OK'}; +} +else{ + print "CRITICAL Host unavailable\n"; + exit $ERRORS{'CRITICAL'}; +} + + +sub print_usage () { + print "\nUsage:\n"; + print "$PROGNAME\n"; + print " -H (--hostname) Hostname to query - (required)\n"; + print " -C (--community) SNMP read community (defaults to public,\n"; + print " used with SNMP v1 and v2c\n"; + print " -v (--snmp_version) 1 for SNMP v1 (default)\n"; + print " 2 for SNMP v2c\n"; + print " -g (--rrdgraph) create a rrd base and add datas into this one\n"; + print " -D (--directory) Path to rrdatabase (or create the .rrd in this directory)\n"; + print " by default: ".$pathtorrdbase."\n"; + print " (The path is valid with spaces '/my\ path/...')\n"; + print " -S (--ServiceId) Oreon Service Id\n"; + print " -d (--day) Uptime in day\n"; + print " -V (--version) Plugin version\n"; + print " -h (--help) usage help\n"; + +} + +sub print_help () { + print "Copyright (c) 2005 Linagora\n"; + print "Modified by Merethis \n"; + print "Bugs to http://www.linagora.com/\n"; + print "\n"; + print_usage(); + print "\n"; +} diff --git a/centreon-plugins/src/check_meta_service.pl b/centreon-plugins/src/check_meta_service.pl new file mode 100644 index 000000000..1f4fb8c49 --- /dev/null +++ b/centreon-plugins/src/check_meta_service.pl @@ -0,0 +1,369 @@ +#! /usr/bin/perl -w +# +# $Id: check_meta_service.pl,v 1.2 2005/07/27 22:21:49 Julio $ +# +# Oreon's plugins are developped with GPL Licence : +# http://www.fsf.org/licenses/gpl.txt +# Developped by : Julien Mathis - Romain Le Merlus +# +# Developped by Julien Mathis for Merethis SARL +# +# 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 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, + "H" => \$opt_H, + "i=s" => \$opt_i); + + +my $dbh = DBI->connect("DBI:mysql:database=oreon;host=localhost", + "oreon", "oreon", + {'RaiseError' => 1}); + +my $sth1 = $dbh->prepare("SELECT * FROM `cfg_perfparse`"); +if (!$sth1->execute) {die "Error:" . $sth1->errstr . "\n";} +my $ref1 = $sth1->fetchrow_hashref(); +my $dbh2 = DBI->connect("DBI:".$ref1->{'Storage_Modules_Load'}.":database=".$ref1->{'DB_Name'}.";host=".$ref1->{'DB_Host'}, + $ref1->{'DB_User'}, $ref1->{'DB_Pass'}, + {'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($$$){ + + #print "warning : ".$warning."-Critical : ".$critical.":$result\b"; + + if ($warning ne $critical){ + if ($warning < $critical){ # Bon sens + if ($result < $warning){ + print "OK result : " . $result . "|OMS=" . $result . ";".$warning.";".$critical."\n"; + exit $ERRORS{'OK'}; + } elsif (($result >= $warning) && ($result < $critical)){ + print "WARNING result : " . $result . "|OMS=" . $result . ";".$warning.";".$critical."\n"; + exit $ERRORS{'WARNING'}; + } elsif ($result >= $critical){ + print "CRITICAL result : " . $result . "|OMS=" . $result . ";".$warning.";".$critical."\n"; + exit $ERRORS{'CRITICAL'}; + } + } else { # sens inverse + if ($result < $critical){ + print "CRITICAL result : " . $result . "|OMS=" . $result . ";".$warning.";".$critical."\n"; + exit $ERRORS{'CRITICAL'}; + } elsif ($result >= $critical && $result < $warning){ + print "WARNING result : " . $result . "|OMS=" . $result . ";".$warning.";".$critical."\n"; + exit $ERRORS{'WARNING'}; + } elsif ($result >= $warning){ + print "OK result : " . $result . "|OMS=" . $result . ";".$warning.";".$critical."\n"; + exit $ERRORS{'OK'}; + } 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 perfdata_service_metric,perfdata_service_bin WHERE perfdata_service_metric.metric_id = '".$metric_id."' AND perfdata_service_metric.last_perfdata_bin = perfdata_service_bin.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 perfdata_service_metric,perfdata_service_bin WHERE perfdata_service_metric.host_name = '".$data->{'host_name'}."' AND perfdata_service_metric.service_description = '".$data->{'service_description'}."' AND perfdata_service_metric.last_perfdata_bin = perfdata_service_bin.id AND perfdata_service_metric.metric = '".$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 perfdata_service_metric,perfdata_service_bin WHERE perfdata_service_metric.host_name = '".$data->{'host_name'}."' AND perfdata_service_metric.service_description = '".$data->{'service_description'}."' AND perfdata_service_metric.last_perfdata_bin = perfdata_service_bin.id AND perfdata_service_metric.metric = '".$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 perfdata_service_metric,perfdata_service_bin WHERE perfdata_service_metric.host_name = '".$host_data->{'host_name'}."' AND perfdata_service_metric.service_description = '".$service_data->{'service_description'}."' AND perfdata_service_metric.last_perfdata_bin = perfdata_service_bin.id AND perfdata_service_metric.metric = '".$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); + ############################################### + } 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"){ + 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); + } +} + + +sub print_usage () { + print "Usage:\n"; + print " check_osl.pl\n"; + print " -H Hostname to query (Required)\n"; + print " -i OSL id\n"; + print " -V (--version) Plugin version\n"; + print " -h (--help) usage help\n"; +} + +sub print_help () +{ + print "###########################################\n"; + print "# #\n"; + print "# Copyright (c) 2004-2006 Merethis #\n"; + print "# Bugs to http://www.oreon-services.com #\n"; + print "# #\n"; + print "###########################################\n"; + print_usage(); + print "\n"; +} diff --git a/centreon-plugins/src/check_nt_oreon.pl b/centreon-plugins/src/check_nt_oreon.pl new file mode 100644 index 000000000..7f1d86371 --- /dev/null +++ b/centreon-plugins/src/check_nt_oreon.pl @@ -0,0 +1,337 @@ +#! /usr/bin/perl -w +# +# $Id: check_graph_nt.pl,v 1.3 2005/08/01 18:04:00 gollum123 Exp $ +# +# Oreon's plugins are developped with GPL Licence : +# http://www.fsf.org/licenses/gpl.txt +# Developped by : Julien Mathis - Mathieu Mettre +# Under control of Flavien Astraud, Jerome Landrieu for Epitech. +# Oreon's plugins are developped in partnership with Linagora company. +# +# 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 FindBin; +use lib "$FindBin::Bin"; +use lib "/srv/nagios/libexec"; +use utils qw($TIMEOUT %ERRORS &print_revision &support); + +if (eval "require oreon" ) { + use oreon qw(get_parameters create_rrd update_rrd &is_valid_serviceid); + use vars qw($VERSION %oreon); + %oreon=get_parameters(); +} else { + print "Unable to load oreon perl module\n"; + exit $ERRORS{'UNKNOWN'}; +} + +use vars qw($PROGNAME); +use Getopt::Long; +use vars qw($opt_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 = $oreon{GLOBAL}{NAGIOS_LIBEXEC}."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 = "check_nt_oreon"; + +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 2>/dev/null`; + my $return = $_; + $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] = $test[3] * 1024 * 1024; + $test[7] = $test[7] * 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] = $test4[1] * 1024 * 1024; + $test[6] = $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 = "Unknow"; + } + 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 . "|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 "Copyright (c) 2004 OREON\n"; + print "Bugs to http://www.oreon.org/\n"; + print "\n"; + print_usage(); + print "\n"; +} diff --git a/centreon-plugins/src/check_snmp_cpfw.pl b/centreon-plugins/src/check_snmp_cpfw.pl new file mode 100644 index 000000000..14b29fa5d --- /dev/null +++ b/centreon-plugins/src/check_snmp_cpfw.pl @@ -0,0 +1,534 @@ +#!/usr/bin/perl -w +############################## check_snmp_cpfw ############## +# Version : 0.7 +# Date : Oct 02 2004 +# Author : Patrick Proy (patrick at proy.org) +# Help : http://www.manubulon.com/nagios/ +# Licence : GPL - http://www.fsf.org/licenses/gpl.txt +# TODO : +# - check sync method +################################################################# +# +# Help : ./check_snmp_cpfw.pl -h +# + +use strict; +use Net::SNMP; +use Getopt::Long; + +# Nagios specific + +use lib "@NAGIOS_PLUGINS@"; +use utils qw(%ERRORS $TIMEOUT); +#my $TIMEOUT = 15; +#my %ERRORS=('OK'=>0,'WARNING'=>1,'CRITICAL'=>2,'UNKNOWN'=>3,'DEPENDENT'=>4); + +# Oreon specific + +if (eval "require oreon" ) { + use oreon qw(get_parameters create_rrd update_rrd &is_valid_serviceid); + use vars qw($VERSION %oreon); + %oreon=get_parameters(); +} else { + print "Unable to load oreon perl module\n"; + exit $ERRORS{'UNKNOWN'}; +} + +my $pathtorrdbase = $oreon{GLOBAL}{DIR_RRDTOOL}; + + +########### SNMP Datas ########### + +###### FW data +my $policy_state = "1.3.6.1.4.1.2620.1.1.1.0"; # "Installed" +my $policy_name = "1.3.6.1.4.1.2620.1.1.2.0"; # Installed policy name +my $connections = "1.3.6.1.4.1.2620.1.1.25.3.0"; # number of connections +#my $connections_peak = "1.3.6.1.4.1.2620.1.1.25.4.0"; # peak number of connections +my @fw_checks = ($policy_state,$policy_name,$connections); + +###### SVN data +my $svn_status = "1.3.6.1.4.1.2620.1.6.102.0"; # "OK" svn status +my %svn_checks = ($svn_status,"OK"); +my %svn_checks_n = ($svn_status,"SVN status"); +my @svn_checks_oid = ($svn_status); + +###### HA data + +my $ha_active = "1.3.6.1.4.1.2620.1.5.5.0"; # "yes" +my $ha_state = "1.3.6.1.4.1.2620.1.5.6.0"; # "active" +my $ha_block_state = "1.3.6.1.4.1.2620.1.5.7.0"; #"OK" : ha blocking state +my $ha_status = "1.3.6.1.4.1.2620.1.5.102.0"; # "OK" : ha status + +my %ha_checks =( $ha_active,"yes",$ha_state,"active",$ha_block_state,"OK",$ha_status,"OK"); +my %ha_checks_n =( $ha_active,"HA active",$ha_state,"HA state",$ha_block_state,"HA block state",$ha_status,"ha_status"); +my @ha_checks_oid =( $ha_active,$ha_state,$ha_block_state,$ha_status); + +my $ha_mode = "1.3.6.1.4.1.2620.1.5.11.0"; # "Sync only" : ha Working mode + +my $ha_tables = "1.3.6.1.4.1.2620.1.5.13.1"; # ha status table +my $ha_tables_index = ".1"; +my $ha_tables_name = ".2"; +my $ha_tables_state = ".3"; # "OK" +my $ha_tables_prbdesc = ".6"; # Description if state is != "OK" + +#my @ha_table_check = ("Synchronization","Filter","cphad","fwd"); # process to check + +####### MGMT data + +my $mgmt_status = "1.3.6.1.4.1.2620.1.7.5.0"; # "active" : management status +my $mgmt_alive = "1.3.6.1.4.1.2620.1.7.6.0"; # 1 : management is alive if 1 +my $mgmt_stat_desc = "1.3.6.1.4.1.2620.1.7.102.0"; # Management status description +my $mgmt_stats_desc_l = "1.3.6.1.4.1.2620.1.7.103.0"; # Management status long description + +my %mgmt_checks = ($mgmt_status,"active",$mgmt_alive,"1"); +my %mgmt_checks_n = ($mgmt_status,"Mgmt status",$mgmt_alive,"Mgmt alive"); +my @mgmt_checks_oid = ($mgmt_status,$mgmt_alive); + +#################################### Globals ##############################"" + +my $Version='0.7'; + +my $o_host = undef; # hostname +my $o_community = undef; # community +my $o_port = 161; # port +my $o_help= undef; # wan't some help ? +my $o_verb= undef; # verbose mode +my $o_version= undef; # print version +my $o_warn= undef; # Warning for connections +my $o_crit= undef; # Crit for connections +my $o_svn= undef; # Check for SVN status +my $o_fw= undef; # Check for FW status +my $o_ha= undef; # Check for HA status +my $o_mgmt= undef; # Check for management status +my $o_policy= undef; # Check for policy name +my $o_conn= undef; # Check for connexions +my $o_perf= undef; # Performance data output + +# SNMPv3 specific +my $o_login= undef; # Login for snmpv3 +my $o_passwd= undef; # Pass for snmpv3 + +# Oreon specific +my $o_step= undef; +my $o_g= undef; +my $o_S= undef; +my $step= undef; +my $rrd= undef; +my $start= undef; +my $ServiceId= undef; +my @rrd_data= undef; + + +# functions + +sub p_version { print "check_snmp_cpfw version : $Version\n"; } + +sub print_usage { + print "Usage: $0 [-v] -H -C | (-l login -x passwd) [-s] [-w [-p=pol_name] [-c=warn,crit]] [-m] [-a] [-f] [-p ] [-t ] [-V]\n"; +} + +sub isnnum { # Return true if arg is not a number + my $num = shift; + if ( $num =~ /^(\d+\.?\d*)|(^\.\d+)$/ ) { return 0 ;} + return 1; +} + +sub help { + print "\nSNMP Checkpoint FW-1 Monitor for Nagios version ",$Version,"\n"; + print "(c)2004 - to my cat Ratoune\n\n"; + print_usage(); + print < \$o_verb, 'verbose' => \$o_verb, + 'h' => \$o_help, 'help' => \$o_help, + 'H:s' => \$o_host, 'hostname:s' => \$o_host, + 'P:i' => \$o_port, 'port:i' => \$o_port, + 'C:s' => \$o_community, 'community:s' => \$o_community, + 'l:s' => \$o_login, 'login:s' => \$o_login, + 'x:s' => \$o_passwd, 'passwd:s' => \$o_passwd, + 't:i' => \$TIMEOUT, 'timeout:i' => \$TIMEOUT, + 'V' => \$o_version, 'version' => \$o_version, + 's' => \$o_svn, 'svn' => \$o_svn, + 'w' => \$o_fw, 'fw' => \$o_fw, + 'a' => \$o_ha, 'ha' => \$o_ha, + 'm' => \$o_mgmt, 'mgmt' => \$o_mgmt, + 'p:s' => \$o_policy, 'policy:s' => \$o_policy, + 'c:s' => \$o_conn, 'connexions:s' => \$o_conn, + 'f' => \$o_perf, 'perfparse' => \$o_perf, + # For Oreon rrdtool graph + "rrd_step:s" => \$o_step, + "g" => \$o_g, "rrdgraph" => \$o_g, + "S=s" => \$o_S, "ServiceId=s" => \$o_S + ); + if (defined ($o_help) ) { help(); exit $ERRORS{"UNKNOWN"}}; + if (defined($o_version)) { p_version(); exit $ERRORS{"UNKNOWN"}}; + if ( ! defined($o_host) ) # check host and filter + { print_usage(); exit $ERRORS{"UNKNOWN"}} + # check snmp information + if ( !defined($o_community) && (!defined($o_login) || !defined($o_passwd)) ) + { print "Put snmp login info!\n"; print_usage(); exit $ERRORS{"UNKNOWN"}} + # Check firewall options + if ( defined($o_conn)) { + if ( ! defined($o_fw)) + { print "Cannot check connexions without checking fw\n"; print_usage(); exit $ERRORS{"UNKNOWN"}} + my @warncrit=split(/,/ , $o_conn); + if ( $#warncrit != 1 ) + { print "Put warn,crit levels with -c option\n";print_usage(); exit $ERRORS{"UNKNOWN"}} + ($o_warn,$o_crit)=@warncrit; + if ( isnnum($o_warn) || isnnum($o_crit) ) + { print "Numeric values for warning and critical in -c options\n";print_usage(); exit $ERRORS{"UNKNOWN"}} + if ($o_warn >= $o_crit) + { print "warning <= critical ! \n";print_usage(); exit $ERRORS{"UNKNOWN"}} + } + if ( defined($o_policy)) { + if (! defined($o_fw)) + { print "Cannot check policy name without checking fw\n"; print_usage(); exit $ERRORS{"UNKNOWN"}} + if ($o_policy eq "") + { print "Put a policy name !\n"; print_usage(); exit $ERRORS{"UNKNOWN"}} + } + if (defined($o_perf) && ! defined ($o_conn)) + { print "Nothing selected for perfparse !\n";print_usage(); exit $ERRORS{"UNKNOWN"}} + if (!defined($o_fw) && !defined($o_ha) && !defined($o_mgmt) && !defined($o_svn)) + { print "Must select a product to check !\n";print_usage(); exit $ERRORS{"UNKNOWN"}} + + ###### Oreon ####### + + if (!defined($o_S)) { $o_S="1_1" } + $ServiceId = is_valid_serviceid($o_S); + + if (!defined($o_step)) { $o_step="300" } + $step = $1 if ($o_step =~ /(\d+)/); + +} + +########## MAIN ####### + +check_options(); + +$rrd = $pathtorrdbase.$ServiceId.".rrd"; +$start=time; + +# Check gobal timeout if snmp screws up +alarm($TIMEOUT+15); + +# Connect to host +my ($session,$error); +if ( defined($o_login) && defined($o_passwd)) { + # SNMPv3 login + verb("SNMPv3 login"); + ($session, $error) = Net::SNMP->session( + -hostname => $o_host, + -version => '3', + -username => $o_login, + -authpassword => $o_passwd, + -authprotocol => 'md5', + -privpassword => $o_passwd + ); +} else { + # SNMPV1 login + ($session, $error) = Net::SNMP->session( + -hostname => $o_host, + -community => $o_community, + -port => $o_port, + -timeout => $TIMEOUT + ); +} +if (!defined($session)) { + printf("ERROR opening session: %s.\n", $error); + exit $ERRORS{"UNKNOWN"}; +} + +########### Global checks ################# + +my $global_status=0; # global status : 0=OK, 1=Warn, 2=Crit +my ($resultat,$key)=(undef,undef); + +########## Check SVN status ############# +my $svn_print=""; +my $svn_state=0; + +if (defined ($o_svn)) { + +$resultat = $session->get_request( + Varbindlist => \@svn_checks_oid +); + + if (defined($resultat)) { + foreach $key ( keys %svn_checks) { + verb("$svn_checks_n{$key} : $svn_checks{$key} / $$resultat{$key}"); + if ( $$resultat{$key} ne $svn_checks{$key} ) { + $svn_print .= $svn_checks_n{$key} . ":" . $$resultat{$key} . " "; + $svn_state=2; + } + } + } else { + $svn_print .= "cannot find oids"; + #Critical state if not found because it means soft is not activated + $svn_state=2; + } + + if ($svn_state == 0) { + $svn_print="SVN : OK"; + } else { + $svn_print="SVN : " . $svn_print; + } + verb("$svn_print"); +} +########## Check mgmt status ############# +my $mgmt_state=0; +my $mgmt_print=""; + +if (defined ($o_mgmt)) { +# Check all states + $resultat=undef; + $resultat = $session->get_request( + Varbindlist => \@mgmt_checks_oid + ); + if (defined($resultat)) { + foreach $key ( keys %mgmt_checks) { + verb("$mgmt_checks_n{$key} : $mgmt_checks{$key} / $$resultat{$key}"); + if ( $$resultat{$key} ne $mgmt_checks{$key} ) { + $mgmt_print .= $mgmt_checks_n{$key} . ":" . $$resultat{$key} . " "; + $mgmt_state=2; + } + } + } else { + $mgmt_print .= "cannot find oids"; + #Critical state if not found because it means soft is not activated + $mgmt_state=2; + } + if ($mgmt_state == 0) { + $mgmt_print="MGMT : OK"; + } else { + $mgmt_print="MGMT : " . $mgmt_print; + } + verb("$svn_print"); +} + +########### Check fw status ############## + +my $fw_state=0; +my $fw_print=""; +my $perf_conn=undef; + +if (defined ($o_fw)) { + +# Check all states + + $resultat = $session->get_request( + Varbindlist => \@fw_checks + ); + if (defined($resultat)) { + verb("State : $$resultat{$policy_state}"); + verb("Name : $$resultat{$policy_name}"); + verb("connections : $$resultat{$connections}"); + + if ($$resultat{$policy_state} ne "Installed") { + $fw_state=2; + $fw_print .= "Policy:". $$resultat{$policy_state}." "; + verb("Policy state not installed"); + } + + if (defined($o_policy)) { + if ($$resultat{$policy_name} ne $o_policy) { + $fw_state=2; + $fw_print .= "Policy installed : $$resultat{$policy_name}"; + } + } + + if (defined($o_conn)) { + if ($$resultat{$connections} > $o_crit) { + $fw_state=2; + $fw_print .= "Connexions : ".$$resultat{$connections}." > ".$o_crit." "; + } else { + if ($$resultat{$connections} > $o_warn) { + $fw_state=1; + $fw_print .= "Connexions : ".$$resultat{$connections}." > ".$o_warn." "; + } + } + $perf_conn=$$resultat{$connections}; + + ## + ## RRD management + ## + + if ($o_g) { + $start=time; + if (! -e $rrd) { + create_rrd($rrd,1,$start,$step,0,"U","GAUGE"); + } + update_rrd($rrd,$start, $perf_conn); + } + } + } else { + $fw_print .= "cannot find oids"; + #Critical state if not found because it means soft is not activated + $fw_state=2; + } + + if ($fw_state==0) { + $fw_print="FW : OK"; + } else { + $fw_print="FW : " . $fw_print; + } + +} +########### Check ha status ############## + +my $ha_state_n=0; +my $ha_print=""; + +if (defined ($o_ha)) { + # Check all states + + $resultat = $session->get_request( + Varbindlist => \@ha_checks_oid + ); + + if (defined($resultat)) { + foreach $key ( keys %ha_checks) { + verb("$ha_checks_n{$key} : $ha_checks{$key} / $$resultat{$key}"); + if ( $$resultat{$key} ne $ha_checks{$key} ) { + $ha_print .= $ha_checks_n{$key} . ":" . $$resultat{$key} . " "; + $ha_state_n=2; + } + } + #my $ha_mode = "1.3.6.1.4.1.2620.1.5.11.0"; # "Sync only" : ha Working mode + } else { + $ha_print .= "cannot find oids"; + #Critical state if not found because it means soft is not activated + $ha_state_n=2; + } + + # get ha status table + $resultat = $session->get_table( + Baseoid => $ha_tables + ); + my %status; + my (@index,@oid) = (undef,undef); + my $nindex=0; + my $index_search= $ha_tables . $ha_tables_index; + + if (defined($resultat)) { + foreach $key ( keys %$resultat) { + if ( $key =~ /$index_search/) { + @oid=split (/\./,$key); + pop(@oid); + $index[$nindex]=pop(@oid); + $nindex++; + } + } + } else { + $ha_print .= "cannot find oids" if ($ha_state_n ==0); + #Critical state if not found because it means soft is not activated + $ha_state_n=2; + } + verb ("found $nindex ha softs"); + if ( $nindex == 0 ) + { + $ha_print .= " no ha soft found" if ($ha_state_n ==0); + $ha_state_n=2; + } else { + my $ha_soft_name=undef; + + for (my $i=0;$i<$nindex;$i++) { + + $key=$ha_tables . $ha_tables_name . "." . $index[$i] . ".0"; + $ha_soft_name= $$resultat{$key}; + + $key=$ha_tables . $ha_tables_state . "." . $index[$i] . ".0"; + if (($status{$ha_soft_name} = $$resultat{$key}) ne "OK") { + $key=$ha_tables . $ha_tables_prbdesc . "." . $index[$i] . ".0"; + $status{$ha_soft_name} = $$resultat{$key}; + $ha_print .= $ha_soft_name . ":" . $status{$ha_soft_name} . " "; + $ha_state_n=2 + } + verb ("$ha_soft_name : $status{$ha_soft_name}"); + } + } + + if ($ha_state_n == 0) { + $ha_print = "HA : OK"; + } else { + $ha_print = "HA : " . $ha_print; + } + +} + +$session->close; + +########## print results and exit + +my $f_print=undef; + +if (defined ($o_fw)) { $f_print = $fw_print } +if (defined ($o_svn)) { $f_print = (defined ($f_print)) ? $f_print . " / ". $svn_print : $svn_print } +if (defined ($o_ha)) { $f_print = (defined ($f_print)) ? $f_print . " / ". $ha_print : $ha_print } +if (defined ($o_mgmt)) { $f_print = (defined ($f_print)) ? $f_print . " / ". $mgmt_print : $mgmt_print } + +my $exit_status=undef; +$f_print .= " / CPFW Status : "; +if (($ha_state_n+$svn_state+$fw_state+$mgmt_state) == 0 ) { + $f_print .= "OK"; + $exit_status= $ERRORS{"OK"}; +} else { + if (($fw_state==1) || ($ha_state_n==1) || ($svn_state==1) || ($mgmt_state==1)) { + $f_print .= "WARNING"; + $exit_status= $ERRORS{"WARNING"}; + } else { + $f_print .= "CRITICAL"; + $exit_status=$ERRORS{"CRITICAL"}; + } +} + +if (defined($o_perf) && defined ($perf_conn)) { + $f_print .= " | fw_connexions=" . $perf_conn; +} + +print "$f_print\n"; +exit $exit_status; + diff --git a/centreon-plugins/src/check_snmp_load.pl b/centreon-plugins/src/check_snmp_load.pl new file mode 100644 index 000000000..714a51e6f --- /dev/null +++ b/centreon-plugins/src/check_snmp_load.pl @@ -0,0 +1,593 @@ +#!/usr/bin/perl -w +############################## check_snmp_load ################# +# Version : 1.2 / BETA +# Date : Aug 27 2005 +# Author : Patrick Proy ( patrick at proy.org) +# Help : http://www.manubulon.com/nagios/ +# Licence : GPL - http://www.fsf.org/licenses/gpl.txt +# Changelog : HP Procurve +# TODO : +################################################################# +# +# Help : ./check_snmp_load.pl -h +# + +use strict; +use Net::SNMP; +use Getopt::Long; + +# Nagios specific + +use lib "@NAGIOS_PLUGINS@"; +use utils qw(%ERRORS $TIMEOUT); +#my $TIMEOUT = 15; +#my %ERRORS=('OK'=>0,'WARNING'=>1,'CRITICAL'=>2,'UNKNOWN'=>3,'DEPENDENT'=>4); + +# Oreon specific + + +if (eval "require oreon" ) { + use oreon qw(get_parameters create_rrd update_rrd &is_valid_serviceid); + use vars qw($VERSION %oreon); + %oreon=get_parameters(); +} else { + print "Unable to load oreon perl module\n"; + exit $ERRORS{'UNKNOWN'}; +} + +my $pathtorrdbase = $oreon{GLOBAL}{DIR_RRDTOOL}; + +# SNMP Datas + +# Generic with host-ressource-mib +my $base_proc = "1.3.6.1.2.1.25.3.3.1"; # oid for all proc info +my $proc_id = "1.3.6.1.2.1.25.3.3.1.1"; # list of processors (product ID) +my $proc_load = "1.3.6.1.2.1.25.3.3.1.2"; # %time the proc was not idle over last minute + +# Linux load + +my $linload_table= "1.3.6.1.4.1.2021.10.1"; # net-snmp load table +my $linload_name = "1.3.6.1.4.1.2021.10.1.2"; # text 'Load-1','Load-5', 'Load-15' +my $linload_load = "1.3.6.1.4.1.2021.10.1.3"; # effective load table + +# Cisco cpu/load + +my $cisco_cpu_5m = "1.3.6.1.4.1.9.2.1.58.0"; # Cisco CPU load (5min %) +my $cisco_cpu_1m = "1.3.6.1.4.1.9.2.1.57.0"; # Cisco CPU load (1min %) +my $cisco_cpu_5s = "1.3.6.1.4.1.9.2.1.56.0"; # Cisco CPU load (5sec %) + +# AS/400 CPU + +my $as400_cpu = "1.3.6.1.4.1.2.6.4.5.1.0"; # AS400 CPU load (10000=100%); + +# Net-SNMP CPU + +my $ns_cpu_idle = "1.3.6.1.4.1.2021.11.11.0"; # Net-snmp cpu idle +my $ns_cpu_user = "1.3.6.1.4.1.2021.11.9.0"; # Net-snmp user cpu usage +my $ns_cpu_system = "1.3.6.1.4.1.2021.11.10.0"; # Net-snmp system cpu usage + +# Procurve CPU +my $procurve_cpu = "1.3.6.1.4.1.11.2.14.11.5.1.9.6.1.0"; # Procurve CPU Counter + +# Nokia CPU +my $nokia_cpu = "1.3.6.1.4.1.94.1.21.1.7.1.0"; # Nokia CPU % usage + +# Bluecoat Appliance +my $bluecoat_cpu = "1.3.6.1.4.1.3417.2.4.1.1.1.4.1"; # Bluecoat %cpu usage. + +# Linkproof Appliance +my $linkproof_cpu= "1.3.6.1.4.1.89.35.1.53.0"; # Ressource utilisation (%) Considers network utilization and internal CPU utilization +# 1.3.6.1.4.1.89.35.1.54 : CPU only (%) +# 1.3.6.1.4.1.89.35.1.55 : network only (%) + +# CPU OID array +my %cpu_oid = ("netsc",$ns_cpu_idle,"as400",$as400_cpu,"bc",$bluecoat_cpu,"nokia",$nokia_cpu,"hp",$procurve_cpu,"lp",$linkproof_cpu); + +# Globals + +my $Version='1.2'; + +my $o_host = undef; # hostname +my $o_community = undef; # community +my $o_port = 161; # port +my $o_help= undef; # wan't some help ? +my $o_verb= undef; # verbose mode +my $o_version= undef; # print version +my $o_check_type= "stand"; # check type : stand | netsc | netsl | as400 | cisco | bc | nokia | hp | lp +# For backward compatibility +my $o_linux= undef; # Check linux load instead of CPU +my $o_linuxC= undef; # Check Net-SNMP CPU +my $o_as400= undef; # Check for AS 400 load +my $o_cisco= undef; # Check for Cisco CPU +# End compatibility +my $o_warn= undef; # warning level +my @o_warnL= undef; # warning levels for Linux Load or Cisco CPU +my $o_crit= undef; # critical level +my @o_critL= undef; # critical level for Linux Load or Cisco CPU +my $o_timeout= 5; # Default 5s Timeout +my $o_perf= undef; # Output performance data +my $o_version2= undef; # use snmp v2c +# SNMPv3 specific +my $o_login= undef; # Login for snmpv3 +my $o_passwd= undef; # Pass for snmpv3 +# Oreon specific +my $o_step= undef; +my $o_g= undef; +my $o_S= undef; +my $step= undef; +my $rrd= undef; +my $start= undef; +my $ServiceId= undef; + +# functions + +sub p_version { print "check_snmp_load version : $Version\n"; } + +sub print_usage { + print "Usage: $0 [-v] -H -C [-2] | (-l login -x passwd) [-p ] -w -c -T=[stand|netsl|netsc|as400|cisco|bc|nokia|hp|lp] [-f] [-t ] [-V]\n"; +} + +sub isnnum { # Return true if arg is not a number + my $num = shift; + if ( $num =~ /^(\d+\.?\d*)|(^\.\d+)$/ ) { return 0 ;} + return 1; +} + +sub help { + print "\nSNMP Load & CPU Monitor for Nagios version ",$Version,"\n"; + print "(c)2004 to my cat Ratoune - Author : Patrick Proy\n\n"; + print_usage(); + print < \$o_verb, 'verbose' => \$o_verb, + 'h' => \$o_help, 'help' => \$o_help, + 'H:s' => \$o_host, 'hostname:s' => \$o_host, + 'p:i' => \$o_port, 'port:i' => \$o_port, + 'C:s' => \$o_community, 'community:s' => \$o_community, + 'l:s' => \$o_login, 'login:s' => \$o_login, + 'x:s' => \$o_passwd, 'passwd:s' => \$o_passwd, + 't:i' => \$o_timeout, 'timeout:i' => \$o_timeout, + 'V' => \$o_version, 'version' => \$o_version, + + '2' => \$o_version2, 'v2c' => \$o_version2, + 'c:s' => \$o_crit, 'critical:s' => \$o_crit, + 'w:s' => \$o_warn, 'warn:s' => \$o_warn, + 'f' => \$o_perf, 'perfparse' => \$o_perf, + 'T:s' => \$o_check_type, 'type:s' => \$o_check_type, +# For backward compatibility + 'L' => \$o_linux, 'linux' => \$o_linux, + 'A' => \$o_as400, 'as400' => \$o_as400, + 'I' => \$o_cisco, 'cisco' => \$o_cisco, + 'N' => \$o_linuxC, 'netsnmp' => \$o_linuxC, +# For Oreon rrdtool graph + "rrd_step:s" => \$o_step, + "g" => \$o_g, "rrdgraph" => \$o_g, + "S=s" => \$o_S, "ServiceId=s" => \$o_S + ); + # For backward compat + if (defined($o_linux)) { $o_check_type="netsl" } + if (defined($o_linuxC)) { $o_check_type="netsc" } + if (defined($o_as400)) { $o_check_type="as400"} + if (defined($o_cisco)) { $o_check_type="cisco"} + # TODO : check the -T option + if (defined ($o_help) ) { help(); exit $ERRORS{"UNKNOWN"}}; + if (defined($o_version)) { p_version(); exit $ERRORS{"UNKNOWN"}}; + if ( ! defined($o_host) ) # check host and filter + { print_usage(); exit $ERRORS{"UNKNOWN"}} + # check snmp information + if ( !defined($o_community) && (!defined($o_login) || !defined($o_passwd)) ) + { print "Put snmp login info!\n"; print_usage(); exit $ERRORS{"UNKNOWN"}} + # Check warnings and critical + if (!defined($o_warn) || !defined($o_crit)) + { print "put warning and critical info!\n"; print_usage(); exit $ERRORS{"UNKNOWN"}} + # Get rid of % sign + $o_warn =~ s/\%//g; + $o_crit =~ s/\%//g; + # Check for multiple warning and crit in case of -L + if (($o_warn =~ /,/) || ($o_crit =~ /,/)) { + if (($o_check_type ne "netsl") && ($o_check_type ne "cisco")) { print "Multiple warning without -L or -I switch\n";print_usage(); exit $ERRORS{"UNKNOWN"}} + @o_warnL=split(/,/ , $o_warn); + @o_critL=split(/,/ , $o_crit); + if (($#o_warnL != 2) || ($#o_critL != 2)) + { print "3 warnings and critical !\n";print_usage(); exit $ERRORS{"UNKNOWN"}} + for (my $i=0;$i<3;$i++) { + if ( isnnum($o_warnL[$i]) || isnnum($o_critL[$i])) + { print "Numeric value for warning or critical !\n";print_usage(); exit $ERRORS{"UNKNOWN"}} + if ($o_warnL[$i] > $o_critL[$i]) + { print "warning <= critical ! \n";print_usage(); exit $ERRORS{"UNKNOWN"}} + } + } else { + if (($o_check_type eq "netsl") || ($o_check_type eq "cisco")) { print "Multiple warn and crit levels needed with -L or -I switch\n";print_usage(); exit $ERRORS{"UNKNOWN"}} + if ( isnnum($o_warn) || isnnum($o_crit) ) + { print "Numeric value for warning or critical !\n";print_usage(); exit $ERRORS{"UNKNOWN"}} + if ($o_warn > $o_crit) + { print "warning <= critical ! \n";print_usage(); exit $ERRORS{"UNKNOWN"}} + } + + ###### Oreon ####### + + if (!defined($o_S)) { $o_S="1_1" } + $ServiceId = is_valid_serviceid($o_S); + + if (!defined($o_step)) { $o_step="300" } + $step = $1 if ($o_step =~ /(\d+)/); + + +} + + + + + +########## MAIN ####### + +check_options(); + +$rrd = $pathtorrdbase.$ServiceId.".rrd"; +$start=time; + +# Check gobal timeout if snmp screws up +if (defined($TIMEOUT)) { + verb("Alarm at $TIMEOUT + 5"); + alarm($TIMEOUT+5); +} else { + verb("no timeout defined : $o_timeout + 10"); + alarm ($o_timeout+10); +} + +# Connect to host +my ($session,$error); +if ( defined($o_login) && defined($o_passwd)) { + # SNMPv3 login + verb("SNMPv3 login"); + ($session, $error) = Net::SNMP->session( + -hostname => $o_host, + -version => '3', + -username => $o_login, + -authpassword => $o_passwd, + -authprotocol => 'md5', + -privpassword => $o_passwd, + -timeout => $o_timeout + ); +} else { + if (defined ($o_version2)) { + # SNMPv2 Login + ($session, $error) = Net::SNMP->session( + -hostname => $o_host, + -version => 2, + -community => $o_community, + -port => $o_port, + -timeout => $o_timeout + ); + } else { + # SNMPV1 login + ($session, $error) = Net::SNMP->session( + -hostname => $o_host, + -community => $o_community, + -port => $o_port, + -timeout => $o_timeout + ); + } +} +if (!defined($session)) { + printf("ERROR opening session: %s.\n", $error); + exit $ERRORS{"UNKNOWN"}; +} + +my $exit_val=undef; +########### Linux load check ############## + +if ($o_check_type eq "netsl") { + +verb("Checking linux load"); +# Get load table +my $resultat = (Net::SNMP->VERSION < 4) ? + $session->get_table($linload_table) + : $session->get_table(Baseoid => $linload_table); + +if (!defined($resultat)) { + printf("ERROR: Description table : %s.\n", $session->error); + $session->close; + exit $ERRORS{"UNKNOWN"}; +} +$session->close; + +my @load = undef; +my @iload = undef; +my @oid=undef; +foreach my $key ( keys %$resultat) { + verb("OID : $key, Desc : $$resultat{$key}"); + if ( $key =~ /$linload_name/ ) { + @oid=split (/\./,$key); + $iload[0]= pop(@oid) if ($$resultat{$key} eq "Load-1"); + $iload[1]= pop(@oid) if ($$resultat{$key} eq "Load-5"); + $iload[2]= pop(@oid) if ($$resultat{$key} eq "Load-15"); + } +} + +for (my $i=0;$i<3;$i++) { $load[$i] = $$resultat{$linload_load . "." . $iload[$i]}}; + +## +## RRD management +## + +if ($o_g) { + $start=time; + if (! -e $rrd) { + create_rrd($rrd,3,$start,$step,0,"U","GAUGE"); + } + update_rrd($rrd,$start, $load[0] ,$load[1], $load[2]); +} + + +print "Load : $load[0] $load[1] $load[2] :"; + +$exit_val=$ERRORS{"OK"}; +for (my $i=0;$i<3;$i++) { + if ( $load[$i] > $o_critL[$i] ) { + print " $load[$i] > $o_critL[$i] : CRITICAL"; + $exit_val=$ERRORS{"CRITICAL"}; + } + if ( $load[$i] > $o_warnL[$i] ) { + # output warn error only if no critical was found + if ($exit_val eq $ERRORS{"OK"}) { + print " $load[$i] > $o_warnL[$i] : WARNING"; + $exit_val=$ERRORS{"WARNING"}; + } + } +} +print " OK" if ($exit_val eq $ERRORS{"OK"}); +if (defined($o_perf)) { + print " | load_1_min=$load[0];$o_warnL[0];$o_critL[0],"; + print "load_5_min=$load[1];$o_warnL[1];$o_critL[1],"; + print "load_15_min=$load[2];$o_warnL[2];$o_critL[2]\n"; +} else { + print "\n"; +} +exit $exit_val; +} + +############## Cisco CPU check ################ + +if ($o_check_type eq "cisco") { +my @oidlists = ($cisco_cpu_5m, $cisco_cpu_1m, $cisco_cpu_5s); +my $resultat = (Net::SNMP->VERSION < 4) ? + $session->get_request(@oidlists) + : $session->get_request(-varbindlist => \@oidlists); + +if (!defined($resultat)) { + printf("ERROR: Description table : %s.\n", $session->error); + $session->close; + exit $ERRORS{"UNKNOWN"}; +} + +$session->close; + +if (!defined ($$resultat{$cisco_cpu_5s})) { + print "No CPU information : UNKNOWN\n"; + exit $ERRORS{"UNKNOWN"}; +} + +my @load = undef; + +$load[0]=$$resultat{$cisco_cpu_5s}; +$load[1]=$$resultat{$cisco_cpu_1m}; +$load[2]=$$resultat{$cisco_cpu_5m}; + +## +## RRD management +## + +if ($o_g) { + $start=time; + if (! -e $rrd) { + create_rrd($rrd,3,$start,$step,0,"U","GAUGE"); + } + update_rrd($rrd,$start,$load[0] ,$load[1], $load[2]); +} + +print "CPU : $load[0] $load[1] $load[2] :"; + +$exit_val=$ERRORS{"OK"}; +for (my $i=0;$i<3;$i++) { + if ( $load[$i] > $o_critL[$i] ) { + print " $load[$i] > $o_critL[$i] : CRITICAL"; + $exit_val=$ERRORS{"CRITICAL"}; + } + if ( $load[$i] > $o_warnL[$i] ) { + # output warn error only if no critical was found + if ($exit_val eq $ERRORS{"OK"}) { + print " $load[$i] > $o_warnL[$i] : WARNING"; + $exit_val=$ERRORS{"WARNING"}; + } + } +} +print " OK" if ($exit_val eq $ERRORS{"OK"}); +if (defined($o_perf)) { + print " | load_5_sec=$load[0]%;$o_warnL[0];$o_critL[0],"; + print "load_1_min=$load[1]%;$o_warnL[1];$o_critL[1],"; + print "load_5_min=$load[2]%;$o_warnL[2];$o_critL[2]\n"; +} else { + print "\n"; +} + +exit $exit_val; +} + +################## CPU for : AS/400 , Netsnmp, HP, Bluecoat, linkproof ########### +if ( $o_check_type =~ /netsc|as400|bc|nokia|hp|lp/ ) { + +# Get load table +my @oidlist = $cpu_oid{$o_check_type}; +verb("Checking OID : @oidlist"); +my $resultat = (Net::SNMP->VERSION < 4) ? + $session->get_request(@oidlist) + : $session->get_request(-varbindlist => \@oidlist); +if (!defined($resultat)) { + printf("ERROR: Description table : %s.\n", $session->error); + $session->close; + exit $ERRORS{"UNKNOWN"}; +} +$session->close; + +if (!defined ($$resultat{$cpu_oid{$o_check_type}})) { + print "No CPU information : UNKNOWN\n"; + exit $ERRORS{"UNKNOWN"}; +} + +my $load=$$resultat{$cpu_oid{$o_check_type}}; +verb("OID returned $load"); +# for AS400, divide by 100 +if ($o_check_type eq "as400") {$load /= 100; }; +# for Net-snmp : oid returned idle time so load = 100-idle. +if ($o_check_type eq "netsc") {$load = 100 - $load; }; + +## +## RRD management +## + +if ($o_g) { + $start=time; + if (! -e $rrd) { + create_rrd($rrd,1,$start,$step,0,"U","GAUGE"); + } + update_rrd($rrd,$start,$load); +} + + +printf("CPU used %.1f%% (",$load); + +$exit_val=$ERRORS{"OK"}; +if ($load > $o_crit) { + print ">$o_crit) : CRITICAL"; + $exit_val=$ERRORS{"CRITICAL"}; +} else { + if ($load > $o_warn) { + print ">$o_warn) : WARNING"; + $exit_val=$ERRORS{"WARNING"}; + } +} +print "<$o_warn) : OK" if ($exit_val eq $ERRORS{"OK"}); +(defined($o_perf)) ? + print " | cpu_prct_used=$load%;$o_warn;$o_crit\n" + : print "\n"; +exit $exit_val; + +} + +########## Standard cpu usage check ############ +# Get desctiption table +my $resultat = (Net::SNMP->VERSION < 4) ? + $session->get_table($base_proc) + : $session->get_table(Baseoid => $base_proc); + +if (!defined($resultat)) { + printf("ERROR: Description table : %s.\n", $session->error); + $session->close; + exit $ERRORS{"UNKNOWN"}; +} + +$session->close; + +my ($cpu_used,$ncpu)=(0,0); +foreach my $key ( keys %$resultat) { + verb("OID : $key, Desc : $$resultat{$key}"); + if ( $key =~ /$proc_load/) { + $cpu_used += $$resultat{$key}; + $ncpu++; + } +} + +if ($ncpu==0) { + print "Can't find CPU usage information : UNKNOWN\n"; + exit $ERRORS{"UNKNOWN"}; +} + +$cpu_used /= $ncpu; + +## +## RRD management +## + +if ($o_g) { + $start=time; + if (! -e $rrd) { + create_rrd($rrd,1,$start,$step,0,"U","GAUGE"); + } + update_rrd($rrd,$start,$cpu_used); +} + +print "$ncpu CPU, ", $ncpu==1 ? "load" : "average load"; +printf(" %.1f",$cpu_used); +$exit_val=$ERRORS{"OK"}; + +if ($cpu_used > $o_crit) { + print " > $o_crit : CRITICAL"; + $exit_val=$ERRORS{"CRITICAL"}; +} else { + if ($cpu_used > $o_warn) { + print " > $o_warn : WARNING"; + $exit_val=$ERRORS{"WARNING"}; + } +} +print " < $o_warn : OK" if ($exit_val eq $ERRORS{"OK"}); +(defined($o_perf)) ? + print " | cpu_prct_used=$cpu_used%;$o_warn;$o_crit\n" + : print "\n"; +exit $exit_val; + diff --git a/centreon-plugins/src/check_snmp_mem.pl b/centreon-plugins/src/check_snmp_mem.pl new file mode 100644 index 000000000..ed93c641b --- /dev/null +++ b/centreon-plugins/src/check_snmp_mem.pl @@ -0,0 +1,543 @@ +#!/usr/bin/perl -w +############################## check_snmp_mem ############## +# Version : 0.9 +# Date : Jul 20 2005 +# Author : Patrick Proy (patrick at proy.org) +# Help : http://www.manubulon.com/nagios/ +# Licence : GPL - http://www.fsf.org/licenses/gpl.txt +# TODO : snmpv3 +################################################################# +# +# Help : ./check_snmp_mem.pl -h +# + +use strict; +use Net::SNMP; +use Getopt::Long; + +# Nagios specific + +use lib "@NAGIOS_PLUGINS@"; +use utils qw(%ERRORS $TIMEOUT); +#my $TIMEOUT = 15; +#my %ERRORS=('OK'=>0,'WARNING'=>1,'CRITICAL'=>2,'UNKNOWN'=>3,'DEPENDENT'=>4); + +# Oreon specific + +#use lib "@NAGIOS_PLUGINS@"; +if (eval "require oreon" ) { + use oreon qw(get_parameters create_rrd update_rrd &is_valid_serviceid); + use vars qw($VERSION %oreon); + %oreon=get_parameters(); +} else { + print "Unable to load oreon perl module\n"; + exit $ERRORS{'UNKNOWN'}; +} + +my $pathtorrdbase = $oreon{GLOBAL}{DIR_RRDTOOL}; + +# SNMP Datas + +# Net-snmp memory + +my $nets_ram_free = "1.3.6.1.4.1.2021.4.6.0"; # Real memory free +my $nets_ram_total = "1.3.6.1.4.1.2021.4.5.0"; # Real memory total +my $nets_swap_free = "1.3.6.1.4.1.2021.4.4.0"; # swap memory free +my $nets_swap_total = "1.3.6.1.4.1.2021.4.3.0"; # Swap memory total +my @nets_oids = ($nets_ram_free,$nets_ram_total,$nets_swap_free,$nets_swap_total); + +# Cisco + +my $cisco_mem_pool = "1.3.6.1.4.1.9.9.48.1.1.1"; # Cisco memory pool +my $cisco_index = "1.3.6.1.4.1.9.9.48.1.1.1.2"; # memory pool name and index +my $cisco_valid = "1.3.6.1.4.1.9.9.48.1.1.1.4"; # Valid memory if 1 +my $cisco_used = "1.3.6.1.4.1.9.9.48.1.1.1.5"; # Used memory +my $cisco_free = "1.3.6.1.4.1.9.9.48.1.1.1.6"; # Used memory +# .1 : type, .2 : name, .3 : alternate, .4 : valid, .5 : used, .6 : free, .7 : max free + +# HP Procurve + +my $hp_mem_pool = "1.3.6.1.4.1.11.2.14.11.5.1.1.2.2.1.1"; # HP memory pool +my $hp_mem_index = "1.3.6.1.4.1.11.2.14.11.5.1.1.2.2.1.1.1"; # memory slot index +my $hp_mem_total = "1.3.6.1.4.1.11.2.14.11.5.1.1.2.2.1.1.5"; # Total Bytes +my $hp_mem_free = "1.3.6.1.4.1.11.2.14.11.5.1.1.2.2.1.1.6"; # Free Bytes +my $hp_mem_free_seg = "1.3.6.1.4.1.11.2.14.11.5.1.1.2.2.1.1.3"; # Free segments + +# AS/400 + +# Windows NT/2K/(XP?) + +# check_snmp_storage.pl -C -H -m "^Virtual Memory$" -w -c + + +# Globals + +my $Version='0.9'; + +my $o_host = undef; # hostname +my $o_community = undef; # community +my $o_port = 161; # port +my $o_help= undef; # wan't some help ? +my $o_verb= undef; # verbose mode +my $o_version= undef; # print version +my $o_netsnmp= 1; # Check with netsnmp (default) +my $o_cisco= undef; # Check cisco router mem +my $o_hp= undef; # Check hp procurve mem +my $o_warn= undef; # warning level option +my $o_warnR= undef; # warning level for Real memory +my $o_warnS= undef; # warning levels for swap +my $o_crit= undef; # Critical level option +my $o_critR= undef; # critical level for Real memory +my $o_critS= undef; # critical level for swap +my $o_perf= undef; # Performance data option +my $o_timeout= 5; # Default 5s Timeout +my $o_version2= undef; # use snmp v2c +# SNMPv3 specific +my $o_login= undef; # Login for snmpv3 +my $o_passwd= undef; # Pass for snmpv3 + +# Oreon specific +my $o_step= undef; +my $o_g= undef; +my $o_S= undef; +my $step= undef; +my $rrd= undef; +my $start= undef; +my $ServiceId= undef; + + +# functions + +sub p_version { print "check_snmp_mem version : $Version\n"; } + +sub print_usage { + print "Usage: $0 [-v] -H -C [-2] | (-l login -x passwd) [-p ] -w -c [-I|-N|-E] [-f] [-t ] [-V]\n"; +} + +sub isnnum { # Return true if arg is not a number + my $num = shift; + if ( $num =~ /^(\d+\.?\d*)|(^\.\d+)$/ ) { return 0 ;} + return 1; +} + +sub round ($$) { + sprintf "%.$_[1]f", $_[0]; +} + +sub help { + print "\nSNMP Memory Monitor for Nagios version ",$Version,"\n"; + print "(c)2004 to my cat Ratoune - Author: Patrick Proy\n\n"; + print_usage(); + print < \$o_verb, 'verbose' => \$o_verb, + 'h' => \$o_help, 'help' => \$o_help, + 'H:s' => \$o_host, 'hostname:s' => \$o_host, + 'p:i' => \$o_port, 'port:i' => \$o_port, + 'C:s' => \$o_community, 'community:s' => \$o_community, + 'l:s' => \$o_login, 'login:s' => \$o_login, + 'x:s' => \$o_passwd, 'passwd:s' => \$o_passwd, + 't:i' => \$o_timeout, 'timeout:i' => \$o_timeout, + 'V' => \$o_version, 'version' => \$o_version, + 'I' => \$o_cisco, 'cisco' => \$o_cisco, + 'N' => \$o_netsnmp, 'netsnmp' => \$o_netsnmp, + 'E' => \$o_hp, 'hp' => \$o_hp, + '2' => \$o_version2, 'v2c' => \$o_version2, + 'c:s' => \$o_crit, 'critical:s' => \$o_crit, + 'w:s' => \$o_warn, 'warn:s' => \$o_warn, + 'f' => \$o_perf, 'perfdata' => \$o_perf, +# For Oreon rrdtool graph + "rrd_step:s" => \$o_step, + "g" => \$o_g, "rrdgraph" => \$o_g, + "S=s" => \$o_S, "ServiceId=s" => \$o_S + ); + if (defined ($o_help) ) { help(); exit $ERRORS{"UNKNOWN"}}; + if (defined($o_version)) { p_version(); exit $ERRORS{"UNKNOWN"}}; + if ( ! defined($o_host) ) # check host and filter + { print "No host defined!\n";print_usage(); exit $ERRORS{"UNKNOWN"}} + # check snmp information + if ( !defined($o_community) && (!defined($o_login) || !defined($o_passwd)) ) + { print "Put snmp login info!\n"; print_usage(); exit $ERRORS{"UNKNOWN"}} + #Check Warning and crit are present + if ( ! defined($o_warn) || ! defined($o_crit)) + { print "Put warning and critical values!\n"; print_usage(); exit $ERRORS{"UNKNOWN"}} + # Get rid of % sign + $o_warn =~ s/\%//g; + $o_crit =~ s/\%//g; + # if -N or -E switch , undef $o_netsnmp + if (defined($o_cisco) || defined($o_hp) ) { + $o_netsnmp=undef; + if ( isnnum($o_warn) || isnnum($o_crit)) + { print "Numeric value for warning or critical !\n";print_usage(); exit $ERRORS{"UNKNOWN"} } + if ( ($o_crit != 0) && ($o_warn > $o_crit) ) + { print "warning <= critical ! \n";print_usage(); exit $ERRORS{"UNKNOWN"}} + } + if (defined($o_netsnmp)) { + my @o_warnL=split(/,/ , $o_warn); + my @o_critL=split(/,/ , $o_crit); + if (($#o_warnL != 1) || ($#o_critL != 1)) + { print "2 warnings and critical !\n";print_usage(); exit $ERRORS{"UNKNOWN"}} + for (my $i=0;$i<2;$i++) { + if ( isnnum($o_warnL[$i]) || isnnum($o_critL[$i])) + { print "Numeric value for warning or critical !\n";print_usage(); exit $ERRORS{"UNKNOWN"} } + if (($o_critL[$i]!= 0) && ($o_warnL[$i] > $o_critL[$i])) + { print "warning <= critical ! \n";print_usage(); exit $ERRORS{"UNKNOWN"}} + if ( $o_critL[$i] > 100) + { print "critical percent must be < 100 !\n";print_usage(); exit $ERRORS{"UNKNOWN"}} + } + $o_warnR=$o_warnL[0];$o_warnS=$o_warnL[1]; + $o_critR=$o_critL[0];$o_critS=$o_critL[1]; + } + + ###### Oreon ####### + + if (!defined($o_S)) { $o_S="1_1" } + $ServiceId = is_valid_serviceid($o_S); + + if (!defined($o_step)) { $o_step="300" } + $step = $1 if ($o_step =~ /(\d+)/); + +} + +########## MAIN ####### + +check_options(); + +$rrd = $pathtorrdbase.$ServiceId.".rrd"; +$start=time; + +# Check gobal timeout if snmp screws up +if (defined($TIMEOUT)) { + verb("Alarm at $TIMEOUT"); + alarm($TIMEOUT); +} else { + verb("no timeout defined : $o_timeout + 10"); + alarm ($o_timeout+10); +} + +# Connect to host +my ($session,$error); +if ( defined($o_login) && defined($o_passwd)) { + # SNMPv3 login + verb("SNMPv3 login"); + ($session, $error) = Net::SNMP->session( + -hostname => $o_host, + -version => '3', + -username => $o_login, + -authpassword => $o_passwd, + -authprotocol => 'md5', + -privpassword => $o_passwd, + -timeout => $o_timeout + ); +} else { + if (defined ($o_version2)) { + # SNMPv2 Login + ($session, $error) = Net::SNMP->session( + -hostname => $o_host, + -version => 2, + -community => $o_community, + -port => $o_port, + -timeout => $o_timeout + ); + } else { + + # SNMPV1 login + ($session, $error) = Net::SNMP->session( + -hostname => $o_host, + -community => $o_community, + -port => $o_port, + -timeout => $o_timeout + ); + } +} +if (!defined($session)) { + printf("ERROR opening session: %s.\n", $error); + exit $ERRORS{"UNKNOWN"}; +} + +# Global variable +my $resultat=undef; + +########### Cisco memory check ############ +if (defined ($o_cisco)) { + + # Get Cisco memory table + $resultat = (Net::SNMP->VERSION < 4) ? + $session->get_table($cisco_mem_pool) + :$session->get_table(Baseoid => $cisco_mem_pool); + + if (!defined($resultat)) { + printf("ERROR: Description table : %s.\n", $session->error); + $session->close; + exit $ERRORS{"UNKNOWN"}; + } + my (@oid,@index)=(undef,undef); + my $nindex=0; + foreach my $key ( keys %$resultat) { + verb("OID : $key, Desc : $$resultat{$key}"); + if ( $key =~ /$cisco_index/ ) { + @oid=split (/\./,$key); + $index[$nindex++] = pop(@oid); + } + } + + # Check if at least 1 memory pool exists + if ($nindex == 0) { + printf("ERROR: No memory pools found"); + $session->close; + exit $ERRORS{"UNKNOWN"}; + } + + # Consolidate the datas + my ($used,$free)=(0,0); + my ($c_output,$prct_free)=(undef,undef); + foreach (@index) { + if ( $$resultat{$cisco_valid . "." . $_} == 1 ) { + $c_output .="," if defined ($c_output); + $used += $$resultat{$cisco_used . "." . $_}; + $free += $$resultat{$cisco_free . "." . $_}; + $c_output .= $$resultat{$cisco_index . "." . $_} . ":" + .round($$resultat{$cisco_used . "." . $_}*100/($$resultat{$cisco_free . "." . $_}+$$resultat{$cisco_used . "." . $_}) ,0) + . "%"; + } + } + my $total=$used+$free; + $prct_free=round($used*100/($total),0); + verb("Used : $used, Free: $free, Output : $c_output"); + + ## + ## RRD management + ## + + if ($o_g) { + $start=time; + if (! -e $rrd) { + create_rrd($rrd,1,$start,$step,0,100,"GAUGE"); + } + update_rrd($rrd,$start,$prct_free); + } + + my $c_status="OK"; + $c_output .=" : " . $prct_free ."% : "; + if (($o_crit!=0)&&($o_crit <= $prct_free)) { + $c_output .= " > " . $o_crit ; + $c_status="CRITICAL"; + } else { + if (($o_warn!=0)&&($o_warn <= $prct_free)) { + $c_output.=" > " . $o_warn; + $c_status="WARNING"; + } + } + $c_output .= " ; ".$c_status; + if (defined ($o_perf)) { + $c_output .= " | ram_used=" . $used.";"; + $c_output .= ($o_warn ==0)? ";" : round($o_warn * $total/100,0).";"; + $c_output .= ($o_crit ==0)? ";" : round($o_crit * $total/100,0).";"; + $c_output .= "0;" . $total ; + } + $session->close; + print "$c_output \n"; + exit $ERRORS{$c_status}; +} + +########### HP Procurve memory check ############ +if (defined ($o_hp)) { + + # Get hp memory table + $resultat = (Net::SNMP->VERSION < 4) ? + $session->get_table($hp_mem_pool) + :$session->get_table(Baseoid => $hp_mem_pool); + + if (!defined($resultat)) { + printf("ERROR: Description table : %s.\n", $session->error); + $session->close; + exit $ERRORS{"UNKNOWN"}; + } + my (@oid,@index)=(undef,undef); + my $nindex=0; + foreach my $key ( keys %$resultat) { + verb("OID : $key, Desc : $$resultat{$key}"); + if ( $key =~ /$hp_mem_index/ ) { + @oid=split (/\./,$key); + $index[$nindex++] = pop(@oid); + } + } + + # Check if at least 1 memory slots exists + if ($nindex == 0) { + printf("ERROR: No memory slots found"); + $session->close; + exit $ERRORS{"UNKNOWN"}; + } + + # Consolidate the datas + my ($total,$free)=(0,0); + my ($c_output,$prct_free)=(undef,undef); + foreach (@index) { + $c_output .="," if defined ($c_output); + $total += $$resultat{$hp_mem_total . "." . $_}; + $free += $$resultat{$hp_mem_free . "." . $_}; + $c_output .= "Slot " . $$resultat{$hp_mem_index . "." . $_} . ":" + .round( + 100 - ($$resultat{$hp_mem_free . "." . $_} *100 / + $$resultat{$hp_mem_total . "." . $_}) ,0) + . "%"; + } + my $used = $total - $free; + $prct_free=round($used*100/($total),0); + verb("Used : $used, Free: $free, Output : $c_output"); + + ## + ## RRD management + ## + + if ($o_g) { + $start=time; + if (! -e $rrd) { + create_rrd($rrd,1,$start,$step,0,100,"GAUGE"); + } + update_rrd($rrd,$start,$prct_free); + } + + my $c_status="OK"; + $c_output .=" : " . $prct_free ."% : "; + if (($o_crit!=0)&&($o_crit <= $prct_free)) { + $c_output .= " > " . $o_crit ; + $c_status="CRITICAL"; + } else { + if (($o_warn!=0)&&($o_warn <= $prct_free)) { + $c_output.=" > " . $o_warn; + $c_status="WARNING"; + } + } + $c_output .= " ; ".$c_status; + if (defined ($o_perf)) { + $c_output .= " | ram_used=" . $used.";"; + $c_output .= ($o_warn ==0)? ";" : round($o_warn * $total/100,0).";"; + $c_output .= ($o_crit ==0)? ";" : round($o_crit * $total/100,0).";"; + $c_output .= "0;" . $total ; + } + $session->close; + print "$c_output \n"; + exit $ERRORS{$c_status}; +} + +########### Net snmp memory check ############ +if (defined ($o_netsnmp)) { + + # Get NetSNMP memory values + $resultat = (Net::SNMP->VERSION < 4) ? + $session->get_request(@nets_oids) + :$session->get_request(-varbindlist => \@nets_oids); + + if (!defined($resultat)) { + printf("ERROR: netsnmp : %s.\n", $session->error); + $session->close; + exit $ERRORS{"UNKNOWN"}; + } + + my ($realused,$swapused)=(undef,undef); + + $realused= ($$resultat{$nets_ram_total} == 0) ? 0 : + ($$resultat{$nets_ram_total}-$$resultat{$nets_ram_free})/$$resultat{$nets_ram_total}; + $swapused= ($$resultat{$nets_swap_total} == 0) ? 0 : + ($$resultat{$nets_swap_total}-$$resultat{$nets_swap_free})/$$resultat{$nets_swap_total}; + $realused=round($realused*100,0); + $swapused=round($swapused*100,0); + verb ("Ram : $$resultat{$nets_ram_free} / $$resultat{$nets_ram_total} : $realused"); + verb ("Swap : $$resultat{$nets_swap_free} / $$resultat{$nets_swap_total} : $swapused"); + + ## + ## RRD management + ## + + if ($o_g) { + $start=time; + if (! -e $rrd) { + create_rrd($rrd,2,$start,$step,0,100,"GAUGE"); + } + update_rrd($rrd,$start,$realused, $swapused ); + } + + + + my $n_status="OK"; + my $n_output="Ram : " . $realused . "%, Swap : " . $swapused . "% :"; + if ((($o_critR!=0)&&($o_critR <= $realused)) || (($o_critS!=0)&&($o_critS <= $swapused))) { + $n_output .= " > " . $o_critR . ", " . $o_critS; + $n_status="CRITICAL"; + } else { + if ((($o_warnR!=0)&&($o_warnR <= $realused)) || (($o_warnS!=0)&&($o_warnS <= $swapused))) { + $n_output.=" > " . $o_warnR . ", " . $o_warnS; + $n_status="WARNING"; + } + } + $n_output .= " ; ".$n_status; + if (defined ($o_perf)) { + $n_output .= " | ram_used=" . ($$resultat{$nets_ram_total}-$$resultat{$nets_ram_free}).";"; + $n_output .= ($o_warnR ==0)? ";" : round($o_warnR * $$resultat{$nets_ram_total}/100,0).";"; + $n_output .= ($o_critR ==0)? ";" : round($o_critR * $$resultat{$nets_ram_total}/100,0).";"; + $n_output .= "0;" . $$resultat{$nets_ram_total}. " "; + $n_output .= "swap_used=" . ($$resultat{$nets_swap_total}-$$resultat{$nets_swap_free}).";"; + $n_output .= ($o_warnS ==0)? ";" : round($o_warnS * $$resultat{$nets_swap_total}/100,0).";"; + $n_output .= ($o_critS ==0)? ";" : round($o_critS * $$resultat{$nets_swap_total}/100,0).";"; + $n_output .= "0;" . $$resultat{$nets_swap_total}; + } + $session->close; + print "$n_output \n"; + exit $ERRORS{$n_status}; + +} diff --git a/centreon-plugins/src/check_snmp_process.pl b/centreon-plugins/src/check_snmp_process.pl new file mode 100644 index 000000000..41d4bfde3 --- /dev/null +++ b/centreon-plugins/src/check_snmp_process.pl @@ -0,0 +1,602 @@ +#!/usr/bin/perl -w +############################## check_snmp_process ############## +# Version : 1.2.1 +# Date : Dec 12 2004 +# Author : Patrick Proy (patrick at proy.org) +# Help : http://www.manubulon.com/nagios/ +# Licence : GPL - http://www.fsf.org/licenses/gpl.txt +# TODO : put $o_delta as an option +############################################################### +# +# help : ./check_snmp_process -h + +############### BASE DIRECTORY FOR TEMP FILE ######## +my $o_base_dir="/tmp/tmp_Nagios_proc."; +my $file_history=200; # number of data to keep in files. +my $delta_of_time_to_make_average=300; # 5minutes by default + +use strict; +use Net::SNMP; +use Getopt::Long; + +# Nagios specific + +use lib "@NAGIOS_PLUGINS@"; +use utils qw(%ERRORS $TIMEOUT); +#my $TIMEOUT = 5; +#my %ERRORS=('OK'=>0,'WARNING'=>1,'CRITICAL'=>2,'UNKNOWN'=>3,'DEPENDENT'=>4); + +# Oreon specific + +#use lib "@NAGIOS_PLUGINS@"; +if (eval "require oreon" ) { + use oreon qw(get_parameters create_rrd update_rrd &is_valid_serviceid); + use vars qw($VERSION %oreon); + %oreon=get_parameters(); +} else { + print "Unable to load oreon perl module\n"; + exit $ERRORS{'UNKNOWN'}; +} + +my $pathtorrdbase = $oreon{GLOBAL}{DIR_RRDTOOL}; + + +# SNMP Datas +my $process_table= '1.3.6.1.2.1.25.4.2.1'; +my $index_table = '1.3.6.1.2.1.25.4.2.1.1'; +my $run_name_table = '1.3.6.1.2.1.25.4.2.1.2'; +my $run_path_table = '1.3.6.1.2.1.25.4.2.1.4'; +my $proc_mem_table = '1.3.6.1.2.1.25.5.1.1.2'; # Kbytes +my $proc_cpu_table = '1.3.6.1.2.1.25.5.1.1.1'; # Centi sec of CPU +my $proc_run_state = '1.3.6.1.2.1.25.4.2.1.7'; + +# Globals + +my $Version='1.2.1'; + +my $o_host = undef; # hostname +my $o_community =undef; # community +my $o_port = 161; # port +my $o_descr = undef; # description filter +my $o_warn = 0; # warning limit +my @o_warnL= undef; # warning limits (min,max) +my $o_crit= 0; # critical limit +my @o_critL= undef; # critical limits (min,max) +my $o_help= undef; # wan't some help ? +my $o_verb= undef; # verbose mode +my $o_version= undef; # print version +my $o_noreg= undef; # Do not use Regexp for name +my $o_path= undef; # check path instead of name +my $o_inverse= undef; # checks max instead of min number of process +my $o_timeout= 5; # Default 5s Timeout +# SNMP V3 specific +my $o_login= undef; # snmp v3 login +my $o_passwd= undef; # snmp v3 passwd +# Memory & CPU +my $o_mem= undef; # checks memory (max) +my @o_memL= undef; # warn and crit level for mem +my $o_mem_avg= undef; # cheks memory average +my $o_cpu= undef; # checks CPU usage +my @o_cpuL= undef; # warn and crit level for cpu +my $o_delta= $delta_of_time_to_make_average; # delta time for CPU check +# Oreon specific +my $o_step= undef; +my $o_g= undef; +my $o_S= undef; +my $step= undef; +my $rrd= undef; +my $start= undef; +my $ServiceId= undef; +my @rrd_data= undef; + +# functions + +sub p_version { print "check_snmp_process version : $Version\n"; } + +sub print_usage { + print "Usage: $0 [-v] -H -C | (-l login -x passwd) [-p ] -n [-w [,] -c [,max_proc] ] [-m, -a -u, ] [-t ] [-f ] [-r] [-V]\n"; +} + +sub isnotnum { # Return true if arg is not a number + my $num = shift; + if ( $num =~ /^(\d+\.?\d*)|(^\.\d+)$/ ) { return 0 ;} + return 1; +} + +# Get the alarm signal (just in case snmp timout screws up) +$SIG{'ALRM'} = sub { + print ("ERROR: Alarm signal (Nagios time-out)\n"); + exit $ERRORS{"UNKNOWN"}; +}; + +sub read_file { + # Input : File, items_number + # Returns : array of value : [line][item] + my ($traffic_file,$items_number)=@_; + my ($ligne,$n_rows)=(undef,0); + my (@last_values,@file_values,$i); + open(FILE,"<".$traffic_file) || return (1,0,0); + + while($ligne = ) + { + chomp($ligne); + @file_values = split(":",$ligne); + #verb("@file_values"); + if ($#file_values >= ($items_number-1)) { + # check if there is enough data, else ignore line + for ( $i=0 ; $i< $items_number ; $i++ ) {$last_values[$n_rows][$i]=$file_values[$i]; } + $n_rows++; + } + } + close FILE; + if ($n_rows != 0) { + return (0,$n_rows,@last_values); + } else { + return (1,0,0); + } +} + +sub write_file { + # Input : file , rows, items, array of value : [line][item] + # Returns : 0 / OK, 1 / error + my ($file_out,$rows,$item,@file_values)=@_; + my $start_line= ($rows > $file_history) ? $rows - $file_history : 0; + if ( open(FILE2,">".$file_out) ) { + for (my $i=$start_line;$i<$rows;$i++) { + for (my $j=0;$j<$item;$j++) { + print FILE2 $file_values[$i][$j]; + if ($j != ($item -1)) { print FILE2 ":" }; + } + print FILE2 "\n"; + } + close FILE2; + return 0; + } else { + return 1; + } +} + +sub help { + print "\nSNMP Process Monitor for Nagios version ",$Version,"\n"; + print "(c)2004 to my cat Ratoune - Author: Patrick Proy\n\n"; + print_usage(); + print < 100% : 100%=1 CPU +-t, --timeout=INTEGER + timeout for SNMP in seconds (Default: 5) +-V, --version + prints version number +-g (--rrdgraph) Create a rrd base if necessary and add datas into this one +--rrd_step Specifies the base interval in seconds with which data will be fed into the RRD (300 by default) +-S (--ServiceId) Oreon Service Id + +Note : + CPU usage is in % of one cpu, so maximum can be 100% * number of CPU + example : + Browse process list :