2015-07-21 11:51:02 +02:00
|
|
|
#
|
2019-01-09 09:57:11 +01:00
|
|
|
# Copyright 2019 Centreon (http://www.centreon.com/)
|
2015-07-21 11:51:02 +02:00
|
|
|
#
|
|
|
|
# Centreon is a full-fledged industry-strength solution that meets
|
|
|
|
# the needs in IT infrastructure and application monitoring for
|
|
|
|
# service performance.
|
|
|
|
#
|
|
|
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
# you may not use this file except in compliance with the License.
|
|
|
|
# You may obtain a copy of the License at
|
|
|
|
#
|
|
|
|
# http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
#
|
|
|
|
# Unless required by applicable law or agreed to in writing, software
|
|
|
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
# See the License for the specific language governing permissions and
|
|
|
|
# limitations under the License.
|
|
|
|
#
|
2015-03-30 15:38:47 +02:00
|
|
|
|
|
|
|
package apps::protocols::bgp::4::mode::bgppeerstate;
|
|
|
|
|
2016-11-22 14:59:19 +01:00
|
|
|
use base qw(centreon::plugins::templates::counter);
|
2015-03-30 15:38:47 +02:00
|
|
|
|
|
|
|
use strict;
|
|
|
|
use warnings;
|
|
|
|
|
2016-11-22 14:59:19 +01:00
|
|
|
my $instance_mode;
|
2015-03-30 15:38:47 +02:00
|
|
|
|
2016-11-22 14:59:19 +01:00
|
|
|
sub custom_status_threshold {
|
|
|
|
my ($self, %options) = @_;
|
|
|
|
my $status = 'ok';
|
|
|
|
my $message;
|
|
|
|
eval {
|
|
|
|
local $SIG{__WARN__} = sub { $message = $_[0]; };
|
|
|
|
local $SIG{__DIE__} = sub { $message = $_[0]; };
|
|
|
|
if (defined($instance_mode->{option_results}->{critical_status}) && $instance_mode->{option_results}->{critical_status} ne '' &&
|
|
|
|
eval "$instance_mode->{option_results}->{critical_status}") {
|
|
|
|
$status = 'critical';
|
|
|
|
} elsif (defined($instance_mode->{option_results}->{warning_status}) && $instance_mode->{option_results}->{warning_status} ne '' &&
|
|
|
|
eval "$instance_mode->{option_results}->{warning_status}") {
|
|
|
|
$status = 'warning';
|
|
|
|
}
|
|
|
|
};
|
|
|
|
if (defined($message)) {
|
|
|
|
$self->{output}->output_add(long_msg => 'filter status issue: ' . $message);
|
|
|
|
}
|
2015-03-30 15:38:47 +02:00
|
|
|
|
2016-11-22 14:59:19 +01:00
|
|
|
return $status;
|
|
|
|
}
|
|
|
|
|
|
|
|
sub custom_status_output {
|
|
|
|
my ($self, %options) = @_;
|
|
|
|
my $msg = "AS:'" . $self->{result_values}->{as} . "' ";
|
|
|
|
$msg .= " Local: '" . $self->{result_values}->{local} . "'";
|
|
|
|
$msg .= " Remote: '" . $self->{result_values}->{remote} . "'";
|
|
|
|
$msg .= " Peer State: '" . $self->{result_values}->{peerstate} . "'";
|
|
|
|
$msg .= " Admin State : '" . $self->{result_values}->{adminstate} . "'";
|
|
|
|
|
|
|
|
return $msg;
|
|
|
|
}
|
|
|
|
|
|
|
|
sub custom_status_calc {
|
|
|
|
my ($self, %options) = @_;
|
|
|
|
|
|
|
|
$self->{result_values}->{adminstate} = $options{new_datas}->{$self->{instance} . '_adminstate'};
|
|
|
|
$self->{result_values}->{peerstate} = $options{new_datas}->{$self->{instance} . '_peerstate'};
|
|
|
|
$self->{result_values}->{display} = $options{new_datas}->{$self->{instance} . '_display'};
|
|
|
|
$self->{result_values}->{local} = $options{new_datas}->{$self->{instance} . '_local'};
|
|
|
|
$self->{result_values}->{remote} = $options{new_datas}->{$self->{instance} . '_remote'};
|
|
|
|
$self->{result_values}->{as} = $options{new_datas}->{$self->{instance} . '_as'};
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
sub set_counters {
|
|
|
|
my ($self, %options) = @_;
|
|
|
|
|
|
|
|
$self->{maps_counters_type} = [
|
|
|
|
{ name => 'peers', type => 1, cb_prefix_output => 'prefix_peers_output', message_multiple => 'All BGP peers are ok' },
|
|
|
|
];
|
|
|
|
$self->{maps_counters}->{peers} = [
|
2016-11-22 16:30:48 +01:00
|
|
|
{ label => 'status', threshold => 0, set => {
|
2016-11-22 14:59:19 +01:00
|
|
|
key_values => [ { name => 'adminstate' }, { name => 'peerstate' }, { name => 'display' },
|
|
|
|
{ name => 'local' }, { name => 'remote' }, { name => 'as' } ],
|
|
|
|
closure_custom_calc => $self->can('custom_status_calc'),
|
|
|
|
closure_custom_output => $self->can('custom_status_output'),
|
|
|
|
closure_custom_perfdata => sub { return 0; },
|
|
|
|
closure_custom_threshold_check => $self->can('custom_status_threshold'),
|
|
|
|
}
|
|
|
|
},
|
|
|
|
{ label => 'updates', set => {
|
|
|
|
key_values => [ { name => 'seconds' }, { name => 'display' } ],
|
|
|
|
output_template => 'Last update : %ss',
|
|
|
|
perfdatas => [
|
|
|
|
{ label => 'seconds', value => 'seconds_absolute', template => '%s',
|
|
|
|
unit => 's', min => 0, label_extra_instance => 1, instance_use => 'display_absolute' },
|
|
|
|
],
|
|
|
|
}
|
|
|
|
},
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
sub prefix_peers_output {
|
|
|
|
my ($self, %options) = @_;
|
|
|
|
|
|
|
|
return "Peer: '" . $options{instance_value}->{display} . "' ";
|
|
|
|
}
|
2015-03-31 13:41:52 +02:00
|
|
|
|
2015-03-30 15:38:47 +02:00
|
|
|
sub new {
|
|
|
|
my ($class, %options) = @_;
|
|
|
|
my $self = $class->SUPER::new(package => __PACKAGE__, %options);
|
|
|
|
bless $self, $class;
|
|
|
|
|
|
|
|
$self->{version} = '1.0';
|
|
|
|
$options{options}->add_options(arguments =>
|
|
|
|
{
|
2016-11-22 14:59:19 +01:00
|
|
|
"filter-peer:s" => { name => 'filter_peer' },
|
|
|
|
"filter-as:s" => { name => 'filter_as' },
|
|
|
|
"warning-status:s" => { name => 'warning_status', default => '' },
|
2016-11-23 19:20:53 +01:00
|
|
|
"critical-status:s" => { name => 'critical_status', default => '' },
|
2015-03-30 15:38:47 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
return $self;
|
|
|
|
}
|
|
|
|
|
2016-11-22 14:59:19 +01:00
|
|
|
sub change_macros {
|
2015-03-30 15:38:47 +02:00
|
|
|
my ($self, %options) = @_;
|
2016-11-22 14:59:19 +01:00
|
|
|
|
|
|
|
foreach (('warning_status', 'critical_status')) {
|
|
|
|
if (defined($self->{option_results}->{$_})) {
|
|
|
|
$self->{option_results}->{$_} =~ s/%\{(.*?)\}/\$self->{result_values}->{$1}/g;
|
2015-03-31 13:41:52 +02:00
|
|
|
}
|
2015-03-30 17:05:50 +02:00
|
|
|
}
|
2015-03-30 15:38:47 +02:00
|
|
|
}
|
|
|
|
|
2016-11-22 14:59:19 +01:00
|
|
|
sub check_options {
|
2015-03-30 15:38:47 +02:00
|
|
|
my ($self, %options) = @_;
|
2016-11-22 14:59:19 +01:00
|
|
|
$self->SUPER::check_options(%options);
|
2015-03-31 13:41:52 +02:00
|
|
|
|
2016-11-22 14:59:19 +01:00
|
|
|
$instance_mode = $self;
|
|
|
|
$self->change_macros();
|
2015-03-30 15:38:47 +02:00
|
|
|
}
|
|
|
|
|
2016-11-22 14:59:19 +01:00
|
|
|
my %map_peer_state = (
|
|
|
|
1 => 'idle',
|
|
|
|
2 => 'connect',
|
|
|
|
3 => 'active',
|
|
|
|
4 => 'opensent',
|
|
|
|
5 => 'openconfirm',
|
|
|
|
6 => 'established',
|
|
|
|
);
|
|
|
|
|
|
|
|
my %map_admin_state = (
|
|
|
|
1 => 'stop',
|
|
|
|
2 => 'start',
|
|
|
|
);
|
|
|
|
|
|
|
|
my $oid_bgpPeerTable = '.1.3.6.1.2.1.15.3';
|
|
|
|
|
|
|
|
my $mapping = {
|
|
|
|
bgpPeerState => { oid => '.1.3.6.1.2.1.15.3.1.2', map => \%map_peer_state },
|
|
|
|
bgpPeerAdminStatus => { oid => '.1.3.6.1.2.1.15.3.1.3', map => \%map_admin_state },
|
|
|
|
bgpPeerRemoteAs => { oid => '.1.3.6.1.2.1.15.3.1.9' },
|
|
|
|
bgpPeerLocalAddr => { oid => '.1.3.6.1.2.1.15.3.1.5' },
|
|
|
|
bgpPeerLocalPort => { oid => '.1.3.6.1.2.1.15.3.1.6' },
|
|
|
|
bgpPeerRemoteAddr => { oid => '.1.3.6.1.2.1.15.3.1.7' },
|
|
|
|
bgpPeerRemotePort => { oid => '.1.3.6.1.2.1.15.3.1.8' },
|
|
|
|
bgpPeerInUpdateElpasedTime => { oid => '.1.3.6.1.2.1.15.3.1.24' },
|
|
|
|
};
|
|
|
|
|
|
|
|
sub manage_selection {
|
2015-09-18 16:11:46 +02:00
|
|
|
my ($self, %options) = @_;
|
|
|
|
|
2016-11-22 14:59:19 +01:00
|
|
|
$self->{peers} = {};
|
|
|
|
|
|
|
|
my $result = $options{snmp}->get_table(oid => $oid_bgpPeerTable, nothing_quit => 1);
|
|
|
|
foreach my $oid (keys %{$result}) {
|
|
|
|
next if ($oid !~ /^$mapping->{bgpPeerState}->{oid}\.(.*)$/);
|
|
|
|
my $instance = $1;
|
|
|
|
my $mapped_value = $options{snmp}->map_instance(mapping => $mapping, results => $result, instance => $instance);
|
|
|
|
|
|
|
|
my $local_addr = $mapped_value->{bgpPeerLocalAddr} . ':' . $mapped_value->{bgpPeerLocalPort};
|
|
|
|
my $remote_addr = $mapped_value->{bgpPeerRemoteAddr} . ':' . $mapped_value->{bgpPeerRemotePort};
|
|
|
|
|
|
|
|
if (defined($self->{option_results}->{filter_peer}) && $self->{option_results}->{filter_peer} ne '' &&
|
|
|
|
$instance !~ /$self->{option_results}->{filter_peer}/) {
|
|
|
|
$self->{output}->output_add(long_msg => "skipping peer '" . $instance . "': no matching filter.", debug => 1);
|
|
|
|
next;
|
2015-09-18 16:11:46 +02:00
|
|
|
}
|
2016-11-22 14:59:19 +01:00
|
|
|
if (defined($self->{option_results}->{filter_as}) && $self->{option_results}->{filter_as} ne '' &&
|
|
|
|
$instance !~ /$self->{option_results}->{filter_as}/) {
|
|
|
|
$self->{output}->output_add(long_msg => "skipping AS '" . $mapped_value->{bgpPeerRemoteAs} . "': no matching filter.", debug => 1);
|
|
|
|
next;
|
2015-09-18 16:11:46 +02:00
|
|
|
}
|
|
|
|
|
2016-11-22 14:59:19 +01:00
|
|
|
$self->{peers}->{$instance} = { adminstate => $mapped_value->{bgpPeerAdminStatus}, local => $local_addr,
|
|
|
|
peerstate => $mapped_value->{bgpPeerState}, remote => $remote_addr,
|
|
|
|
seconds => $mapped_value->{bgpPeerInUpdateElpasedTime}, as => $mapped_value->{bgpPeerRemoteAs},
|
|
|
|
display => $instance };
|
|
|
|
}
|
2017-04-24 19:18:24 +02:00
|
|
|
|
|
|
|
if (scalar(keys %{$self->{peers}}) <= 0) {
|
|
|
|
$self->{output}->add_option_msg(short_msg => 'No peers detected, check your filter ? ');
|
|
|
|
$self->{output}->option_exit();
|
|
|
|
}
|
2015-09-18 16:11:46 +02:00
|
|
|
}
|
|
|
|
|
2016-11-22 14:59:19 +01:00
|
|
|
1;
|
2015-03-30 15:38:47 +02:00
|
|
|
|
|
|
|
__END__
|
|
|
|
|
|
|
|
=head1 MODE
|
|
|
|
|
2015-03-31 13:41:52 +02:00
|
|
|
Check BGP basic infos (BGP4-MIB.mib and rfc4273)
|
|
|
|
|
2015-03-30 15:38:47 +02:00
|
|
|
=over 8
|
|
|
|
|
2016-11-22 14:59:19 +01:00
|
|
|
=item B<--filter-as>
|
2015-03-30 17:05:50 +02:00
|
|
|
|
2016-11-22 14:59:19 +01:00
|
|
|
Filter based on AS number (regexp allowed)
|
2015-03-30 17:05:50 +02:00
|
|
|
|
2016-11-22 14:59:19 +01:00
|
|
|
=item B<--filter-peer>
|
2015-03-31 13:41:52 +02:00
|
|
|
|
2016-11-22 14:59:19 +01:00
|
|
|
Filter based on IP of peers (regexp allowed)
|
2015-03-31 13:41:52 +02:00
|
|
|
|
2016-11-22 16:34:27 +01:00
|
|
|
=item B<--warning-updates>
|
2015-03-31 13:41:52 +02:00
|
|
|
|
2016-11-22 14:59:19 +01:00
|
|
|
Warning threshold on last update (seconds)
|
2015-03-30 15:38:47 +02:00
|
|
|
|
2016-11-22 16:34:27 +01:00
|
|
|
=item B<--critical-updates>
|
2016-11-22 14:59:19 +01:00
|
|
|
|
|
|
|
Critical threshold on last update (seconds)
|
|
|
|
|
|
|
|
=item B<--warning-status>
|
2015-03-30 15:38:47 +02:00
|
|
|
|
2016-11-22 16:33:38 +01:00
|
|
|
Specify admin and peer state that trigger a warning. Can use %{adminstate} and %{peerstate}
|
|
|
|
e.g --warning-status "%{adminstate} =~ /stop"
|
2015-03-30 15:38:47 +02:00
|
|
|
|
2016-11-22 14:59:19 +01:00
|
|
|
=item B<--critical-status>
|
|
|
|
|
2016-11-22 16:33:38 +01:00
|
|
|
Specify admin and peer state that trigger a critical. Can use %{adminstate} and %{peerstate}
|
2016-11-22 14:59:19 +01:00
|
|
|
|
|
|
|
=back
|
|
|
|
|
|
|
|
=cut
|