add -P (SNMP port) option for check_centreon_snmp_loadaverage

git-svn-id: http://svn.centreon.com/trunk/plugins-2.x@8223 6bcd3966-0018-0410-8128-fd23d134de7e
This commit is contained in:
Nicolas Cordier 2009-05-27 14:10:02 +00:00
parent 5bd37cb22b
commit 0bc34b9681
1 changed files with 10 additions and 4 deletions

View File

@ -57,7 +57,7 @@ if (eval "require centreon" ) {
use vars qw($PROGNAME);
use Getopt::Long;
use vars qw($opt_V $opt_h $opt_v $opt_C $opt_H $opt_c $opt_w $opt_D $snmp $opt_k $opt_u $opt_p @critical @warning);
use vars qw($opt_V $opt_h $opt_v $opt_C $opt_H $opt_c $opt_w $opt_D $snmp $opt_k $opt_u $opt_p $opt_P @critical @warning);
# Plugin var init
@ -73,6 +73,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,
"v=s" => \$opt_v, "snmp=s" => \$opt_v,
"C=s" => \$opt_C, "community=s" => \$opt_C,
@ -85,6 +86,10 @@ if ($opt_V) {
exit $ERRORS{'OK'};
}
if (!defined($opt_P)) {
$opt_P = 161;
}
if ($opt_h) {
print_help();
exit $ERRORS{'OK'};
@ -150,19 +155,19 @@ my $OID_CPULOAD_15 =$centreon{UNIX}{CPU_LOAD_15M};
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'};
@ -201,6 +206,7 @@ sub print_usage () {
print " -w (--warning) Three warning tresholds (defaults : 1,3,5)\n";
print " -v (--snmp_version) 1 for SNMP v1 (default)\n";
print " 2 for SNMP v2c\n";
print " -P (--snmp-port) SNMP port (default: 161)\n";
print " -k (--key) snmp V3 key\n";
print " -p (--password) snmp V3 password\n";
print " -u (--username) snmp v3 username \n";