enhance junos bgp (#2321)
This commit is contained in:
parent
ef0d016576
commit
e93e628f8c
|
@ -24,12 +24,13 @@ use base qw(centreon::plugins::templates::counter);
|
||||||
|
|
||||||
use strict;
|
use strict;
|
||||||
use warnings;
|
use warnings;
|
||||||
use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold);
|
use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold_ng);
|
||||||
|
|
||||||
sub custom_status_output {
|
sub custom_status_output {
|
||||||
my ($self, %options) = @_;
|
my ($self, %options) = @_;
|
||||||
|
|
||||||
my $msg = sprintf("[Local IP '%s:%s', Type '%s', AS '%s'][Remote IP '%s:%s', Type '%s', AS '%s'] State is '%s', Status is '%s'",
|
return sprintf(
|
||||||
|
"[local IP '%s:%s', type '%s', AS '%s'][remote IP '%s:%s', type '%s', AS '%s'] state is '%s', status is '%s'",
|
||||||
$self->{result_values}->{local_ip},
|
$self->{result_values}->{local_ip},
|
||||||
$self->{result_values}->{local_port},
|
$self->{result_values}->{local_port},
|
||||||
$self->{result_values}->{local_type},
|
$self->{result_values}->{local_type},
|
||||||
|
@ -41,55 +42,37 @@ sub custom_status_output {
|
||||||
$self->{result_values}->{peer_state},
|
$self->{result_values}->{peer_state},
|
||||||
$self->{result_values}->{peer_status}
|
$self->{result_values}->{peer_status}
|
||||||
);
|
);
|
||||||
return $msg;
|
|
||||||
}
|
|
||||||
|
|
||||||
sub custom_status_calc {
|
|
||||||
my ($self, %options) = @_;
|
|
||||||
|
|
||||||
$self->{result_values}->{peer_state} = $options{new_datas}->{$self->{instance} . '_jnxBgpM2PeerState'};
|
|
||||||
$self->{result_values}->{peer_status} = $options{new_datas}->{$self->{instance} . '_jnxBgpM2PeerStatus'};
|
|
||||||
$self->{result_values}->{local_type} = $options{new_datas}->{$self->{instance} . '_jnxBgpM2PeerLocalAddrType'};
|
|
||||||
$self->{result_values}->{local_ip} = $options{new_datas}->{$self->{instance} . '_jnxBgpM2PeerLocalAddr'};
|
|
||||||
$self->{result_values}->{local_port} = $options{new_datas}->{$self->{instance} . '_jnxBgpM2PeerLocalPort'};
|
|
||||||
$self->{result_values}->{local_as} = $options{new_datas}->{$self->{instance} . '_jnxBgpM2PeerLocalAs'};
|
|
||||||
$self->{result_values}->{remote_type} = $options{new_datas}->{$self->{instance} . '_jnxBgpM2PeerRemoteAddrType'};
|
|
||||||
$self->{result_values}->{remote_ip} = $options{new_datas}->{$self->{instance} . '_jnxBgpM2PeerRemoteAddr'};
|
|
||||||
$self->{result_values}->{remote_port} = $options{new_datas}->{$self->{instance} . '_jnxBgpM2PeerRemotePort'};
|
|
||||||
$self->{result_values}->{remote_as} = $options{new_datas}->{$self->{instance} . '_jnxBgpM2PeerRemoteAs'};
|
|
||||||
$self->{result_values}->{peer_identifier} = $options{new_datas}->{$self->{instance} . '_jnxBgpM2PeerIdentifier'};
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
sub set_counters {
|
sub set_counters {
|
||||||
my ($self, %options) = @_;
|
my ($self, %options) = @_;
|
||||||
|
|
||||||
$self->{maps_counters_type} = [
|
$self->{maps_counters_type} = [
|
||||||
{ name => 'peers', type => 1, cb_prefix_output => 'prefix_peers_output',
|
{ name => 'peers', type => 1, cb_prefix_output => 'prefix_peers_output', message_multiple => 'All BGP peers are ok' }
|
||||||
message_multiple => 'All BGP peers are ok' },
|
|
||||||
];
|
];
|
||||||
|
|
||||||
$self->{maps_counters}->{peers} = [
|
$self->{maps_counters}->{peers} = [
|
||||||
{ label => 'status', threshold => 0, set => {
|
{ label => 'status', type => 2, critical_default => '%{peer_status} =~ /running/ && %{peer_state} !~ /established/', set => {
|
||||||
key_values => [ { name => 'jnxBgpM2PeerState' }, { name => 'jnxBgpM2PeerStatus' },
|
key_values => [
|
||||||
{ name => 'jnxBgpM2PeerLocalAddrType' }, { name => 'jnxBgpM2PeerLocalAddr' },
|
{ name => 'local_ip' }, { name => 'local_port' },
|
||||||
{ name => 'jnxBgpM2PeerLocalPort' }, { name => 'jnxBgpM2PeerLocalAs' },
|
{ name => 'local_type' }, { name => 'local_as' },
|
||||||
{ name => 'jnxBgpM2PeerRemoteAddrType' }, { name => 'jnxBgpM2PeerRemoteAddr' },
|
{ name => 'remote_ip' }, { name => 'remote_port' },
|
||||||
{ name => 'jnxBgpM2PeerRemotePort' }, { name => 'jnxBgpM2PeerRemoteAs' },
|
{ name => 'remote_type' }, { name => 'remote_as' },
|
||||||
{ name => 'jnxBgpM2PeerIdentifier' } ],
|
{ name => 'peer_state' }, { name => 'peer_status' },
|
||||||
closure_custom_calc => $self->can('custom_status_calc'),
|
{ name => 'peer_identifier' }
|
||||||
|
],
|
||||||
closure_custom_output => $self->can('custom_status_output'),
|
closure_custom_output => $self->can('custom_status_output'),
|
||||||
closure_custom_perfdata => sub { return 0; },
|
closure_custom_perfdata => sub { return 0; },
|
||||||
closure_custom_threshold_check => \&catalog_status_threshold,
|
closure_custom_threshold_check => \&catalog_status_threshold_ng
|
||||||
|
}
|
||||||
}
|
}
|
||||||
},
|
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
sub prefix_peers_output {
|
sub prefix_peers_output {
|
||||||
my ($self, %options) = @_;
|
my ($self, %options) = @_;
|
||||||
|
|
||||||
return "Peer '" . $options{instance_value}->{jnxBgpM2PeerIdentifier} . "' ";
|
return "Peer '" . $options{instance_value}->{peer_identifier} . "' ";
|
||||||
}
|
}
|
||||||
|
|
||||||
sub new {
|
sub new {
|
||||||
|
@ -98,76 +81,54 @@ sub new {
|
||||||
bless $self, $class;
|
bless $self, $class;
|
||||||
|
|
||||||
$options{options}->add_options(arguments => {
|
$options{options}->add_options(arguments => {
|
||||||
"filter-peer:s" => { name => 'filter_peer' },
|
'filter-peer:s' => { name => 'filter_peer' },
|
||||||
"filter-as:s" => { name => 'filter_as' },
|
'filter-as:s' => { name => 'filter_as' }
|
||||||
"warning-status:s" => { name => 'warning_status', default => '' },
|
|
||||||
"critical-status:s" => { name => 'critical_status',
|
|
||||||
default => '%{peer_status} =~ /running/ && %{peer_state} !~ /established/' },
|
|
||||||
});
|
});
|
||||||
|
|
||||||
return $self;
|
return $self;
|
||||||
}
|
}
|
||||||
|
|
||||||
sub check_options {
|
my $map_peer_state = {
|
||||||
my ($self, %options) = @_;
|
1 => 'idle', 2 => 'connect', 3 => 'active',
|
||||||
$self->SUPER::check_options(%options);
|
4 => 'opensent', 5 => 'openconfirm', 6 => 'established'
|
||||||
|
};
|
||||||
|
|
||||||
$self->change_macros(macros => ['warning_status', 'critical_status']);
|
my $map_peer_status = {
|
||||||
}
|
1 => 'halted', 2 => 'running'
|
||||||
|
};
|
||||||
|
|
||||||
my %map_peer_state = (
|
my $map_type = {
|
||||||
1 => 'idle',
|
0 => 'unknown', 1 => 'ipv4', 2 => 'ipv6', 3 => 'ipv4z', 4 => 'ipv6z', 16 => 'dns'
|
||||||
2 => 'connect',
|
};
|
||||||
3 => 'active',
|
|
||||||
4 => 'opensent',
|
|
||||||
5 => 'openconfirm',
|
|
||||||
6 => 'established',
|
|
||||||
);
|
|
||||||
|
|
||||||
my %map_peer_status = (
|
|
||||||
1 => 'halted',
|
|
||||||
2 => 'running',
|
|
||||||
);
|
|
||||||
|
|
||||||
my %map_type = (
|
|
||||||
0 => 'unknown',
|
|
||||||
1 => 'ipv4',
|
|
||||||
2 => 'ipv6',
|
|
||||||
3 => 'ipv4z',
|
|
||||||
4 => 'ipv6z',
|
|
||||||
16 => 'dns',
|
|
||||||
);
|
|
||||||
|
|
||||||
my $oid_jnxBgpM2PeerTable = '.1.3.6.1.4.1.2636.5.1.1.2.1.1';
|
my $oid_jnxBgpM2PeerTable = '.1.3.6.1.4.1.2636.5.1.1.2.1.1';
|
||||||
|
|
||||||
my $mapping = {
|
my $mapping = {
|
||||||
jnxBgpM2PeerIdentifier => { oid => '.1.3.6.1.4.1.2636.5.1.1.2.1.1.1.1' },
|
peer_identifier => { oid => '.1.3.6.1.4.1.2636.5.1.1.2.1.1.1.1' }, # jnxBgpM2PeerIdentifier
|
||||||
jnxBgpM2PeerState => { oid => '.1.3.6.1.4.1.2636.5.1.1.2.1.1.1.2', map => \%map_peer_state },
|
peer_state => { oid => '.1.3.6.1.4.1.2636.5.1.1.2.1.1.1.2', map => $map_peer_state }, # jnxBgpM2PeerState
|
||||||
jnxBgpM2PeerStatus => { oid => '.1.3.6.1.4.1.2636.5.1.1.2.1.1.1.3', map => \%map_peer_status },
|
peer_status => { oid => '.1.3.6.1.4.1.2636.5.1.1.2.1.1.1.3', map => $map_peer_status }, # jnxBgpM2PeerStatus
|
||||||
jnxBgpM2PeerLocalAddrType => { oid => '.1.3.6.1.4.1.2636.5.1.1.2.1.1.1.6', map => \%map_type },
|
local_type => { oid => '.1.3.6.1.4.1.2636.5.1.1.2.1.1.1.6', map => $map_type }, # jnxBgpM2PeerLocalAddrType
|
||||||
jnxBgpM2PeerLocalAddr => { oid => '.1.3.6.1.4.1.2636.5.1.1.2.1.1.1.7' },
|
local_ip => { oid => '.1.3.6.1.4.1.2636.5.1.1.2.1.1.1.7' }, # jnxBgpM2PeerLocalAddr
|
||||||
jnxBgpM2PeerLocalPort => { oid => '.1.3.6.1.4.1.2636.5.1.1.2.1.1.1.8' },
|
local_port => { oid => '.1.3.6.1.4.1.2636.5.1.1.2.1.1.1.8' }, # jnxBgpM2PeerLocalPort
|
||||||
jnxBgpM2PeerLocalAs => { oid => '.1.3.6.1.4.1.2636.5.1.1.2.1.1.1.9' },
|
local_as => { oid => '.1.3.6.1.4.1.2636.5.1.1.2.1.1.1.9' }, # jnxBgpM2PeerLocalAs
|
||||||
jnxBgpM2PeerRemoteAddrType => { oid => '.1.3.6.1.4.1.2636.5.1.1.2.1.1.1.10', map => \%map_type },
|
remote_type => { oid => '.1.3.6.1.4.1.2636.5.1.1.2.1.1.1.10', map => $map_type }, # jnxBgpM2PeerRemoteAddrType
|
||||||
jnxBgpM2PeerRemoteAddr => { oid => '.1.3.6.1.4.1.2636.5.1.1.2.1.1.1.11' },
|
remote_ip => { oid => '.1.3.6.1.4.1.2636.5.1.1.2.1.1.1.11' }, # jnxBgpM2PeerRemoteAddr
|
||||||
jnxBgpM2PeerRemotePort => { oid => '.1.3.6.1.4.1.2636.5.1.1.2.1.1.1.12' },
|
remote_port => { oid => '.1.3.6.1.4.1.2636.5.1.1.2.1.1.1.12' }, # jnxBgpM2PeerRemotePort
|
||||||
jnxBgpM2PeerRemoteAs => { oid => '.1.3.6.1.4.1.2636.5.1.1.2.1.1.1.13' },
|
remote_as => { oid => '.1.3.6.1.4.1.2636.5.1.1.2.1.1.1.13' } # jnxBgpM2PeerRemoteAs
|
||||||
};
|
};
|
||||||
|
|
||||||
sub manage_selection {
|
sub manage_selection {
|
||||||
my ($self, %options) = @_;
|
my ($self, %options) = @_;
|
||||||
|
|
||||||
$self->{peers} = {};
|
|
||||||
|
|
||||||
my $snmp_result = $options{snmp}->get_table(
|
my $snmp_result = $options{snmp}->get_table(
|
||||||
oid => $oid_jnxBgpM2PeerTable,
|
oid => $oid_jnxBgpM2PeerTable,
|
||||||
start => $mapping->{jnxBgpM2PeerIdentifier}->{oid},
|
end => $mapping->{remote_as}->{oid},
|
||||||
end => $mapping->{jnxBgpM2PeerRemoteAs}->{oid},
|
|
||||||
nothing_quit => 1
|
nothing_quit => 1
|
||||||
);
|
);
|
||||||
|
|
||||||
|
$self->{peers} = {};
|
||||||
foreach my $oid (keys %{$snmp_result}) {
|
foreach my $oid (keys %{$snmp_result}) {
|
||||||
next if ($oid !~ /^$mapping->{jnxBgpM2PeerIdentifier}->{oid}\.(.*)$/);
|
next if ($oid !~ /^$mapping->{peer_identifier}->{oid}\.(.*)$/);
|
||||||
my $instance = $1;
|
my $instance = $1;
|
||||||
|
|
||||||
my $result = $options{snmp}->map_instance(
|
my $result = $options{snmp}->map_instance(
|
||||||
|
@ -175,12 +136,17 @@ sub manage_selection {
|
||||||
results => $snmp_result,
|
results => $snmp_result,
|
||||||
instance => $instance
|
instance => $instance
|
||||||
);
|
);
|
||||||
$result->{jnxBgpM2PeerIdentifier} = join('.', map { hex($_) } unpack('(H2)*', $result->{jnxBgpM2PeerIdentifier}));
|
$result->{peer_identifier} = join('.', map { hex($_) } unpack('(H2)*', $result->{peer_identifier}));
|
||||||
$result->{jnxBgpM2PeerLocalAddr} = join('.', map { hex($_) } unpack('(H2)*', $result->{jnxBgpM2PeerLocalAddr}));
|
$result->{local_ip} = join('.', map { hex($_) } unpack('(H2)*', $result->{local_ip}));
|
||||||
$result->{jnxBgpM2PeerRemoteAddr} = join('.', map { hex($_) } unpack('(H2)*', $result->{jnxBgpM2PeerRemoteAddr}));
|
|
||||||
|
$result->{remote_ip} = defined($result->{remote_ip}) ? join('.', map { hex($_) } unpack('(H2)*', $result->{remote_ip})) : '-';
|
||||||
|
$result->{remote_port} = defined($result->{remote_port}) ? $result->{remote_port} : '-';
|
||||||
|
$result->{remote_as} = defined($result->{remote_as}) ? $result->{remote_as} : '-';
|
||||||
|
$result->{remote_type} = defined($result->{remote_type}) ? $result->{remote_type} : '-';
|
||||||
|
$result->{local_as} = defined($result->{local_as}) ? $result->{local_as} : '-';
|
||||||
|
|
||||||
if (defined($self->{option_results}->{filter_peer}) && $self->{option_results}->{filter_peer} ne '' &&
|
if (defined($self->{option_results}->{filter_peer}) && $self->{option_results}->{filter_peer} ne '' &&
|
||||||
$result->{jnxBgpM2PeerIdentifier} !~ /$self->{option_results}->{filter_peer}/) {
|
$result->{peer_identifier} !~ /$self->{option_results}->{filter_peer}/) {
|
||||||
$self->{output}->output_add(
|
$self->{output}->output_add(
|
||||||
long_msg => "skipping peer '" . $result->{jnxBgpM2PeerIdentifier} . "': no matching filter.",
|
long_msg => "skipping peer '" . $result->{jnxBgpM2PeerIdentifier} . "': no matching filter.",
|
||||||
debug => 1
|
debug => 1
|
||||||
|
@ -188,7 +154,7 @@ sub manage_selection {
|
||||||
next;
|
next;
|
||||||
}
|
}
|
||||||
|
|
||||||
$self->{peers}->{$instance} = { %{$result} };
|
$self->{peers}->{$instance} = $result;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (scalar(keys %{$self->{peers}}) <= 0) {
|
if (scalar(keys %{$self->{peers}}) <= 0) {
|
||||||
|
|
Loading…
Reference in New Issue