Debian Codegraph @

src/network/nokia/timos/snmp/mode/bgpusage.pm

raw
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::bgpusage;
22
23 use base qw(centreon::plugins::templates::counter);
24
25 use strict;
26 use warnings;
27 use Digest::MD5 qw(md5_hex);
28 use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold);
29
30 sub custom_status_output {
31 my ($self, %options) = @_;
32
33 my $msg = 'state : ' . $self->{result_values}->{state};
34 return $msg;
35 }
36
37 sub custom_status_calc {
38 my ($self, %options) = @_;
39
40 $self->{result_values}->{state} = $options{new_datas}->{$self->{instance} . '_state'};
41 $self->{result_values}->{display} = $options{new_datas}->{$self->{instance} . '_display'};
42 return 0;
43 }
44
45 sub set_counters {
46 my ($self, %options) = @_;
47
48 $self->{maps_counters_type} = [
49 { name => 'bgp', type => 1, cb_prefix_output => 'prefix_bgp_output', message_multiple => 'All BGP are ok' },
50 ];
51 $self->{maps_counters}->{bgp} = [
52 { label => 'status', threshold => 0, set => {
53 key_values => [ { name => 'state' }, { name => 'display' } ],
54 closure_custom_calc => $self->can('custom_status_calc'),
55 closure_custom_output => $self->can('custom_status_output'),
56 closure_custom_perfdata => sub { return 0; },
57 closure_custom_threshold_check => \&catalog_status_threshold,
58 }
59 },
60 { label => 'active-prefixes', set => {
61 key_values => [ { name => 'active_prefixes' }, { name => 'display' } ],
62 output_template => 'Active Prefixes : %s',
63 perfdatas => [
64 { label => 'active_prefixes', value => 'active_prefixes', template => '%s',
65 min => 0, label_extra_instance => 1, instance_use => 'display' },
66 ],
67 }
68 },
69 { label => 'sent-prefixes', set => {
70 key_values => [ { name => 'sent_prefixes', diff => 1 }, { name => 'display' } ],
71 output_template => 'Sent Prefixes : %s',
72 perfdatas => [
73 { label => 'sent_prefixes', value => 'sent_prefixes', template => '%s',
74 min => 0, label_extra_instance => 1, instance_use => 'display' },
75 ],
76 }
77 },
78 { label => 'received-prefixes', set => {
79 key_values => [ { name => 'received_prefixes', diff => 1 }, { name => 'display' } ],
80 output_template => 'Received Prefixes : %s',
81 perfdatas => [
82 { label => 'received_prefixes', value => 'received_prefixes', template => '%s',
83 min => 0, label_extra_instance => 1, instance_use => 'display' },
84 ],
85 }
86 },
87 ];
88 }
89
90 sub prefix_bgp_output {
91 my ($self, %options) = @_;
92
93 return "BGP '" . $options{instance_value}->{display} . "' ";
94 }
95
96 sub new {
97 my ($class, %options) = @_;
98 my $self = $class->SUPER::new(package => __PACKAGE__, %options, statefile => 1);
99 bless $self, $class;
100
101 $options{options}->add_options(arguments =>
102 {
103 "filter-name:s" => { name => 'filter_name' },
104 "warning-status:s" => { name => 'warning_status', default => '' },
105 "critical-status:s" => { name => 'critical_status', default => '%{state} =~ /outOfService/' },
106 });
107
108 return $self;
109 }
110
111 sub check_options {
112 my ($self, %options) = @_;
113 $self->SUPER::check_options(%options);
114
115 $self->change_macros(macros => ['warning_status', 'critical_status']);
116 }
117
118 my %map_status = (1 => 'unknown', 2 => 'inService', 3 => 'outOfService',
119 4 => 'transition', 5 => 'disabled',
120 );
121
122 my $oid_vRtrName = '.1.3.6.1.4.1.6527.3.1.2.3.1.1.4';
123 my $mapping = {
124 tBgpPeerNgDescription => { oid => '.1.3.6.1.4.1.6527.3.1.2.14.4.7.1.7' },
125 tBgpPeerNgOperStatus => { oid => '.1.3.6.1.4.1.6527.3.1.2.14.4.7.1.42', map => \%map_status },
126 tBgpPeerNgPeerAS4Byte => { oid => '.1.3.6.1.4.1.6527.3.1.2.14.4.7.1.66' },
127 tBgpPeerNgOperReceivedPrefixes => { oid => '.1.3.6.1.4.1.6527.3.1.2.14.4.8.1.5' },
128 tBgpPeerNgOperSentPrefixes => { oid => '.1.3.6.1.4.1.6527.3.1.2.14.4.8.1.6' },
129 tBgpPeerNgOperActivePrefixes => { oid => '.1.3.6.1.4.1.6527.3.1.2.14.4.8.1.7' },
130 };
131
132 sub manage_selection {
133 my ($self, %options) = @_;
134
135 my $snmp_result = $options{snmp}->get_multiple_table(oids => [
136 { oid => $oid_vRtrName },
137 { oid => $mapping->{tBgpPeerNgDescription}->{oid} },
138 { oid => $mapping->{tBgpPeerNgPeerAS4Byte}->{oid} },
139 ], return_type => 1, nothing_quit => 1);
140 $self->{bgp} = {};
141 foreach my $oid (keys %$snmp_result) {
142 next if ($oid !~ /^$mapping->{tBgpPeerNgPeerAS4Byte}->{oid}\.(\d+)\.(\d+)\.(.*)$/);
143 my ($vrtr_id, $peer_type, $peer_addr) = ($1, $2, $3);
144
145 my $vrtr_name = $snmp_result->{$oid_vRtrName . '.' . $vrtr_id};
146 my $result = $options{snmp}->map_instance(mapping => $mapping, results => $snmp_result, instance => $vrtr_id . '.' . $peer_type . '.' . $peer_addr);
147
148 my $name = $vrtr_name . ':' . $peer_addr . ':' . $result->{tBgpPeerNgPeerAS4Byte} . ':' . $result->{tBgpPeerNgDescription};
149 if (defined($self->{option_results}->{filter_name}) && $self->{option_results}->{filter_name} ne '' &&
150 $name !~ /$self->{option_results}->{filter_name}/) {
151 $self->{output}->output_add(long_msg => "skipping '" . $name . "'.", debug => 1);
152 next;
153 }
154
155 $self->{bgp}->{$vrtr_id . '.' . $peer_type . '.' . $peer_addr} = {
156 display => $name
157 };
158 }
159
160 $options{snmp}->load(oids => [$mapping->{tBgpPeerNgOperReceivedPrefixes}->{oid}, $mapping->{tBgpPeerNgOperSentPrefixes}->{oid},
161 $mapping->{tBgpPeerNgOperActivePrefixes}->{oid}, $mapping->{tBgpPeerNgOperStatus}->{oid}],
162 instances => [keys %{$self->{bgp}}], instance_regexp => '^(.*)$');
163 $snmp_result = $options{snmp}->get_leef(nothing_quit => 1);
164 foreach (keys %{$self->{bgp}}) {
165 my $result = $options{snmp}->map_instance(mapping => $mapping, results => $snmp_result, instance => $_);
166
167 $self->{bgp}->{$_}->{sent_prefixes} = $result->{tBgpPeerNgOperSentPrefixes};
168 $self->{bgp}->{$_}->{active_prefixes} = $result->{tBgpPeerNgOperActivePrefixes};
169 $self->{bgp}->{$_}->{received_prefixes} = $result->{tBgpPeerNgOperReceivedPrefixes};
170 $self->{bgp}->{$_}->{state} = $result->{tBgpPeerNgOperStatus};
171 }
172
173 if (scalar(keys %{$self->{bgp}}) <= 0) {
174 $self->{output}->add_option_msg(short_msg => "No bgp found.");
175 $self->{output}->option_exit();
176 }
177
178 $self->{cache_name} = "nokia_timos_" . $options{snmp}->get_hostname() . '_' . $options{snmp}->get_port() . '_' . $self->{mode} . '_' .
179 (defined($self->{option_results}->{filter_name}) ? md5_hex($self->{option_results}->{filter_name}) : md5_hex('all')) . '_' .
180 (defined($self->{option_results}->{filter_counters}) ? md5_hex($self->{option_results}->{filter_counters}) : md5_hex('all'));
181 }
182
183 1;
184
185 __END__
186
187 =head1 MODE
188
189 Check BGP usage.
190
191 =over 8
192
193 =item B<--warning-*>
194
195 Warning threshold.
196 Can be: 'active-prefixes', 'sent-prefixes', 'received-prefixes'.
197
198 =item B<--critical-*>
199
200 Critical threshold.
201 Can be: 'active-prefixes', 'sent-prefixes', 'received-prefixes'.
202
203 =item B<--warning-status>
204
205 Define the conditions to match for the status to be WARNING.
206 You can use the following variables: %{display}, %{state}
207
208 =item B<--critical-status>
209
210 Define the conditions to match for the status to be CRITICAL (default: '%{state} =~ /outOfService/')
211 You can use the following variables: %{display}, %{state}
212
213 =item B<--filter-name>
214
215 Filter by BGP name (can be a regexp).
216 Syntax: VrtrName:peeraddr:peerAS:description
217
218 =back
219
220 =cut