Debian Codegraph @

src/centreon/common/cisco/standard/snmp/mode/vpc.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 centreon::common::cisco::standard::snmp::mode::vpc;
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_ng);
29
30 sub custom_keepalive_status_output {
31 my ($self, %options) = @_;
32
33 return sprintf(
34 'status: %s',
35 $self->{result_values}->{keepalive_status}
36 );
37 }
38
39 sub custom_peer_status_output {
40 my ($self, %options) = @_;
41
42 return sprintf(
43 'role: %s',
44 $self->{result_values}->{role}
45 );
46 }
47
48 sub custom_peer_status_calc {
49 my ($self, %options) = @_;
50
51 $self->{result_values}->{role_last} = $options{old_datas}->{$self->{instance} . '_role'};
52 $self->{result_values}->{role} = $options{new_datas}->{$self->{instance} . '_role'};
53 if (!defined($options{old_datas}->{$self->{instance} . '_role'})) {
54 $self->{error_msg} = "buffer creation";
55 return -2;
56 }
57
58 return 0;
59 }
60
61 sub custom_link_status_output {
62 my ($self, %options) = @_;
63
64 return sprintf(
65 'operational status: %s',
66 $self->{result_values}->{link_status}
67 );
68 }
69
70 sub domain_long_output {
71 my ($self, %options) = @_;
72
73 return "checking vPC domain '" . $options{instance_value}->{domain_id} . "'";
74 }
75
76 sub prefix_domain_output {
77 my ($self, %options) = @_;
78
79 return "vPC domain '" . $options{instance_value}->{domain_id} . "' ";
80 }
81
82 sub prefix_host_output {
83 my ($self, %options) = @_;
84
85 return "host link '" . $options{instance_value}->{display} . "' ";
86 }
87
88 sub prefix_peer_output {
89 my ($self, %options) = @_;
90
91 return "peer '" . $options{instance_value}->{macaddress} . "' ";
92 }
93
94 sub prefix_keepalive_output {
95 my ($self, %options) = @_;
96
97 return 'keepalive ';
98 }
99
100 sub set_counters {
101 my ($self, %options) = @_;
102
103 $self->{maps_counters_type} = [
104 { name => 'domains', type => 3, cb_prefix_output => 'prefix_domain_output', cb_long_output => 'domain_long_output', indent_long_output => ' ', message_multiple => 'All vPC domains are ok',
105 group => [
106 { name => 'peer', type => 0, cb_prefix_output => 'prefix_peer_output', skipped_code => { -10 => 1 } },
107 { name => 'keepalive', type => 0, cb_prefix_output => 'prefix_keepalive_output', skipped_code => { -10 => 1 } },
108 { name => 'hosts', display_long => 1, cb_prefix_output => 'prefix_host_output', message_multiple => 'All host links are ok', type => 1, skipped_code => { -10 => 1 } },
109 ]
110 }
111 ];
112
113 $self->{maps_counters}->{peer} = [
114 {
115 label => 'peer-status',
116 type => 2,
117 critical_default => '%{role} ne %{role_last}',
118 set => {
119 key_values => [ { name => 'role' }, { name => 'domain_id' } ],
120 closure_custom_calc => $self->can('custom_peer_status_calc'),
121 closure_custom_output => $self->can('custom_peer_status_output'),
122 closure_custom_perfdata => sub { return 0; },
123 closure_custom_threshold_check => \&catalog_status_threshold_ng
124 }
125 },
126 { label => 'host-links-up', nlabel => 'vpc.host.links.up.count', display_ok => 0, set => {
127 key_values => [ { name => 'links_up' }, { name => 'links_total' } ],
128 output_template => 'host links up: %s',
129 perfdatas => [
130 { template => '%s', min => 0, max => 'links_total', label_extra_instance => 1 }
131 ]
132 }
133 },
134 { label => 'host-links-down', nlabel => 'vpc.host.links.down.count', display_ok => 0, set => {
135 key_values => [ { name => 'links_down' }, { name => 'links_total' } ],
136 output_template => 'host links down: %s',
137 perfdatas => [
138 { template => '%s', min => 0, max => 'links_total', label_extra_instance => 1 }
139 ]
140 }
141 },
142 { label => 'host-links-downstar', nlabel => 'vpc.host.links.downstar.count', display_ok => 0, set => {
143 key_values => [ { name => 'links_downstar' }, { name => 'links_total' } ],
144 output_template => 'host links downstar: %s',
145 perfdatas => [
146 { template => '%s', min => 0, max => 'links_total', label_extra_instance => 1 }
147 ]
148 }
149 }
150 ];
151
152 $self->{maps_counters}->{keepalive} = [
153 {
154 label => 'keepalive-status',
155 type => 2,
156 critical_default => '%{keepalive_status} ne "alive"',
157 set => {
158 key_values => [ { name => 'keepalive_status' }, { name => 'domain_id' } ],
159 closure_custom_calc => $self->can('custom_keepalive_status_calc'),
160 closure_custom_output => $self->can('custom_keepalive_status_output'),
161 closure_custom_perfdata => sub { return 0; },
162 closure_custom_threshold_check => \&catalog_status_threshold_ng
163 }
164 },
165 { label => 'keepalive-messages-sent', nlabel => 'vpc.keepalive.messages.sent.count', display_ok => 0, set => {
166 key_values => [ { name => 'keepalive_sent', diff => 1 } ],
167 output_template => 'messages sent: %s',
168 perfdatas => [
169 { template => '%s', min => 0, label_extra_instance => 1 }
170 ]
171 }
172 },
173 { label => 'keepalive-messages-received', nlabel => 'vpc.keepalive.messages.received.count', display_ok => 0, set => {
174 key_values => [ { name => 'keepalive_received', diff => 1 } ],
175 output_template => 'messages received: %s',
176 perfdatas => [
177 { template => '%s', min => 0, label_extra_instance => 1 }
178 ]
179 }
180 }
181 ];
182
183 $self->{maps_counters}->{hosts} = [
184 {
185 label => 'link-status',
186 type => 2,
187 warning_default => '%{link_status} =~ /downStar/i',
188 critical_default => '%{link_status} eq "down"',
189 set => {
190 key_values => [ { name => 'link_status' }, { name => 'display' } ],
191 closure_custom_output => $self->can('custom_link_status_output'),
192 closure_custom_perfdata => sub { return 0; },
193 closure_custom_threshold_check => \&catalog_status_threshold_ng
194 }
195 }
196 ];
197 }
198
199 sub new {
200 my ($class, %options) = @_;
201 my $self = $class->SUPER::new(package => __PACKAGE__, %options, statefile => 1, force_new_perfdata => 1);
202 bless $self, $class;
203
204 $options{options}->add_options(arguments => {
205 });
206
207 return $self;
208 }
209
210 my $mapping_role = {
211 1 => 'primarySecondary', 2 => 'primary',
212 3 => 'secondaryPrimary', 4 => 'secondary',
213 5 => 'noneEstablished'
214 };
215 my $mapping_keepalive_status = {
216 1 => 'disabled', 2 => 'alive',
217 3 => 'peerUnreachable', 4 => 'aliveButDomainIdDismatch',
218 5 => 'suspendedAsISSU', 6 => 'suspendedAsDestIPUnreachable',
219 7 => 'suspendedAsVRFUnusable', 8 => 'misconfigured'
220 };
221 my $mapping_link_status = {
222 1 => 'down', 2 => 'downStar', 3 => 'up'
223 };
224
225 my $mapping = {
226 role => { oid => '.1.3.6.1.4.1.9.9.807.1.2.1.1.2', map => $mapping_role }, # cVpcRoleStatus
227 macaddress => { oid => '.1.3.6.1.4.1.9.9.807.1.2.1.1.5' } # cVpcSystemOperMacAddress
228 };
229 my $mapping2 = {
230 keepalive_status => { oid => '.1.3.6.1.4.1.9.9.807.1.1.2.1.2', map => $mapping_keepalive_status }, # cVpcPeerKeepAliveStatus
231 keepalive_sent => { oid => '.1.3.6.1.4.1.9.9.807.1.3.1.1.2' }, # cVpcStatsPeerKeepAliveMsgsSent
232 keepalive_received => { oid => '.1.3.6.1.4.1.9.9.807.1.3.1.1.3' } # cVpcStatsPeerKeepAliveMsgsRcved
233 };
234 my $mapping3 = {
235 if_index => { oid => '.1.3.6.1.4.1.9.9.807.1.4.2.1.3' }, # cVpcStatusHostLinkIfIndex
236 link_status => { oid => '.1.3.6.1.4.1.9.9.807.1.4.2.1.4', map => $mapping_link_status } # cVpcStatusHostLinkStatus
237 };
238 my $oid_cVpcRoleEntry = '.1.3.6.1.4.1.9.9.807.1.2.1.1';
239 my $oid_cVpcStatsPeerKeepAliveEntry = '.1.3.6.1.4.1.9.9.807.1.3.1.1';
240 my $oid_cVpcStatusHostLinkEntry = '.1.3.6.1.4.1.9.9.807.1.4.2.1';
241 my $oid_ifName = '.1.3.6.1.2.1.31.1.1.1.1';
242
243 sub manage_selection {
244 my ($self, %options) = @_;
245
246 my $snmp_result = $options{snmp}->get_multiple_table(
247 oids => [
248 { oid => $oid_cVpcRoleEntry, start => $mapping->{role}->{oid}, end => $mapping->{macaddress}->{oid} },
249 { oid => $oid_cVpcStatusHostLinkEntry, start => $mapping3->{if_index}->{oid}, end => $mapping3->{link_status}->{oid} }
250 ],
251 nothing_quit => 1
252 );
253
254 $self->{domains} = {};
255 foreach my $oid (keys %{$snmp_result->{$oid_cVpcRoleEntry}}) {
256 next if ($oid !~ /^$mapping->{role}->{oid}\.(.*)$/);
257 my $result = $options{snmp}->map_instance(mapping => $mapping, results => $snmp_result->{$oid_cVpcRoleEntry}, instance => $1);
258 my $domain_id = $1;
259
260 $self->{domains}->{$domain_id} = {
261 domain_id => $domain_id,
262 peer => {
263 domain_id => $domain_id,
264 role => $result->{role},
265 macaddress => $result->{macaddress},
266 links_up => 0,
267 links_down => 0,
268 links_downstar => 0,
269 links_total => 0
270 },
271 keepalive => {},
272 hosts => {}
273 };
274 }
275
276 my $if_indexes = {};
277 foreach (keys %{$snmp_result->{$oid_cVpcStatusHostLinkEntry}}) {
278 next if (!/^$mapping3->{link_status}->{oid}\.(\d+)\.(\d+)/);
279 my ($domain_id, $vpc_id) = ($1, $2);
280 next if (!defined($self->{domains}->{$domain_id}));
281
282 my $result = $options{snmp}->map_instance(mapping => $mapping3, results => $snmp_result->{$oid_cVpcStatusHostLinkEntry}, instance => $domain_id . '.' . $vpc_id);
283
284 $if_indexes->{ $result->{if_index} } = 1;
285 $self->{domains}->{$domain_id}->{hosts}->{ $result->{if_index} } = {
286 display => $result->{if_index},
287 link_status => $result->{link_status}
288 };
289 $self->{domains}->{$domain_id}->{peer}->{links_total}++;
290 $self->{domains}->{$domain_id}->{peer}->{'links_' . lc($result->{link_status})}++;
291 }
292
293 # get interface name
294 $options{snmp}->load(
295 oids => [ $oid_ifName ],
296 instances => [keys %$if_indexes],
297 instance_regexp => '^(.*)$'
298 );
299 $snmp_result = $options{snmp}->get_leef();
300 foreach my $domain_id (keys %{$self->{domains}}) {
301 foreach my $if_index (keys %{$self->{domains}->{$domain_id}->{hosts}}) {
302 next if (
303 !defined($snmp_result->{ $oid_ifName . '.' . $if_index }) ||
304 $snmp_result->{ $oid_ifName . '.' . $if_index } eq ''
305 );
306 $self->{domains}->{$domain_id}->{hosts}->{$if_index}->{display} = $snmp_result->{ $oid_ifName . '.' . $if_index };
307 }
308 }
309
310 # Keepalive part
311 $snmp_result = $options{snmp}->get_multiple_table(
312 oids => [
313 { oid => $oid_cVpcStatsPeerKeepAliveEntry, start => $mapping2->{keepalive_sent}->{oid}, end => $mapping2->{keepalive_received}->{oid} },
314 { oid => $mapping2->{keepalive_status}->{oid} }
315 ],
316 return_type => 1
317 );
318 foreach (keys %$snmp_result) {
319 next if (!/^$mapping2->{keepalive_status}->{oid}\.(\d+)/);
320 my $domain_id = $1;
321 next if (!defined($self->{domains}->{$domain_id}));
322
323 my $result = $options{snmp}->map_instance(mapping => $mapping2, results => $snmp_result, instance => $domain_id);
324
325 $self->{domains}->{$domain_id}->{keepalive} = {
326 domain_id => $domain_id,
327 %$result
328 };
329 }
330
331 $self->{cache_name} = 'cisco_standard_' . $self->{mode} . '_' . $options{snmp}->get_hostname() . '_' . $options{snmp}->get_port() . '_' .
332 (defined($self->{option_results}->{filter_counters}) ? md5_hex($self->{option_results}->{filter_counters}) : md5_hex('all'));
333 }
334
335 1;
336
337 __END__
338
339 =head1 MODE
340
341 Check virtual port-channel (vPC).
342
343 =over 8
344
345 =item B<--unknown-peer-status>
346
347 Define the conditions to match for the status to be UNKNOWN.
348 You can use the following variables: %{role}, %{role_last}, %{domain_id}
349
350 =item B<--warning-peer-status>
351
352 Define the conditions to match for the status to be WARNING.
353 You can use the following variables: %{role}, %{role_last}, %{domain_id}
354
355 =item B<--critical-peer-status>
356
357 Define the conditions to match for the status to be CRITICAL (default: '%{role} ne %{role_last}').
358 You can use the following variables: %{role}, %{role_last}, %{domain_id}
359
360 =item B<--unknown-keepalive-status>
361
362 Define the conditions to match for the status to be UNKNOWN.
363 You can use the following variables: %{keepalive_status}, %{domain_id}
364
365 =item B<--warning-keepalive-status>
366
367 Define the conditions to match for the status to be WARNING.
368 You can use the following variables: %{keepalive_status}, %{domain_id}
369
370 =item B<--critical-keepalive-status>
371
372 Define the conditions to match for the status to be CRITICAL (default: '%{keepalive_status} ne "alive"').
373 You can use the following variables: %{keepalive_status}, %{domain_id}
374
375 =item B<--unknown-link-status>
376
377 Define the conditions to match for the status to be UNKNOWN.
378 You can use the following variables: %{link_status}, %{display}
379
380 =item B<--warning-link-status>
381
382 Define the conditions to match for the status to be WARNING (default: '%{link_status} =~ /downStar/i')
383 You can use the following variables: %{link_status}, %{display}
384
385 =item B<--critical-link-status>
386
387 Define the conditions to match for the status to be CRITICAL (default: '%{link_status} eq "down"').
388 You can use the following variables: %{link_status}, %{display}
389
390 =item B<--warning-*> B<--critical-*>
391
392 Thresholds.
393 Can be: 'host-links-up', 'host-links-down', 'host-links-downstar',
394 'keepalive-messages-sent', 'keepalive-messages-received'.
395
396 =back
397
398 =cut