From da81d84606186a05bfb97b2b521fe4b0dc86765d Mon Sep 17 00:00:00 2001 From: Mat Sugumaran Date: Mon, 19 May 2008 10:21:35 +0000 Subject: [PATCH] plugin updated to take snmp port in parameter git-svn-id: http://svn.centreon.com/trunk/plugins-2.x@5188 6bcd3966-0018-0410-8128-fd23d134de7e --- .../src/check_centreon_snmp_remote_storage | 15 +++++++++------ centreon-plugins/src/check_centreon_snmp_traffic | 13 ++++++++----- 2 files changed, 17 insertions(+), 11 deletions(-) diff --git a/centreon-plugins/src/check_centreon_snmp_remote_storage b/centreon-plugins/src/check_centreon_snmp_remote_storage index df3c75e25..e2a314a0a 100644 --- a/centreon-plugins/src/check_centreon_snmp_remote_storage +++ b/centreon-plugins/src/check_centreon_snmp_remote_storage @@ -41,7 +41,7 @@ if (eval "require centreon" ) { } use vars qw($PROGNAME); use Getopt::Long; -use vars qw($opt_V $opt_t $opt_h $opt_v $opt_f $opt_C $opt_d $opt_k $opt_u $opt_p $opt_n $opt_w $opt_c $opt_H $opt_s @test); +use vars qw($opt_V $opt_t $opt_P $opt_h $opt_v $opt_f $opt_C $opt_d $opt_k $opt_u $opt_p $opt_n $opt_w $opt_c $opt_H $opt_s @test); # Plugin var init @@ -59,6 +59,7 @@ GetOptions "u=s" => \$opt_u, "username=s" => \$opt_u, "p=s" => \$opt_p, "password=s" => \$opt_p, "k=s" => \$opt_k, "key=s" => \$opt_k, + "P=s" => \$opt_P, "--snmp-port=s" => \$opt_P, "V" => \$opt_V, "version" => \$opt_V, "s" => \$opt_s, "show" => \$opt_s, "v=s" => \$opt_v, "snmp=s" => \$opt_v, @@ -75,7 +76,9 @@ if ($opt_V) { print_revision($PROGNAME,'$Revision: 1.2 $'); exit $ERRORS{'OK'}; } - +if (!defined($opt_P)) { + $opt_P = 161; +} if ($opt_h) { print_help(); exit $ERRORS{'OK'}; @@ -157,19 +160,19 @@ my $OID_hrStorageUsed = $centreon{MIB2}{HR_STORAGE_USED}; # create a SNMP session my ($session, $error); if ($snmp eq "1" || $snmp eq "2") { - ($session, $error) = Net::SNMP->session(-hostname => $opt_H, -community => $opt_C, -version => $snmp); + ($session, $error) = Net::SNMP->session(-hostname => $opt_H, -community => $opt_C, -version => $snmp, -port => $opt_P); 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); + ($session, $error) = Net::SNMP->session(-hostname => $opt_H, -version => $snmp, -username => $opt_u, -authkey => $opt_k, -port => $opt_P); if (!defined($session)) { print("UNKNOWN: SNMP Session : $error\n"); exit $ERRORS{'UNKNOWN'}; } } elsif ($opt_p) { - ($session, $error) = Net::SNMP->session(-hostname => $opt_H, -version => $snmp, -username => $opt_u, -authpassword => $opt_p); + ($session, $error) = Net::SNMP->session(-hostname => $opt_H, -version => $snmp, -username => $opt_u, -authpassword => $opt_p, -port => $opt_P); if (!defined($session)) { print("UNKNOWN: SNMP Session : $error\n"); exit $ERRORS{'UNKNOWN'}; @@ -235,7 +238,7 @@ my $result = $session->get_request( ] ); if (!defined($result)) { - printf("ERROR: %s", $session->error); + printf("ERROR: %s.\n", $session->error); if ($opt_n) { print(" - You must specify the disk name when option -n is used");} print ".\n"; $session->close; diff --git a/centreon-plugins/src/check_centreon_snmp_traffic b/centreon-plugins/src/check_centreon_snmp_traffic index 789f34b69..42347a1db 100644 --- a/centreon-plugins/src/check_centreon_snmp_traffic +++ b/centreon-plugins/src/check_centreon_snmp_traffic @@ -40,7 +40,7 @@ if (eval "require centreon" ) { } use vars qw($PROGNAME); use Getopt::Long; -use vars qw($opt_V $opt_h $opt_64bits $opt_v $opt_C $opt_b $opt_k $opt_u $opt_p $opt_H $opt_D $opt_i $opt_n $opt_w $opt_c $opt_s $opt_T $opt_r); +use vars qw($opt_V $opt_h $opt_P $opt_64bits $opt_v $opt_C $opt_b $opt_k $opt_u $opt_p $opt_H $opt_D $opt_i $opt_n $opt_w $opt_c $opt_s $opt_T $opt_r); # Plugin var init @@ -55,6 +55,7 @@ GetOptions ("h" => \$opt_h, "help" => \$opt_h, "u=s" => \$opt_u, "username=s" => \$opt_u, "p=s" => \$opt_p, "password=s" => \$opt_p, + "P=s" => \$opt_P, "--snmp-port=s" => \$opt_P, "k=s" => \$opt_k, "key=s" => \$opt_k, "s" => \$opt_s, "show" => \$opt_s, "V" => \$opt_V, "version" => \$opt_V, @@ -123,7 +124,9 @@ $opt_i = 2; if (!$opt_b) { $opt_b = 95; } - +if (!defined($opt_P)) { + $opt_P = 161; +} if ($opt_b =~ /([0-9]+)/) { my $bps = $1; } @@ -169,19 +172,19 @@ my @operstatus = ("up","down","testing", "unknown", "dormant", "notPresent", "lo # create a SNMP session my ($session, $error); if ($snmp eq "1" || $snmp =~ /2/) { - ($session, $error) = Net::SNMP->session(-hostname => $opt_H, -community => $opt_C, -version => $snmp); + ($session, $error) = Net::SNMP->session(-hostname => $opt_H, -community => $opt_C, -version => $snmp, -port => $opt_P); 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); + ($session, $error) = Net::SNMP->session(-hostname => $opt_H, -version => $snmp, -username => $opt_u, -authkey => $opt_k, -port => $opt_P); if (!defined($session)) { print("UNKNOWN: SNMP Session : $error\n"); exit $ERRORS{'UNKNOWN'}; } }elsif ($opt_p) { - ($session, $error) = Net::SNMP->session(-hostname => $opt_H, -version => $snmp, -username => $opt_u, -authpassword => $opt_p); + ($session, $error) = Net::SNMP->session(-hostname => $opt_H, -version => $snmp, -username => $opt_u, -authpassword => $opt_p, -port => $opt_P); if (!defined($session)) { print("UNKNOWN: SNMP Session : $error\n"); exit $ERRORS{'UNKNOWN'};