New -oid option to choose the OID.

fixes #4906
This commit is contained in:
Antoine Nguyen 2013-09-30 10:23:13 +02:00
parent 588a4d78fb
commit 6fb3711469
2 changed files with 24 additions and 7 deletions

View File

@ -35,7 +35,6 @@ HR_STORAGE_SIZE=.1.3.6.1.2.1.25.2.3.1.5
HR_STORAGE_USED=.1.3.6.1.2.1.25.2.3.1.6
OBJECTID=.1.3.6.1.2.1.1.1.0
UPTIME_WINDOWS=.1.3.6.1.2.1.1.3.0
#UPTIME_OTHER=.1.3.6.1.2.1.25.1.1.0
UPTIME_OTHER=.1.3.6.1.2.1.1.3.0
IF_IN_OCTET=.1.3.6.1.2.1.2.2.1.10
IF_OUT_OCTET=.1.3.6.1.2.1.2.2.1.16
@ -48,5 +47,5 @@ IF_IN_ERROR=.1.3.6.1.2.1.2.2.1.14
IF_OUT_ERROR=.1.3.6.1.2.1.2.2.1.20
IF_ADMINSTATUS=.1.3.6.1.2.1.2.2.1.7
IF_OPERSTATUS=.1.3.6.1.2.1.2.2.1.8
IF_ALIAS=.1.3.6.1.2.1.31.1.1.1.18
IF_NAME=.1.3.6.1.2.1.31.1.1.1.1

View File

@ -44,7 +44,7 @@ require "@NAGIOS_PLUGINS@/Centreon/SNMP/Utils.pm";
use vars qw($PROGNAME);
use Getopt::Long;
use vars qw($opt_V $opt_h $opt_i $opt_n $opt_w $opt_c $opt_s $opt_T $opt_a $opt_r $opt_S);
use vars qw($opt_V $opt_h $opt_i $opt_n $opt_w $opt_c $opt_s $opt_T $opt_a $opt_r $opt_S $opt_o);
my $centplugins_path = "@CENTPLUGINS_TMP@";
my %ERRORS = ('OK' => 0, 'WARNING' => 1, 'CRITICAL' => 2, 'UNKNOWN' => 3);
@ -71,6 +71,12 @@ my %OPTION = (
"disable-warn-state" => undef
);
my %supported_oids = (
ifDescr => "IF_DESC",
ifAlias => "IF_ALIAS",
ifName => "IF_NAME"
);
# Catch UNKNOWN From GetOptions (like -i without value)
$SIG{'__WARN__'} = sub { print $_[0]; exit($ERRORS{'UNKNOWN'}); };
@ -101,8 +107,10 @@ GetOptions
"w=s" => \$opt_w, "warning=s" => \$opt_w,
"c=s" => \$opt_c, "critical=s" => \$opt_c,
"T=s" => \$opt_T, "r" => \$opt_r,
"S" => \$opt_S,
"a=i" => \$opt_a, "cache=s" => \$opt_a);
"S" => \$opt_S,
"a=i" => \$opt_a, "cache=s" => \$opt_a,
"o=s" => \$opt_o, "oid=s" => \$opt_o
);
if ($opt_V) {
print_revision($PROGNAME,'$Revision: 1.3 $');
@ -140,6 +148,15 @@ if (!defined($opt_a)) {
$opt_a = 3;
}
if (defined $opt_o) {
if (!exists $supported_oids{$opt_o}) {
print "Unsupported oid\n";
exit $ERRORS{UNKNOWN};
}
} else {
$opt_o = 'ifDescr';
}
my $critical = 95;
if ($opt_c && $opt_c =~ /[0-9]+/) {
$critical = $opt_c;
@ -169,7 +186,7 @@ if ($critical <= $warning){
$session = Centreon::SNMP::Utils::connection($ERRORS{'UNKNOWN'}, $session_params);
my $OID_DESC = $centreon{MIB2}{IF_DESC};
my $OID_DESC = $centreon{MIB2}{$supported_oids{$opt_o}};
my $OID_OPERSTATUS = $centreon{MIB2}{IF_OPERSTATUS};
my @operstatus = ("up","down","testing", "unknown", "dormant", "notPresent", "lowerLayerDown");
@ -559,6 +576,7 @@ sub print_usage () {
print " --snmp-timeout SNMP Timeout\n";
print " -s (--show) Describes all interfaces number (debug mode)\n";
print " -i (--interface) Set the interface number (2 by default)\n";
print " -o (--oid) Specify the OID used to retrieve the interface (ifDescr/ifAlias/ifName)\n";
print " -n (--name) Allows to use interface name with option -i instead of interface oid index\n";
print " (ex: -i \"eth0\" -n, -i \"VMware Virtual Ethernet Adapter for VMnet8\" -n\n";
print " (choose an unique expression for each interface)\n";