mirror of
https://github.com/centreon/centreon-plugins.git
synced 2025-07-26 23:24:27 +02:00
enh(protocol/ospf): mode neighbor - harden code (#3258)
This commit is contained in:
parent
45174c68a8
commit
f6bcff4414
@ -107,14 +107,10 @@ sub new {
|
|||||||
}
|
}
|
||||||
|
|
||||||
my %map_state = (
|
my %map_state = (
|
||||||
1 => 'down',
|
1 => 'down', 2 => 'attempt',
|
||||||
2 => 'attempt',
|
3 => 'init', 4 => 'twoWay',
|
||||||
3 => 'init',
|
5 => 'exchangeStart', 6 => 'exchange',
|
||||||
4 => 'twoWay',
|
7 => 'loading', 8 => 'full'
|
||||||
5 => 'exchangeStart',
|
|
||||||
6 => 'exchange',
|
|
||||||
7 => 'loading',
|
|
||||||
8 => 'full'
|
|
||||||
);
|
);
|
||||||
my $mapping = {
|
my $mapping = {
|
||||||
NbrIpAddr => { oid => '.1.3.6.1.2.1.14.10.1.1' },
|
NbrIpAddr => { oid => '.1.3.6.1.2.1.14.10.1.1' },
|
||||||
@ -127,24 +123,27 @@ my $oid_ospfNbrEntry = '.1.3.6.1.2.1.14.10.1';
|
|||||||
sub manage_selection {
|
sub manage_selection {
|
||||||
my ($self, %options) = @_;
|
my ($self, %options) = @_;
|
||||||
|
|
||||||
$self->{nb} = {};
|
|
||||||
$self->{global} = { total => 0 };
|
$self->{global} = { total => 0 };
|
||||||
my $snmp_result = $options{snmp}->get_table(
|
my $snmp_result = $options{snmp}->get_table(
|
||||||
oid => $oid_ospfNbrEntry,
|
oid => $oid_ospfNbrEntry,
|
||||||
nothing_quit => 1
|
nothing_quit => 1
|
||||||
);
|
);
|
||||||
|
|
||||||
|
$self->{nb} = {};
|
||||||
foreach my $oid (keys %{$snmp_result}) {
|
foreach my $oid (keys %{$snmp_result}) {
|
||||||
next if ($oid !~ /^$mapping->{NbrState}->{oid}\.(.*)$/);
|
next if ($oid !~ /^$mapping->{NbrState}->{oid}\.(.*)$/);
|
||||||
my $instance = $1;
|
my $instance = $1;
|
||||||
my $result = $options{snmp}->map_instance(mapping => $mapping, results => $snmp_result, instance => $instance);
|
|
||||||
|
|
||||||
|
$self->{nb}->{$instance} = $options{snmp}->map_instance(mapping => $mapping, results => $snmp_result, instance => $instance);
|
||||||
|
if (!defined($self->{nb}->{$instance}->{NbrIpAddr})) {
|
||||||
|
$instance =~ /^(.*)\.(\d+)$/;
|
||||||
|
$self->{nb}->{$instance}->{NbrIpAddr} = $1;
|
||||||
|
}
|
||||||
$self->{global}->{total}++;
|
$self->{global}->{total}++;
|
||||||
$self->{nb}->{$instance} = { %$result };
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (scalar(keys %{$self->{nb}}) <= 0) {
|
if (scalar(keys %{$self->{nb}}) <= 0) {
|
||||||
$self->{output}->add_option_msg(short_msg => "No neighbors found.");
|
$self->{output}->add_option_msg(short_msg => 'No neighbors found.');
|
||||||
$self->{output}->option_exit();
|
$self->{output}->option_exit();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user