git-svn-id: http://svn.centreon.com/Plugins/Dev@2668 6bcd3966-0018-0410-8128-fd23d134de7e
This commit is contained in:
Mat Sugumaran 2007-07-11 16:38:27 +00:00
parent 339bae8137
commit 7428a3ba9d
1 changed files with 140 additions and 143 deletions

View File

@ -1,143 +1,140 @@
#! /usr/bin/perl -w #! /usr/bin/perl -w
# #
# $Id: check_TcpConn.pl,v 1.2 2005/11/17 10:21:49 Sugumaran Mat $ # $Id: check_TcpConn.pl,v 1.2 2005/11/17 10:21:49 Sugumaran Mat $
# #
# This plugin is developped under GPL Licence: # This plugin is developped under GPL Licence:
# http://www.fsf.org/licenses/gpl.txt # http://www.fsf.org/licenses/gpl.txt
# #
# Developped by Merethis SARL : http://www.merethis.com # Developped by Merethis SARL : http://www.merethis.com
# #
# The Software is provided to you AS IS and WITH ALL FAULTS. # The Software is provided to you AS IS and WITH ALL FAULTS.
# MERETHIS makes no representation and gives no warranty whatsoever, # MERETHIS makes no representation and gives no warranty whatsoever,
# whether express or implied, and without limitation, with regard to the quality, # whether express or implied, and without limitation, with regard to the quality,
# safety, contents, performance, merchantability, non-infringement or suitability for # safety, contents, performance, merchantability, non-infringement or suitability for
# any particular or intended purpose of the Software found on the LINAGORA web site. # 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, # 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 # incidental or consequential damages however they may arise and even if MERETHIS has
# been previously advised of the possibility of such damages. # been previously advised of the possibility of such damages.
## ##
## Plugin init ## Plugin init
## ##
use strict;
use strict; use Net::SNMP qw(:snmp);
use Net::SNMP qw(:snmp); use FindBin;
use FindBin; use lib "$FindBin::Bin";
use lib "$FindBin::Bin"; use lib "@NAGIOS_PLUGINS";
use lib "@NAGIOS_PLUGINS@"; use utils qw($TIMEOUT %ERRORS &print_revision &support);
use utils qw($TIMEOUT %ERRORS &print_revision &support); if (eval "require oreon" ) {
use oreon qw(get_parameters);
if (eval "require oreon" ) { use vars qw($VERSION %oreon);
use oreon qw(get_parameters create_rrd update_rrd &is_valid_serviceid); %oreon = get_parameters();
use vars qw($VERSION %oreon); } else {
%oreon=get_parameters(); print "Unable to load oreon perl module\n";
} else { exit $ERRORS{'UNKNOWN'};
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($PROGNAME); use vars qw($snmp);
use Getopt::Long;
use vars qw($opt_h $opt_V $opt_H $opt_C $opt_v $opt_p $opt_c $opt_w); $PROGNAME = "ckeck_TcpConn";
use vars qw($snmp); sub print_help ();
sub print_usage ();
$PROGNAME = "ckeck_TcpConn";
sub print_help (); Getopt::Long::Configure('bundling');
sub print_usage (); GetOptions
("h" => \$opt_h, "help" => \$opt_h,
Getopt::Long::Configure('bundling'); "v=s" => \$opt_v, "snmp_version=s" => \$opt_v,
GetOptions "V" => \$opt_V, "version" => \$opt_V,
("h" => \$opt_h, "help" => \$opt_h, "H=s" => \$opt_H, "Hostname=s" => \$opt_H,
"v=s" => \$opt_v, "snmp_version" => \$opt_v, "p=i" => \$opt_p, "port=s" => \$opt_p,
"V" => \$opt_V, "version" => \$opt_V, "C=s" => \$opt_C, "Community=s" => \$opt_C,
"H=s" => \$opt_H, "Hostname" => \$opt_H, "c=s"=> \$opt_c, "w=s"=> \$opt_w
"p=i" => \$opt_p, "port" => \$opt_p, );
"C=s" => \$opt_C, "Community" => \$opt_C,
"c=s" => \$opt_c, "w=s" => \$opt_w if ($opt_V) {
); print_revision($PROGNAME,'$Revision: 1.0');
exit $ERRORS{'OK'};
if ($opt_V) { }
print_revision($PROGNAME,'$Revision: 1.0');
exit $ERRORS{'OK'}; if ($opt_h) {
} print_help();
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_H = shift unless ($opt_H); $opt_p = shift unless ($opt_p);
(print_usage() && exit $ERRORS{'OK'}) unless ($opt_H); (print_usage() && exit $ERRORS{'OK'}) unless ($opt_p);
$opt_p = shift unless ($opt_p); ($opt_v) || ($opt_v = shift) || ($opt_v = "v1");
(print_usage() && exit $ERRORS{'OK'}) unless ($opt_p); my $snmp = $1 if ($opt_v =~ /(\d)/);
($opt_v) || ($opt_v = shift) || ($opt_v = "v1"); ($opt_C) || ($opt_C = shift) || ($opt_C = "public");
my $snmp = $1 if ($opt_v =~ /(\d)/);
my $name = $0;
($opt_C) || ($opt_C = shift) || ($opt_C = "public"); $name =~ s/\.pl.*//g;
my $day = 0;
my $name = $0;
$name =~ s/\.pl.*//g; #=== create a SNMP session ====
my $day = 0; # 1.3.6.1.4.1.232.1.2.2.1.1.6
#=== create a SNMP session ==== my ($session, $error) = Net::SNMP->session(-hostname => $opt_H,-community => $opt_C, -version => $snmp);
# 1.3.6.1.4.1.232.1.2.2.1.1.6 if (!defined($session)) {
print("CRITICAL: $error");
my ($session, $error) = Net::SNMP->session(-hostname => $opt_H,-community => $opt_C, -version => $snmp); exit $ERRORS{'CRITICAL'};
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);
my $OID_TCP_PORT = ".1.3.6.1.2.1.6.13.1.3"; if (!defined($result)) {
printf("ERROR: Description Table : %s.\n", $session->error);
my $result = $session->get_table(Baseoid => $OID_TCP_PORT); $session->close;
if (!defined($result)) { exit $ERRORS{'UNKNOWN'};
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) {
my $cpt = 0; $cpt++;
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;}
if (!defined($opt_w)){$opt_w = 20;} print "Number of connections on port $opt_p : $cpt |nb_conn=$cpt\n";
if (!defined($opt_c)){$opt_c = 30;} if ($cpt >= $opt_w && $cpt < $opt_c){
exit $ERRORS{'WARNING'};
print "Number of connections on port $opt_p : $cpt |nb_conn=$cpt\n"; } elsif ($cpt >= $opt_c){
if ($cpt >= $opt_w && $cpt < $opt_c){ exit $ERRORS{'CRITICAL'};
exit $ERRORS{'WARNING'}; } else {
} elsif ($cpt >= $opt_c){ exit $ERRORS{'OK'};
exit $ERRORS{'CRITICAL'}; }
} else {
exit $ERRORS{'OK'};
} sub print_usage () {
print "\nUsage:\n";
print "$PROGNAME\n";
sub print_usage () { print " -H (--hostname) Hostname to query - (required)\n";
print "\nUsage:\n"; print " -p (--port) port you want to check - (required)\n";
print "$PROGNAME\n"; print " -C (--community) SNMP read community (defaults to public,\n";
print " -H (--hostname) Hostname to query - (required)\n"; print " used with SNMP v1 and v2c\n";
print " -p (--port) port you want to check - (required)\n"; print " -v (--snmp_version) 1 for SNMP v1 (default)\n";
print " -C (--community) SNMP read community (defaults to public,\n"; print " 2 for SNMP v2c\n";
print " used with SNMP v1 and v2c\n"; print " -V (--version) Plugin version\n";
print " -v (--snmp_version) 1 for SNMP v1 (default)\n"; print " -h (--help) usage help\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";
sub print_help () { print "# Developped by Julien Mathis =\n";
print "#=========================================\n"; print "# Bugs to http://www.oreon-project.org/ =\n";
print "# Copyright (c) 2005 Merethis SARL =\n"; print "#=========================================\n";
print "# Developped by Julien Mathis =\n"; print_usage();
print "# Bugs to http://www.oreon-project.org/ =\n"; print "\n";
print "#=========================================\n"; }
print_usage();
print "\n";
}