From 45ed2a95ee655dec10bdb1d22eb0afe8341a7947 Mon Sep 17 00:00:00 2001 From: Mat Sugumaran Date: Thu, 13 Sep 2007 08:27:15 +0000 Subject: [PATCH] new plugins git-svn-id: http://svn.centreon.com/Plugins/Dev@3116 6bcd3966-0018-0410-8128-fd23d134de7e --- src/check_centreon_MS_multiple_services | 247 +++++++++++++++++++++ src/check_centreon_snmp_multiple_process | 253 +++++++++++++++++++++ src/check_centreon_snmp_multiple_process2 | 255 ++++++++++++++++++++++ 3 files changed, 755 insertions(+) create mode 100644 src/check_centreon_MS_multiple_services create mode 100644 src/check_centreon_snmp_multiple_process create mode 100644 src/check_centreon_snmp_multiple_process2 diff --git a/src/check_centreon_MS_multiple_services b/src/check_centreon_MS_multiple_services new file mode 100644 index 000000000..d367e06fe --- /dev/null +++ b/src/check_centreon_MS_multiple_services @@ -0,0 +1,247 @@ +#! /usr/bin/perl -w +################################################################### +# Oreon is developped with GPL Licence 2.0 +# +# GPL License: http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt +# +# Developped by : Julien Mathis - Romain Le Merlus +# Christophe Coraboeuf - Sugumaran Mathavarajan +# +################################################################### +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License +# as published by the Free Software Foundation; either version 2 +# of the License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# For information : contact@merethis.com +#################################################################### +# +# Script init +# + +use strict; +use Net::SNMP qw(:snmp oid_lex_sort); +use FindBin; +use lib "$FindBin::Bin"; +use lib "/srv/nagios/libexec"; +use utils qw($TIMEOUT %ERRORS &print_revision &support); +if (eval "require oreon" ) { + use oreon qw(get_parameters); + 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_v $opt_C $opt_p $opt_H $opt_n $opt_k $opt_u $opt_x $result @result %process_list %STATUS); + +# Plugin var init + +my($proc, $proc_run); + +$PROGNAME = $0; +sub print_help (); +sub print_usage (); + +%STATUS=(1=>'running',2=>'runnable',3=>'notRunnable',4=>'invalid'); + +Getopt::Long::Configure('bundling'); +GetOptions + ("h" => \$opt_h, "help" => \$opt_h, + "u=s" => \$opt_u, "username=s" => \$opt_u, + "x=s" => \$opt_x, "password=s" => \$opt_x, + "k=s" => \$opt_k, "key=s" => \$opt_k, + "V" => \$opt_V, "version" => \$opt_V, + "n" => \$opt_n, "number" => \$opt_n, + "v=s" => \$opt_v, "snmp=s" => \$opt_v, + "C=s" => \$opt_C, "community=s" => \$opt_C, + "p=s" => \$opt_p, "process=s" => \$opt_p, + "H=s" => \$opt_H, "hostname=s" => \$opt_H); + +if ($opt_V) { + print_revision($PROGNAME,'$Revision: 1.2 $'); + exit $ERRORS{'OK'}; +} + +if ($opt_h) { + print_help(); + exit $ERRORS{'OK'}; +} + +if (!$opt_H) { + print_usage(); + exit $ERRORS{'OK'}; +} +my $snmp = "1"; +$snmp = $opt_v if ($opt_v && $opt_v =~ /^[0-9]$/); + +if ($snmp eq "3") { + if (!$opt_u) { + print "Option -u (--username) is required for snmpV3\n"; + exit $ERRORS{'OK'}; + } + if (!$opt_x && !$opt_k) { + print "Option -k (--key) or -x (--password) is required for snmpV3\n"; + exit $ERRORS{'OK'}; + } elsif ($opt_x && $opt_k) { + print "Only option -k (--key) or -x (--password) is needed for snmpV3\n"; + exit $ERRORS{'OK'}; + } +} + +$opt_C = "public" if (!$opt_C); + +my $process; +if(!$opt_p) { + print_usage(); + exit $ERRORS{'OK'}; +} elsif ($opt_p !~ /([-.A-Za-z0-9\,]+)/){ + print_usage(); + exit $ERRORS{'OK'}; +} +$process = $opt_p; +my @process_temp = split /\,/,$opt_p; +my (@proc,@status); +foreach (@process_temp) { +$status[scalar(@status)] = 0; +$proc[scalar(@proc)] = $_; +} +my $name = $0; + +# Plugin snmp requests +my $OID_SW_ServiceName = "1.3.6.1.4.1.77.1.2.3.1.1"; +my $OID_SW_ServiceInstallStatus = "1.3.6.1.4.1.77.1.2.3.1.2"; +my $OID_SW_ServiceStatus = "1.3.6.1.4.1.77.1.2.3.1.3"; + +my ($session, $error); +if ($snmp eq "1" || $snmp eq "2") { + ($session, $error) = Net::SNMP->session(-hostname => $opt_H, -community => $opt_C, -version => $snmp); + if (!defined($session)) { + print("UNKNOWN: SNMP Session : $error\n"); + exit $ERRORS{'UNKNOWN'}; + } +} elsif ($opt_k) { + ($session, $error) = Net::SNMP->session(-hostname => $opt_H, -version => $snmp, -username => $opt_u, -authkey => $opt_k); + if (!defined($session)) { + print("UNKNOWN: SNMP Session : $error\n"); + exit $ERRORS{'UNKNOWN'}; + } +} elsif ($opt_x) { + ($session, $error) = Net::SNMP->session(-hostname => $opt_H, -version => $snmp, -username => $opt_u, -authpassword => $opt_x); + if (!defined($session)) { + print("UNKNOWN: SNMP Session : $error\n"); + exit $ERRORS{'UNKNOWN'}; + } +} +$result = $session->get_table(Baseoid => $OID_SW_ServiceName); +if (!defined($result)) { + printf("UNKNOWN: %s.\n", $session->error); + $session->close; + exit $ERRORS{'UNKNOWN'}; +} +my %install_status = ( 1=>"Uninstalled", 2=> "Install-pending", 3=> "Uninstall-Pending", 4=>"Installed"); +my %defined_status = ( 1=>"Active", 2=>"Continue-Pending", 3=> "Pause-Pending", 4=> "Paused"); +foreach my $key (oid_lex_sort(keys %$result)) { + my $found = 0; + for(my $i = 0; $i < scalar(@proc) && !$found; $i++) { + my $value = substr($key, length($OID_SW_ServiceName)+1, length($key)); + if (lc $proc[$i] eq lc $result->{$key}) { + my $result2 = $session->get_request(-varbindlist => [$OID_SW_ServiceInstallStatus . "." . $value]); + if (!defined($result)) { + printf("UNKNOWN: %s.\n", $session->error); + $session->close; + exit $ERRORS{'UNKNOWN'}; + } + if ((my $temp_installStatus_val = $result2->{$OID_SW_ServiceInstallStatus . "." . $value})) { + if ($temp_installStatus_val != 1 && $temp_installStatus_val != 3) { + $result2 = $session->get_request(-varbindlist => [$OID_SW_ServiceStatus . "." . $value]); + if (!defined($result)) { + printf("UNKNOWN: %s.\n", $session->error); + $session->close; + exit $ERRORS{'UNKNOWN'}; + } + $status[$i] = $defined_status{$result2->{$OID_SW_ServiceStatus . "." . $value}}; + }else { + $status[$i] = $install_status{$temp_installStatus_val}; + } + } + $found = 1; + } + } +} + +my $final_status = "OK"; +my $active = ""; +my $inactive = ""; +my $unknown = ""; +# Plugin return code +for (my $i = 0; $i < scalar(@proc); $i++) { + if (defined($status[$i])) { + my $written = 0; + if ($final_status ne "CRITICAL" && $status[$i] eq "0") { + $status[$i] = "Unknown"; + $final_status = "WARNING"; + $written = 1; + $unknown .= $proc[$i]." - "; + } + if ($final_status ne "CRITICAL" && $status[$i] eq "Uninstall-Pending" || $status[$i] eq "Pause-Pending") { + $final_status = "WARNING"; + $written = 1; + $inactive .= $proc[$i]." - "; + } + if ($status[$i] && ($status[$i] eq "Uninstalled" || $status[$i] eq "paused")) { + $final_status = "CRITICAL"; + $written = 1; + $inactive .= $proc[$i]." - "; + } + if (!$written) { + $active .= $proc[$i]." - "; + } + } +} +my $msg = ""; +if ($inactive ne "") { + $msg .= "INACTIVE : $inactive "; +} +if ($unknown ne "") { + $msg .= "UNKNOWN : $unknown "; +} +if ($active ne "") { + $msg .= "ACTIVE : $active"; +} +$msg =~ s/\- $//; +print "$msg\n"; +exit $ERRORS{$final_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 " -n (--number) Return the number of current running processes. \n"; + print " -p (--process) Set the process name ex: by default smbd\n"; + print " -k (--key) snmp V3 key\n"; + print " -x (--password) snmp V3 password\n"; + print " -u (--username) snmp v3 username \n"; + print " -V (--version) Plugin version\n"; + print " -h (--help) usage help\n"; +} +sub print_help () { + print "##############################################\n"; + print "# Copyright (c) 2004-2007 Centreon #\n"; + print "# Bugs to http://bugs.oreon-project.org/ #\n"; + print "##############################################\n"; + print_usage(); + print "\n"; +} diff --git a/src/check_centreon_snmp_multiple_process b/src/check_centreon_snmp_multiple_process new file mode 100644 index 000000000..1bc4d6abc --- /dev/null +++ b/src/check_centreon_snmp_multiple_process @@ -0,0 +1,253 @@ +#! /usr/bin/perl -w +################################################################### +# Oreon is developped with GPL Licence 2.0 +# +# GPL License: http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt +# +# Developped by : Julien Mathis - Romain Le Merlus +# Christophe Coraboeuf - Sugumaran Mathavarajan +# +################################################################### +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License +# as published by the Free Software Foundation; either version 2 +# of the License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# For information : contact@merethis.com +#################################################################### +# +# Script init +# + +use strict; +use Net::SNMP qw(:snmp oid_lex_sort); +use FindBin; +use lib "$FindBin::Bin"; +use lib "/srv/nagios/libexec"; +use utils qw($TIMEOUT %ERRORS &print_revision &support); +if (eval "require oreon" ) { + use oreon qw(get_parameters); + 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_d $opt_h $opt_v $opt_C $opt_p $opt_H $opt_n $opt_k $opt_u $opt_x $result @result %process_list %STATUS); + +# Plugin var init + +my($proc, $proc_run); + +$PROGNAME = $0; +sub print_help (); +sub print_usage (); + +%STATUS=(1=>'running',2=>'runnable',3=>'notRunnable',4=>'invalid'); + +Getopt::Long::Configure('bundling'); +GetOptions + ("h" => \$opt_h, "help" => \$opt_h, + "u=s" => \$opt_u, "username=s" => \$opt_u, + "x=s" => \$opt_x, "password=s" => \$opt_x, + "k=s" => \$opt_k, "key=s" => \$opt_k, + "V" => \$opt_V, "version" => \$opt_V, + "n" => \$opt_n, "number" => \$opt_n, + "v=s" => \$opt_v, "snmp=s" => \$opt_v, + "d" => \$opt_d, "debug" => \$opt_d, + "C=s" => \$opt_C, "community=s" => \$opt_C, + "p=s" => \$opt_p, "process=s" => \$opt_p, + "H=s" => \$opt_H, "hostname=s" => \$opt_H); + +if ($opt_V) { + print_revision($PROGNAME,'$Revision: 1.2 $'); + exit $ERRORS{'OK'}; +} + +if ($opt_h) { + print_help(); + exit $ERRORS{'OK'}; +} + +if (!$opt_H) { + print_usage(); + exit $ERRORS{'OK'}; +} +my $snmp = "1"; +$snmp = $opt_v if ($opt_v && $opt_v =~ /^[0-9]$/); + +if ($snmp eq "3") { + if (!$opt_u) { + print "Option -u (--username) is required for snmpV3\n"; + exit $ERRORS{'OK'}; + } + if (!$opt_x && !$opt_k) { + print "Option -k (--key) or -x (--password) is required for snmpV3\n"; + exit $ERRORS{'OK'}; + } elsif ($opt_x && $opt_k) { + print "Only option -k (--key) or -x (--password) is needed for snmpV3\n"; + exit $ERRORS{'OK'}; + } +} + +$opt_C = "public" if (!$opt_C); + +my $process; +if(!$opt_p) { + print_usage(); + exit $ERRORS{'OK'}; +} elsif ($opt_p !~ /([-.A-Za-z0-9\,]+)/){ + print_usage(); + exit $ERRORS{'OK'}; +} +$process = $opt_p; +my @process_temp = split /\,/,$opt_p; +my (@proc,@status,@parameters); +foreach (@process_temp) { +my @tab = split /\:/,$_; +$status[scalar(@proc)] = 0; +$proc[scalar(@proc)] = $tab[0]; +$parameters[scalar(@parameters)] = $tab[1]; +} +my $name = $0; + +# Plugin snmp requests +my $OID_SW_RunName = $oreon{MIB2}{SW_RUNNAME}; +my $OID_SW_RunParameters = $oreon{MIB2}{SW_RUNPARAMETERS}; +my $OID_SW_RunIndex =$oreon{MIB2}{SW_RUNINDEX}; +my $OID_SW_RunStatus =$oreon{MIB2}{SW_RUNSTATUS}; + +my ($session, $error); +if ($snmp eq "1" || $snmp eq "2") { + ($session, $error) = Net::SNMP->session(-hostname => $opt_H, -community => $opt_C, -version => $snmp); + if (!defined($session)) { + print("UNKNOWN: SNMP Session : $error\n"); + exit $ERRORS{'UNKNOWN'}; + } +} elsif ($opt_k) { + ($session, $error) = Net::SNMP->session(-hostname => $opt_H, -version => $snmp, -username => $opt_u, -authkey => $opt_k); + if (!defined($session)) { + print("UNKNOWN: SNMP Session : $error\n"); + exit $ERRORS{'UNKNOWN'}; + } +} elsif ($opt_x) { + ($session, $error) = Net::SNMP->session(-hostname => $opt_H, -version => $snmp, -username => $opt_u, -authpassword => $opt_x); + if (!defined($session)) { + print("UNKNOWN: SNMP Session : $error\n"); + exit $ERRORS{'UNKNOWN'}; + } +} +$result = $session->get_table(Baseoid => $OID_SW_RunName); +if (!defined($result)) { + printf("UNKNOWN: %s.\n", $session->error); + $session->close; + exit $ERRORS{'UNKNOWN'}; +} + +my %defined_status = (0=>"NotPresent", 1=>"Running", 2=> "Runnable", 3=> "NotRunnable", 4=>"Invalid"); +foreach my $key (oid_lex_sort(keys %$result)) { + my $found = 0; + for(my $i = 0; $i < scalar(@proc) && !$found; $i++) { + my @oid_list = split (/\./,$key); + my $value = pop(@oid_list); + if (lc $proc[$i] eq lc $result->{$key}) { + my $result2 = $session->get_request(-varbindlist => [$OID_SW_RunStatus . "." . $value]); + if (!defined($result)) { + printf("UNKNOWN: %s.\n", $session->error); + $session->close; + exit $ERRORS{'UNKNOWN'}; + } + my $temp_status_val = $result2->{$OID_SW_RunStatus . "." . $value}; + if (defined ($parameters[$i]) && $parameters[$i] ne "") { + $result2 = $session->get_request(-varbindlist => [$OID_SW_RunParameters . "." . $value]); + if (!defined($result)) { + printf("UNKNOWN: %s.\n", $session->error); + $session->close; + exit $ERRORS{'UNKNOWN'}; + } + if (lc $parameters[$i] eq lc $result2->{$OID_SW_RunParameters . "." . $value}) { + $status[$i] = $temp_status_val; + $found = 1; + } + }else { + $status[$i] = $temp_status_val; + $found = 1; + } + } + } +} + +my $final_status = "OK"; +my $msg = ""; +my $notPresent = ""; +my $critical =""; +my $OK = ""; +# Plugin return code +my $unKnown = ""; +#$msg =~ s/\-$//; +for (my $i = 0; $i < scalar(@proc); $i++) { + if (defined($status[$i])) { + if ($status[$i] != 1 && $status[$i] != 2) { + if ($status[$i] == 0) { + $final_status = "CRITICAL"; + $notPresent .= $proc[$i]." - "; + } + if ($status[$i]) { + $final_status = "CRITICAL"; + $critical .= $proc[$i]." - "; + } + }else { + $OK .= $proc[$i]." - "; + } + }else { + $unKnown .= $proc[$i]." - "; + } +} +if ($critical ne "") { +$msg = "CRITICAL : $critical"; +} +if ($notPresent ne "") { +$msg .= "NOT-PRESENT : $notPresent"; +} +if ($OK ne "" && $opt_d) { +$msg .= "OK : $OK"; +} +if ($msg eq "" ) { + $msg = "All process OK"; +} +$msg =~ s/\- $//; +print "$msg\n"; +exit $ERRORS{$final_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 " -n (--number) Return the number of current running processes. \n"; + print " -p (--process) Set the process name ex: by default smbd\n"; + print " -k (--key) snmp V3 key\n"; + print " -x (--password) snmp V3 password\n"; + print " -u (--username) snmp v3 username \n"; + print " -V (--version) Plugin version\n"; + print " -h (--help) usage help\n"; +} +sub print_help () { + print "##############################################\n"; + print "# Copyright (c) 2004-2007 Centreon #\n"; + print "# Bugs to http://bugs.oreon-project.org/ #\n"; + print "##############################################\n"; + print_usage(); + print "\n"; +} diff --git a/src/check_centreon_snmp_multiple_process2 b/src/check_centreon_snmp_multiple_process2 new file mode 100644 index 000000000..df20c4598 --- /dev/null +++ b/src/check_centreon_snmp_multiple_process2 @@ -0,0 +1,255 @@ +#! /usr/bin/perl -w +################################################################### +# Oreon is developped with GPL Licence 2.0 +# +# GPL License: http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt +# +# Developped by : Julien Mathis - Romain Le Merlus +# Christophe Coraboeuf - Sugumaran Mathavarajan +# +################################################################### +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License +# as published by the Free Software Foundation; either version 2 +# of the License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# For information : contact@merethis.com +#################################################################### +# +# Script init +# + +use strict; +use Net::SNMP qw(:snmp oid_lex_sort); +use FindBin; +use lib "$FindBin::Bin"; +use lib "/srv/nagios/libexec"; +use utils qw($TIMEOUT %ERRORS &print_revision &support); +if (eval "require oreon" ) { + use oreon qw(get_parameters); + 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_d $opt_h $opt_v $opt_C $opt_p $opt_H $opt_n $opt_k $opt_u $opt_x $result @result %process_list %STATUS); + +# Plugin var init + +my($proc, $proc_run); + +$PROGNAME = $0; +sub print_help (); +sub print_usage (); + +%STATUS=(1=>'running',2=>'runnable',3=>'notRunnable',4=>'invalid'); + +Getopt::Long::Configure('bundling'); +GetOptions + ("h" => \$opt_h, "help" => \$opt_h, + "u=s" => \$opt_u, "username=s" => \$opt_u, + "x=s" => \$opt_x, "password=s" => \$opt_x, + "k=s" => \$opt_k, "key=s" => \$opt_k, + "V" => \$opt_V, "version" => \$opt_V, + "n" => \$opt_n, "number" => \$opt_n, + "v=s" => \$opt_v, "snmp=s" => \$opt_v, + "d" => \$opt_d, "debug" => \$opt_d, + "C=s" => \$opt_C, "community=s" => \$opt_C, + "p=s" => \$opt_p, "process=s" => \$opt_p, + "H=s" => \$opt_H, "hostname=s" => \$opt_H); + +if ($opt_V) { + print_revision($PROGNAME,'$Revision: 1.2 $'); + exit $ERRORS{'OK'}; +} + +if ($opt_h) { + print_help(); + exit $ERRORS{'OK'}; +} + +if (!$opt_H) { + print_usage(); + exit $ERRORS{'OK'}; +} +my $snmp = "1"; +$snmp = $opt_v if ($opt_v && $opt_v =~ /^[0-9]$/); + +if ($snmp eq "3") { + if (!$opt_u) { + print "Option -u (--username) is required for snmpV3\n"; + exit $ERRORS{'OK'}; + } + if (!$opt_x && !$opt_k) { + print "Option -k (--key) or -x (--password) is required for snmpV3\n"; + exit $ERRORS{'OK'}; + } elsif ($opt_x && $opt_k) { + print "Only option -k (--key) or -x (--password) is needed for snmpV3\n"; + exit $ERRORS{'OK'}; + } +} + +$opt_C = "public" if (!$opt_C); + +my $process; +if(!$opt_p) { + print_usage(); + exit $ERRORS{'OK'}; +} elsif ($opt_p !~ /([-.A-Za-z0-9\,]+)/){ + print_usage(); + exit $ERRORS{'OK'}; +} +$process = $opt_p; +my @process_temp = split /\,/,$opt_p; +my (@proc,@status,@parameters); +foreach (@process_temp) { +my @tab = split /\:/,$_; +$status[scalar(@proc)] = 0; +$proc[scalar(@proc)] = $tab[0]; +$parameters[scalar(@parameters)] = $tab[1]; +} +my $name = $0; + +# Plugin snmp requests +my $OID_SW_RunName = $oreon{MIB2}{SW_RUNNAME}; +my $OID_SW_RunParameters = $oreon{MIB2}{SW_RUNPARAMETERS}; +my $OID_SW_RunIndex =$oreon{MIB2}{SW_RUNINDEX}; +my $OID_SW_RunStatus =$oreon{MIB2}{SW_RUNSTATUS}; + +my ($session, $error); +if ($snmp eq "1" || $snmp eq "2") { + ($session, $error) = Net::SNMP->session(-hostname => $opt_H, -community => $opt_C, -version => $snmp); + if (!defined($session)) { + print("UNKNOWN: SNMP Session : $error\n"); + exit $ERRORS{'UNKNOWN'}; + } +} elsif ($opt_k) { + ($session, $error) = Net::SNMP->session(-hostname => $opt_H, -version => $snmp, -username => $opt_u, -authkey => $opt_k); + if (!defined($session)) { + print("UNKNOWN: SNMP Session : $error\n"); + exit $ERRORS{'UNKNOWN'}; + } +} elsif ($opt_x) { + ($session, $error) = Net::SNMP->session(-hostname => $opt_H, -version => $snmp, -username => $opt_u, -authpassword => $opt_x); + if (!defined($session)) { + print("UNKNOWN: SNMP Session : $error\n"); + exit $ERRORS{'UNKNOWN'}; + } +} +$result = $session->get_table(Baseoid => $OID_SW_RunName); +if (!defined($result)) { + printf("UNKNOWN: %s.\n", $session->error); + $session->close; + exit $ERRORS{'UNKNOWN'}; +} + +my %defined_status = (0=>"NotPresent", 1=>"Running", 2=> "Runnable", 3=> "NotRunnable", 4=>"Invalid"); +foreach my $key (oid_lex_sort(keys %$result)) { + my $found = 0; + for(my $i = 0; $i < scalar(@proc) && !$found; $i++) { + my @oid_list = split (/\./,$key); + my $value = pop(@oid_list); + if (lc $proc[$i] eq lc $result->{$key}) { + my $result2 = $session->get_request(-varbindlist => [$OID_SW_RunStatus . "." . $value]); + if (!defined($result)) { + printf("UNKNOWN: %s.\n", $session->error); + $session->close; + exit $ERRORS{'UNKNOWN'}; + } + my $temp_status_val = $result2->{$OID_SW_RunStatus . "." . $value}; + if (defined ($parameters[$i]) && $parameters[$i] ne "") { + $result2 = $session->get_request(-varbindlist => [$OID_SW_RunParameters . "." . $value]); + if (!defined($result)) { + printf("UNKNOWN: %s.\n", $session->error); + $session->close; + exit $ERRORS{'UNKNOWN'}; + } + $result2->{$OID_SW_RunParameters . "." . $value} = lc $result2->{$OID_SW_RunParameters . "." . $value}; + my $temp_parameter = lc $parameters[$i]; + if ($result2->{$OID_SW_RunParameters . "." . $value} =~ /$temp_parameter/) { + $status[$i] = $temp_status_val; + $found = 1; + } + }else { + $status[$i] = $temp_status_val; + $found = 1; + } + } + } +} + +my $final_status = "OK"; +my $msg = ""; +my $notPresent = ""; +my $critical =""; +my $OK = ""; +# Plugin return code +my $unKnown = ""; +#$msg =~ s/\-$//; +for (my $i = 0; $i < scalar(@proc); $i++) { + if (defined($status[$i])) { + if ($status[$i] != 1 && $status[$i] != 2) { + if ($status[$i] == 0) { + $final_status = "CRITICAL"; + $notPresent .= $proc[$i]." - "; + } + if ($status[$i]) { + $final_status = "CRITICAL"; + $critical .= $proc[$i]." - "; + } + }else { + $OK .= $proc[$i]." - "; + } + }else { + $unKnown .= $proc[$i]." - "; + } +} +if ($critical ne "") { +$msg = "CRITICAL : $critical"; +} +if ($notPresent ne "") { +$msg .= "NOT-PRESENT : $notPresent"; +} +if ($OK ne "" && $opt_d) { +$msg .= "OK : $OK"; +} +if ($msg eq "" ) { + $msg = "All process OK"; +} +$msg =~ s/\- $//; +print "$msg\n"; +exit $ERRORS{$final_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 " -n (--number) Return the number of current running processes. \n"; + print " -p (--process) Set the process name ex: by default smbd\n"; + print " -k (--key) snmp V3 key\n"; + print " -x (--password) snmp V3 password\n"; + print " -u (--username) snmp v3 username \n"; + print " -V (--version) Plugin version\n"; + print " -h (--help) usage help\n"; +} +sub print_help () { + print "##############################################\n"; + print "# Copyright (c) 2004-2007 Centreon #\n"; + print "# Bugs to http://bugs.oreon-project.org/ #\n"; + print "##############################################\n"; + print_usage(); + print "\n"; +}