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
This commit is contained in:
parent
e3be492d48
commit
da81d84606
|
@ -41,7 +41,7 @@ if (eval "require centreon" ) {
|
||||||
}
|
}
|
||||||
use vars qw($PROGNAME);
|
use vars qw($PROGNAME);
|
||||||
use Getopt::Long;
|
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
|
# Plugin var init
|
||||||
|
|
||||||
|
@ -59,6 +59,7 @@ GetOptions
|
||||||
"u=s" => \$opt_u, "username=s" => \$opt_u,
|
"u=s" => \$opt_u, "username=s" => \$opt_u,
|
||||||
"p=s" => \$opt_p, "password=s" => \$opt_p,
|
"p=s" => \$opt_p, "password=s" => \$opt_p,
|
||||||
"k=s" => \$opt_k, "key=s" => \$opt_k,
|
"k=s" => \$opt_k, "key=s" => \$opt_k,
|
||||||
|
"P=s" => \$opt_P, "--snmp-port=s" => \$opt_P,
|
||||||
"V" => \$opt_V, "version" => \$opt_V,
|
"V" => \$opt_V, "version" => \$opt_V,
|
||||||
"s" => \$opt_s, "show" => \$opt_s,
|
"s" => \$opt_s, "show" => \$opt_s,
|
||||||
"v=s" => \$opt_v, "snmp=s" => \$opt_v,
|
"v=s" => \$opt_v, "snmp=s" => \$opt_v,
|
||||||
|
@ -75,7 +76,9 @@ if ($opt_V) {
|
||||||
print_revision($PROGNAME,'$Revision: 1.2 $');
|
print_revision($PROGNAME,'$Revision: 1.2 $');
|
||||||
exit $ERRORS{'OK'};
|
exit $ERRORS{'OK'};
|
||||||
}
|
}
|
||||||
|
if (!defined($opt_P)) {
|
||||||
|
$opt_P = 161;
|
||||||
|
}
|
||||||
if ($opt_h) {
|
if ($opt_h) {
|
||||||
print_help();
|
print_help();
|
||||||
exit $ERRORS{'OK'};
|
exit $ERRORS{'OK'};
|
||||||
|
@ -157,19 +160,19 @@ my $OID_hrStorageUsed = $centreon{MIB2}{HR_STORAGE_USED};
|
||||||
# create a SNMP session
|
# create a SNMP session
|
||||||
my ($session, $error);
|
my ($session, $error);
|
||||||
if ($snmp eq "1" || $snmp eq "2") {
|
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)) {
|
if (!defined($session)) {
|
||||||
print("UNKNOWN: SNMP Session : $error\n");
|
print("UNKNOWN: SNMP Session : $error\n");
|
||||||
exit $ERRORS{'UNKNOWN'};
|
exit $ERRORS{'UNKNOWN'};
|
||||||
}
|
}
|
||||||
} elsif ($opt_k) {
|
} 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)) {
|
if (!defined($session)) {
|
||||||
print("UNKNOWN: SNMP Session : $error\n");
|
print("UNKNOWN: SNMP Session : $error\n");
|
||||||
exit $ERRORS{'UNKNOWN'};
|
exit $ERRORS{'UNKNOWN'};
|
||||||
}
|
}
|
||||||
} elsif ($opt_p) {
|
} 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)) {
|
if (!defined($session)) {
|
||||||
print("UNKNOWN: SNMP Session : $error\n");
|
print("UNKNOWN: SNMP Session : $error\n");
|
||||||
exit $ERRORS{'UNKNOWN'};
|
exit $ERRORS{'UNKNOWN'};
|
||||||
|
@ -235,7 +238,7 @@ my $result = $session->get_request(
|
||||||
]
|
]
|
||||||
);
|
);
|
||||||
if (!defined($result)) {
|
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");}
|
if ($opt_n) { print(" - You must specify the disk name when option -n is used");}
|
||||||
print ".\n";
|
print ".\n";
|
||||||
$session->close;
|
$session->close;
|
||||||
|
|
|
@ -40,7 +40,7 @@ if (eval "require centreon" ) {
|
||||||
}
|
}
|
||||||
use vars qw($PROGNAME);
|
use vars qw($PROGNAME);
|
||||||
use Getopt::Long;
|
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
|
# Plugin var init
|
||||||
|
|
||||||
|
@ -55,6 +55,7 @@ GetOptions
|
||||||
("h" => \$opt_h, "help" => \$opt_h,
|
("h" => \$opt_h, "help" => \$opt_h,
|
||||||
"u=s" => \$opt_u, "username=s" => \$opt_u,
|
"u=s" => \$opt_u, "username=s" => \$opt_u,
|
||||||
"p=s" => \$opt_p, "password=s" => \$opt_p,
|
"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,
|
"k=s" => \$opt_k, "key=s" => \$opt_k,
|
||||||
"s" => \$opt_s, "show" => \$opt_s,
|
"s" => \$opt_s, "show" => \$opt_s,
|
||||||
"V" => \$opt_V, "version" => \$opt_V,
|
"V" => \$opt_V, "version" => \$opt_V,
|
||||||
|
@ -123,7 +124,9 @@ $opt_i = 2;
|
||||||
if (!$opt_b) {
|
if (!$opt_b) {
|
||||||
$opt_b = 95;
|
$opt_b = 95;
|
||||||
}
|
}
|
||||||
|
if (!defined($opt_P)) {
|
||||||
|
$opt_P = 161;
|
||||||
|
}
|
||||||
if ($opt_b =~ /([0-9]+)/) {
|
if ($opt_b =~ /([0-9]+)/) {
|
||||||
my $bps = $1;
|
my $bps = $1;
|
||||||
}
|
}
|
||||||
|
@ -169,19 +172,19 @@ my @operstatus = ("up","down","testing", "unknown", "dormant", "notPresent", "lo
|
||||||
# create a SNMP session
|
# create a SNMP session
|
||||||
my ($session, $error);
|
my ($session, $error);
|
||||||
if ($snmp eq "1" || $snmp =~ /2/) {
|
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)) {
|
if (!defined($session)) {
|
||||||
print("UNKNOWN: SNMP Session : $error\n");
|
print("UNKNOWN: SNMP Session : $error\n");
|
||||||
exit $ERRORS{'UNKNOWN'};
|
exit $ERRORS{'UNKNOWN'};
|
||||||
}
|
}
|
||||||
}elsif ($opt_k) {
|
}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)) {
|
if (!defined($session)) {
|
||||||
print("UNKNOWN: SNMP Session : $error\n");
|
print("UNKNOWN: SNMP Session : $error\n");
|
||||||
exit $ERRORS{'UNKNOWN'};
|
exit $ERRORS{'UNKNOWN'};
|
||||||
}
|
}
|
||||||
}elsif ($opt_p) {
|
}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)) {
|
if (!defined($session)) {
|
||||||
print("UNKNOWN: SNMP Session : $error\n");
|
print("UNKNOWN: SNMP Session : $error\n");
|
||||||
exit $ERRORS{'UNKNOWN'};
|
exit $ERRORS{'UNKNOWN'};
|
||||||
|
|
Loading…
Reference in New Issue