moved from merethis_plugins to centreon_plugins

git-svn-id: http://svn.centreon.com/Plugins/Dev@2588 6bcd3966-0018-0410-8128-fd23d134de7e
This commit is contained in:
Mat Sugumaran 2007-07-09 07:28:35 +00:00
parent 5e3e52cef5
commit afe0e44bfa
2 changed files with 390 additions and 0 deletions

View File

@ -0,0 +1,147 @@
#! /usr/bin/perl -w
#
# $Id: check_TcpConn.pl,v 1.2 2005/11/17 10:21:49 Sugumaran Mat $
#
# 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_H $opt_C $opt_v $opt_p $opt_c $opt_w);
use vars qw($snmp);
$PROGNAME = "ckeck_TcpConn";
sub print_help ();
sub print_usage ();
Getopt::Long::Configure('bundling');
GetOptions
("h" => \$opt_h, "help" => \$opt_h,
"v=s" => \$opt_v, "snmp_version" => \$opt_v,
"V" => \$opt_V, "version" => \$opt_V,
"H=s" => \$opt_H, "Hostname" => \$opt_H,
"p=i" => \$opt_p, "port" => \$opt_p,
<<<<<<< .mine
"C=s" => \$opt_c, "Community" => \$opt_c
=======
"C=s" => \$opt_C, "Community" => \$opt_C,
"c=s" => \$opt_c, "w=s" => \$opt_w
>>>>>>> .r479
);
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_p = shift unless ($opt_p);
(print_usage() && exit $ERRORS{'OK'}) unless ($opt_p);
($opt_v) || ($opt_v = shift) || ($opt_v = "v1");
my $snmp = $1 if ($opt_v =~ /(\d)/);
($opt_C) || ($opt_C = shift) || ($opt_C = "public");
my $name = $0;
$name =~ s/\.pl.*//g;
my $day = 0;
#=== create a SNMP session ====
# 1.3.6.1.4.1.232.1.2.2.1.1.6
my ($session, $error) = Net::SNMP->session(-hostname => $opt_H,-community => $opt_C, -version => $snmp);
if (!defined($session)) {
print("CRITICAL: $error");
exit $ERRORS{'CRITICAL'};
}
my $OID_TCP_PORT = ".1.3.6.1.2.1.6.13.1.3";
my $result = $session->get_table(Baseoid => $OID_TCP_PORT);
if (!defined($result)) {
printf("ERROR: Description Table : %s.\n", $session->error);
$session->close;
exit $ERRORS{'UNKNOWN'};
}
my $cpt = 0;
foreach my $key (oid_lex_sort(keys %$result)) {
if ($result->{$key} == $opt_p) {
$cpt++;
}
}
if (!defined($opt_w)){$opt_w = 20;}
if (!defined($opt_c)){$opt_c = 30;}
print "Number of connections on port $opt_p : $cpt |nb_conn=$cpt\n";
if ($cpt >= $opt_w && $cpt < $opt_c){
exit $ERRORS{'WARNING'};
} elsif ($cpt >= $opt_c){
exit $ERRORS{'CRITICAL'};
} else {
exit $ERRORS{'OK'};
}
sub print_usage () {
print "\nUsage:\n";
print "$PROGNAME\n";
print " -H (--hostname) Hostname to query - (required)\n";
print " -p (--port) port you want to check - (required)\n";
print " -C (--community) SNMP read community (defaults to public,\n";
print " used with SNMP v1 and v2c\n";
print " -v (--snmp_version) 1 for SNMP v1 (default)\n";
print " 2 for SNMP v2c\n";
print " -V (--version) Plugin version\n";
print " -h (--help) usage help\n";
}
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";
}

View File

