From 83251e5d3103d92b09ff3159fb6cc2e15ce61b13 Mon Sep 17 00:00:00 2001 From: garnier-quentin Date: Wed, 16 Dec 2015 16:45:50 +0100 Subject: [PATCH] + Enhance snmp library (can force getnext and avoid a loop) --- centreon-plugins/centreon/plugins/snmp.pm | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/centreon-plugins/centreon/plugins/snmp.pm b/centreon-plugins/centreon/plugins/snmp.pm index b8562bbfb..4bcf9f7b1 100644 --- a/centreon-plugins/centreon/plugins/snmp.pm +++ b/centreon-plugins/centreon/plugins/snmp.pm @@ -52,6 +52,7 @@ sub new { "snmp-retries:s" => { name => 'snmp_retries', default => 5 }, "maxrepetitions:s" => { name => 'maxrepetitions', default => 50 }, "subsetleef:s" => { name => 'subsetleef', default => 50 }, + "snmp-force-getnext" => { name => 'snmp_force_getnext' }, "snmp-username:s" => { name => 'snmp_security_name' }, "authpassphrase:s" => { name => 'snmp_auth_passphrase' }, "authprotocol:s" => { name => 'snmp_auth_protocol' }, @@ -354,7 +355,7 @@ sub get_multiple_table { my $vb = new SNMP::VarList(@bindings); - if ($self->is_snmpv1()) { + if ($self->is_snmpv1() || defined($self->{snmp_force_getnext})) { $self->{session}->getnext($vb); } else { my $current_repeat_count = floor($repeat_count / (scalar(keys %{$working_oids}))); @@ -420,6 +421,12 @@ sub get_multiple_table { $working_oids->{ $bases[$pos % $current_oids] }->{start} = $complete_oid; } + + # infinite loop. Some equipments it returns nothing!!?? + if ($pos == -1) { + $self->{output}->add_option_msg(short_msg => "SNMP Table Request: problem to get values (try --snmp-force-getnext option)"); + $self->{output}->option_exit(exit_litteral => $self->{snmp_errors_exit}); + } } my $total = 0; @@ -495,7 +502,7 @@ sub get_table { $last_oid =~ /(.*)\.(\d+)([\.\s]*)$/; my $vb = new SNMP::VarList([$1, $2]); - if ($self->is_snmpv1()) { + if ($self->is_snmpv1() || defined($self->{snmp_force_getnext})) { $self->{session}->getnext($vb); } else { $self->{session}->getbulk(0, $repeat_count, $vb); @@ -636,6 +643,7 @@ sub check_options { $self->{output}->option_exit(); } + $self->{snmp_force_getnext} = $options{option_results}->{snmp_force_getnext}; $self->{maxrepetitions} = $options{option_results}->{maxrepetitions}; $self->{subsetleef} = (defined($options{option_results}->{subsetleef}) && $options{option_results}->{subsetleef} =~ /^[0-9]+$/) ? $options{option_results}->{subsetleef} : 50; $self->{snmp_errors_exit} = $options{option_results}->{snmp_errors_exit}; @@ -842,6 +850,10 @@ Max repetitions value (default: 50) (only for SNMP v2 and v3). How many oid values per SNMP request (default: 50) (for get_leef method. Be cautious whe you set it. Prefer to let the default value). +=item B<--snmp-force-getnext> + +Use snmp getnext function (even in snmp v2c and v3). + =item B<--snmp-username> Security name (only for SNMP v3).