| 1 |
# |
| 2 |
# Copyright 2024 Centreon (http://www.centreon.com/) |
| 3 |
# |
| 4 |
# Centreon is a full-fledged industry-strength solution that meets |
| 5 |
# the needs in IT infrastructure and application monitoring for |
| 6 |
# service performance. |
| 7 |
# |
| 8 |
# Licensed under the Apache License, Version 2.0 (the "License"); |
| 9 |
# you may not use this file except in compliance with the License. |
| 10 |
# You may obtain a copy of the License at |
| 11 |
# |
| 12 |
# http://www.apache.org/licenses/LICENSE-2.0 |
| 13 |
# |
| 14 |
# Unless required by applicable law or agreed to in writing, software |
| 15 |
# distributed under the License is distributed on an "AS IS" BASIS, |
| 16 |
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 17 |
# See the License for the specific language governing permissions and |
| 18 |
# limitations under the License. |
| 19 |
# |
| 20 |
|
| 21 |
package network::nokia::timos::snmp::mode::listbgp; |
| 22 |
|
| 23 |
use base qw(centreon::plugins::mode); |
| 24 |
|
| 25 |
use strict; |
| 26 |
use warnings; |
| 27 |
|
| 28 |
sub new { |
| 29 |
my ($class, %options) = @_; |
| 30 |
my $self = $class->SUPER::new(package => __PACKAGE__, %options); |
| 31 |
bless $self, $class; |
| 32 |
|
| 33 |
$options{options}->add_options(arguments => |
| 34 |
{ |
| 35 |
}); |
| 36 |
return $self; |
| 37 |
} |
| 38 |
|
| 39 |
sub check_options { |
| 40 |
my ($self, %options) = @_; |
| 41 |
$self->SUPER::init(%options); |
| 42 |
} |
| 43 |
|
| 44 |
my %map_status = (1 => 'unknown', 2 => 'inService', 3 => 'outOfService', |
| 45 |
4 => 'transition', 5 => 'disabled', |
| 46 |
); |
| 47 |
my %map_type = (1 => 'noType', 2 => 'internal', 3 => 'external'); |
| 48 |
my $oid_vRtrName = '.1.3.6.1.4.1.6527.3.1.2.3.1.1.4'; |
| 49 |
my $mapping = { |
| 50 |
tBgpPeerNgDescription => { oid => '.1.3.6.1.4.1.6527.3.1.2.14.4.7.1.7' }, |
| 51 |
tBgpPeerNgPeerType => { oid => '.1.3.6.1.4.1.6527.3.1.2.14.4.7.1.27', map => \%map_type }, |
| 52 |
tBgpPeerNgOperStatus => { oid => '.1.3.6.1.4.1.6527.3.1.2.14.4.7.1.42', map => \%map_status }, |
| 53 |
tBgpPeerNgPeerAS4Byte => { oid => '.1.3.6.1.4.1.6527.3.1.2.14.4.7.1.66' }, |
| 54 |
}; |
| 55 |
|
| 56 |
sub manage_selection { |
| 57 |
my ($self, %options) = @_; |
| 58 |
|
| 59 |
my $snmp_result = $options{snmp}->get_multiple_table(oids => [ |
| 60 |
{ oid => $oid_vRtrName }, |
| 61 |
{ oid => $mapping->{tBgpPeerNgOperStatus}->{oid} }, |
| 62 |
{ oid => $mapping->{tBgpPeerNgPeerType}->{oid} }, |
| 63 |
{ oid => $mapping->{tBgpPeerNgDescription}->{oid} }, |
| 64 |
{ oid => $mapping->{tBgpPeerNgPeerAS4Byte}->{oid} }, |
| 65 |
], return_type => 1, nothing_quit => 1); |
| 66 |
$self->{bgp} = {}; |
| 67 |
foreach my $oid (keys %$snmp_result) { |
| 68 |
next if ($oid !~ /^$mapping->{tBgpPeerNgPeerAS4Byte}->{oid}\.(\d+)\.(\d+)\.(.*)$/); |
| 69 |
my ($vrtr_id, $peer_type, $peer_addr) = ($1, $2, $3); |
| 70 |
|
| 71 |
my $vrtr_name = $snmp_result->{$oid_vRtrName . '.' . $vrtr_id}; |
| 72 |
my $result = $options{snmp}->map_instance(mapping => $mapping, results => $snmp_result, instance => $vrtr_id . '.' . $peer_type . '.' . $peer_addr); |
| 73 |
|
| 74 |
$self->{bgp}->{$vrtr_id . '.' . $peer_type . '.' . $peer_addr} = { |
| 75 |
vrtr_name => $vrtr_name, peer_type => $result->{tBgpPeerNgPeerType}, |
| 76 |
peer_addr => $peer_addr, peer_as => $result->{tBgpPeerNgPeerAS4Byte}, |
| 77 |
status => $result->{tBgpPeerNgOperStatus}, description => $result->{tBgpPeerNgDescription} }; |
| 78 |
} |
| 79 |
} |
| 80 |
|
| 81 |
sub run { |
| 82 |
my ($self, %options) = @_; |
| 83 |
|
| 84 |
$self->manage_selection(%options); |
| 85 |
foreach my $instance (sort keys %{$self->{bgp}}) { |
| 86 |
$self->{output}->output_add(long_msg => '[vrtr_name = ' . $self->{bgp}->{$instance}->{vrtr_name} . |
| 87 |
"] [peer_addr = '" . $self->{bgp}->{$instance}->{peer_addr} . |
| 88 |
"'] [peer_as = '" . $self->{bgp}->{$instance}->{peer_as} . |
| 89 |
"'] [peer_type = '" . $self->{bgp}->{$instance}->{peer_type} . |
| 90 |
"'] [description = '" . $self->{bgp}->{$instance}->{description} . |
| 91 |
"'] [status = '" . $self->{bgp}->{$instance}->{status} . |
| 92 |
'"]'); |
| 93 |
} |
| 94 |
|
| 95 |
$self->{output}->output_add(severity => 'OK', |
| 96 |
short_msg => 'List BGP:'); |
| 97 |
$self->{output}->display(nolabel => 1, force_ignore_perfdata => 1, force_long_output => 1); |
| 98 |
$self->{output}->exit(); |
| 99 |
} |
| 100 |
|
| 101 |
sub disco_format { |
| 102 |
my ($self, %options) = @_; |
| 103 |
|
| 104 |
$self->{output}->add_disco_format(elements => ['vrtr_name', 'peer_addr', 'peer_as', 'peer_type', 'status', 'description']); |
| 105 |
} |
| 106 |
|
| 107 |
sub disco_show { |
| 108 |
my ($self, %options) = @_; |
| 109 |
|
| 110 |
$self->manage_selection(%options); |
| 111 |
foreach my $instance (sort keys %{$self->{bgp}}) { |
| 112 |
$self->{output}->add_disco_entry(vrtr_name => $self->{bgp}->{$instance}->{vrtr_name}, |
| 113 |
peer_addr => $self->{bgp}->{$instance}->{peer_addr}, |
| 114 |
peer_as => $self->{bgp}->{$instance}->{peer_as}, |
| 115 |
peer_type => $self->{bgp}->{$instance}->{peer_type}, |
| 116 |
status => $self->{bgp}->{$instance}->{status}, |
| 117 |
description => $self->{bgp}->{$instance}->{description}, |
| 118 |
); |
| 119 |
} |
| 120 |
} |
| 121 |
|
| 122 |
1; |
| 123 |
|
| 124 |
__END__ |
| 125 |
|
| 126 |
=head1 MODE |
| 127 |
|
| 128 |
List BGP. |
| 129 |
|
| 130 |
=over 8 |
| 131 |
|
| 132 |
=back |
| 133 |
|
| 134 |
=cut |
| 135 |
|