@ -0,0 +1,243 @@
#! /usr/bin/perl -w
#
# $Id: check_packetsErrors.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 - Sugumaran Mat
#
# 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 "@NAGIOS_PLUGINS@";
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($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_v $opt_C $opt_H $opt_w $opt_c);
#
# Plugin var init
#
$PROGNAME = "$0";
my ($row, @flg_created, @last_check_time, @last_in_errors, @last_out_errors, $result_in, $result_out, @nb_out_errors, @nb_in_errors, $update_time, $db_file);
my $pathtolibexecnt = $oreon{NAGIOS_LIBEXEC};
sub print_help ();
sub print_usage ();
Getopt::Long::Configure('bundling');
GetOptions
("h" => \$opt_h, "help" => \$opt_h,
"V" => \$opt_V, "version" => \$opt_V,
"v=s" => \$opt_v, "snmp=s" => \$opt_v,
"C=s" => \$opt_C, "community=s" => \$opt_C,
"w=s" => \$opt_w, "warning=s" => \$opt_w,
"c=s" => \$opt_c, "critical=s" => \$opt_c,
"H=s" => \$opt_H, "hostname=s" => \$opt_H);
if ($opt_V) {
print_revision($PROGNAME,'$Revision: 1.2 $');
exit $ERRORS{'OK'};
}
if ($opt_h) {
print_help();
exit $ERRORS{'OK'};
}
##################################################
##### Verify Options
##
$opt_H = shift unless ($opt_H);
(print_usage() && exit $ERRORS{'OK'}) unless ($opt_H);
($opt_v) || ($opt_v = shift) || ($opt_v = "1");
my $snmp = $1 if ($opt_v =~ /(\d)/);
($opt_C) || ($opt_C = shift) || ($opt_C = "public");
($opt_c) || ($opt_c = shift) || ($opt_c = 100);
my $critical = $1 if ($opt_c =~ /([0-9]+)/);
($opt_w) || ($opt_w = shift) || ($opt_w = 80);
my $warning = $1 if ($opt_w =~ /([0-9]+)/);
if ($critical <= $warning){
print "(--crit) must be superior to (--warn)";
print_usage();
exit $ERRORS{'OK'};
}
my $start=time;
#################################################
##### Plugin snmp requests
##
my $OID_IN_ERRORS = ".1.3.6.1.2.1.2.2.1.14";
my $OID_OUT_ERRORS = ".1.3.6.1.2.1.2.2.1.20";
# create a SNMP session
my ($session, $error) = Net::SNMP->session(-hostname => $opt_H, -community => $opt_C, -version => $snmp);
if (!defined($session)) {
print("UNKNOWN: SNMP Session : $error");
exit $ERRORS{'UNKNOWN'};
}
####### Get IN ERRORS
$result_in = $session->get_table(Baseoid => $OID_IN_ERRORS);
if (!defined($result_in)) {
printf("ERROR: IN_ERRORS : %s.\n", $session->error);
$session->close;
exit $ERRORS{'UNKNOWN'};
}
# loop for each interface
foreach my $err (oid_lex_sort(keys %$result_in)) {
$nb_in_errors[scalar(@nb_in_errors)] = $result_in->{$err};
}
# ####### Get OUT ERRORS
$result_out = $session->get_table(Baseoid => $OID_OUT_ERRORS);
if (!defined($result_out)) {
printf("ERROR: OUT_ERRORS : %s.\n", $session->error);
$session->close;
exit $ERRORS{'UNKNOWN'};
}
foreach my $err (oid_lex_sort(keys %$result_out)) {
$nb_out_errors[scalar(@nb_out_errors)] = $result_out->{$err};
}
# #############################################
# ##### read and write in buffer file
# ##
for (my $i = 0; $i < scalar(@nb_in_errors); $i++) {
if (-e "/tmp/packet_errors_if".$i."_".$opt_H.".tmp") {
open(FILE,"<"."/tmp/packet_errors_if".$i."_".$opt_H.".tmp");
while($row = <FILE>){
my @last_values = split(":",$row);
$last_check_time[$i] = $last_values[0];
$last_in_errors[$i] = $last_values[1];
$last_out_errors[$i] = $last_values[2];
$flg_created[$i] = 1;
}
close(FILE);
} else {
$flg_created[$i] = 0;
}
$update_time = time;
unless (open(FILE,">"."/tmp/packet_errors_if".$i."_".$opt_H.".tmp")){
print "Unknown - /tmp/tmp/packet_errors_if".$i."_".$opt_H.".tmp!\n";
exit $ERRORS{"UNKNOWN"};
}
print FILE "$update_time:$nb_in_errors[$i]:$nb_out_errors[$i]";
close(FILE);
if ($flg_created[$i] eq 0){
print "First execution : Buffer in creation.... \n";
}
}
# #############################################
# ##### return result
# ##
my $status = "OK";
my @msg;
my $diff_test = 0;
for (my $i = 0; $i < scalar(@nb_in_errors); $i++) {
my $interface = $i+1;
if ($flg_created[$i]) {
if (($nb_in_errors[$i] - $last_in_errors[$i] >= $critical) or ($nb_out_errors[$i] - $last_out_errors[$i] >= $critical)){
$msg[$i] = "$interface:critical ";
$status = "CRITICAL";
}
if(($nb_in_errors[$i] - $last_in_errors[$i] >= $warning) or ($nb_out_errors[$i] - $last_out_errors[$i] >= $warning)){
if (!defined($msg[$i])) {
$msg[$i] = "$interface:warning ";
}
if ($status ne "CRITICAL") {
$status = "WARNING";
}
}
$diff_test = 1;
}
}
if (!$diff_test) {
exit($ERRORS{'UNKNOWN'});
}
my $output = "";
for (my $i = 0; $i < scalar (@msg); $i++) {
if (defined($msg[$i])) {
$output .= $msg[$i];
}
}
if ($output ne ""){
print $output."\n";
}else {
print "Status OK on all interfaces\n";
}
exit($ERRORS{$status});
sub print_usage () {
print "\nUsage:\n";
print "$PROGNAME\n";
print " -H (--hostname) Hostname to query - (required)\n";
print " -C (--community) SNMP read community (default to public)\n";
print " used with SNMP v1 and v2c\n";
print " -v (--snmp_version) 1 for SNMP v1 (default)\n";
print " 2 for SNMP v2c\n";
print " -w (--warn) Signal strength at which a warning message will be generated\n";
print " (default 80)\n";
print " -c (--crit) Signal strength at which a critical message will be generated\n";
print " (default 100)\n";
print " -V (--version) Plugin version\n";
print " -h (--help) usage help\n";
}
sub print_help () {
print "##########################################\n";
print "# Copyright (c) 2004-2006 Oreon #\n";
print "# Bugs to http://www.oreon-project.org/ #\n";
print "##########################################\n";
print_usage();
print "\n";
}