Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add the -A/--use-ifalias option to do name lookup from ifAlias #17

Merged
merged 1 commit into from
Feb 6, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion plugins/check_snmp_int.pl
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
my $index_table = '1.3.6.1.2.1.2.2.1.1';
my $descr_table = '1.3.6.1.2.1.2.2.1.2';
my $name_table = '1.3.6.1.2.1.31.1.1.1.1';
my $alias_table = '.1.3.6.1.2.1.31.1.1.1.18';
my $oper_table = '1.3.6.1.2.1.2.2.1.8.';
my $admin_table = '1.3.6.1.2.1.2.2.1.7.';
my $speed_table = '1.3.6.1.2.1.2.2.1.5.';
Expand Down Expand Up @@ -81,6 +82,7 @@
my $o_gig= undef; # output in GBytes or Gbits (-G)
my $o_prct= undef; # output in % of max speed (-u)
my $o_use_ifname= undef; # use IF-MIB::ifName instead of IF-MIB::ifDescr
my $o_use_ifalias= undef; # use IF-MIB::ifAlias instead of IF-MIB::ifDescr

my $o_timeout= undef; # Timeout (Default 5)
# SNMP Message size parameter (Makina Corpus contrib)
Expand Down Expand Up @@ -151,7 +153,7 @@ sub write_file {
sub p_version { print "check_snmp_int version : $Version\n"; }

sub print_usage {
print "Usage: $0 [-v] -H <host> -C <snmp_community> [-2] | (-l login -x passwd [-X pass -L <authp>,<privp>) [-p <port>] -n <name in desc_oid> [-i -a -D] [-r] [-f[eSyY]] [-k[qBMGu] -g -w<warn levels> -c<crit levels> -d<delta>] [-o <octet_length>] [-t <timeout>] [-s] --label [-V]\n";
print "Usage: $0 [-v] -H <host> -C <snmp_community> [-2] | (-l login -x passwd [-X pass -L <authp>,<privp>) [-p <port>] -n <name in desc_oid> [-N -A -i -a -D] [-r] [-f[eSyY]] [-k[qBMGu] -g -w<warn levels> -c<crit levels> -d<delta>] [-o <octet_length>] [-t <timeout>] [-s] --label [-V]\n";
}

sub isnnum { # Return true if arg is not a number
Expand Down Expand Up @@ -192,6 +194,8 @@ sub help {
Do not use regexp to match NAME in description OID
-N, --use-ifname
Use IF-MIB::ifName as source for NIC name instead of IF-MIB::ifDescr
-A, --use-ifalias
Use IF-MIB::ifAlias as source for NIC name instead of IF-MIB::ifDescr
-i, --inverse
Make critical when up
-a, --admin
Expand Down Expand Up @@ -260,6 +264,7 @@ sub check_options {
'p:i' => \$o_port, 'port:i' => \$o_port,
'n:s' => \$o_descr, 'name:s' => \$o_descr,
'N' => \$o_use_ifname, 'use-ifname' => \$o_use_ifname,
'A' => \$o_use_ifalias, 'use-ifalias' => \$o_use_ifalias,
'C:s' => \$o_community, 'community:s' => \$o_community,
'2' => \$o_version2, 'v2c' => \$o_version2,
'l:s' => \$o_login, 'login:s' => \$o_login,
Expand Down Expand Up @@ -451,9 +456,17 @@ sub check_options {

# Get description table
my $query_table = $descr_table;
if (defined($o_use_ifalias) and defined($o_use_ifname)) {
printf("ERROR: Options -N and -A are exclusive. Please select only one.\n");
$session->close;
exit $ERRORS{"UNKNOWN"};
}
if (defined($o_use_ifname)) {
$query_table = $name_table;
}
if (defined($o_use_ifalias)) {
$query_table = $alias_table;
}
my $resultat = $session->get_table(
Baseoid => $query_table
);
Expand Down