Debian Codegraph @

src/network/brocade/snmp/mode/interfaces.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::brocade::snmp::mode::interfaces;
22
23 use base qw(snmp_standard::mode::interfaces);
24
25 use strict;
26 use warnings;
27
28 sub set_oids_errors {
29 my ($self, %options) = @_;
30
31 $self->SUPER::set_oids_errors(%options);
32 $self->{oid_in_crc} = '.1.3.6.1.4.1.1588.2.1.1.1.6.2.1.22'; # swFCPortRxCrcs
33 }
34
35 sub set_oids_label {
36 my ($self, %options) = @_;
37
38 $self->SUPER::set_oids_label(%options);
39 $self->{oids_label}->{fcportname} = { oid => '.1.3.6.1.4.1.1588.2.1.1.1.6.2.1.36', get => 'reload_get_fcportname', cache => 'reload_cache_fcportname' };
40 }
41
42 sub set_counters_errors {
43 my ($self, %options) = @_;
44
45 $self->SUPER::set_counters_errors(%options);
46
47 push @{$self->{maps_counters}->{int}},
48 { label => 'in-crc', filter => 'add_errors', nlabel => 'interface.packets.in.crc.count', set => {
49 key_values => [ { name => 'incrc', diff => 1 }, { name => 'total_in_packets', diff => 1 }, { name => 'display' }, { name => 'mode_cast' } ],
50 closure_custom_calc => $self->can('custom_errors_calc'), closure_custom_calc_extra_options => { label_ref1 => 'in', label_ref2 => 'crc' },
51 closure_custom_output => $self->can('custom_errors_output'), output_error_template => 'Packets In Crc : %s',
52 closure_custom_perfdata => $self->can('custom_errors_perfdata'),
53 closure_custom_threshold_check => $self->can('custom_errors_threshold')
54 }
55 }
56 ;
57
58 push @{$self->{maps_counters}->{int}},
59 { label => 'laser-temp', filter => 'add_optical', nlabel => 'interface.laser.temperature.celsius', set => {
60 key_values => [ { name => 'laser_temp' }, { name => 'display' } ],
61 output_template => 'Laser Temperature : %.2f C', output_error_template => 'Laser Temperature : %.2f',
62 perfdatas => [
63 { label => 'laser_temp', template => '%.2f',
64 unit => 'C', label_extra_instance => 1, instance_use => 'display' }
65 ]
66 }
67 },
68 { label => 'input-power', filter => 'add_optical', nlabel => 'interface.input.power.dbm', set => {
69 key_values => [ { name => 'input_power' }, { name => 'display' } ],
70 output_template => 'Input Power : %s dBm', output_error_template => 'Input Power : %s',
71 perfdatas => [
72 { label => 'input_power', template => '%s',
73 unit => 'dBm', label_extra_instance => 1, instance_use => 'display' }
74 ]
75 }
76 },
77 { label => 'output-power', filter => 'add_optical', nlabel => 'interface.output.power.dbm', set => {
78 key_values => [ { name => 'output_power' }, { name => 'display' } ],
79 output_template => 'Output Power : %s dBm', output_error_template => 'Output Power : %s',
80 perfdatas => [
81 { label => 'output_power', template => '%s',
82 unit => 'dBm', label_extra_instance => 1, instance_use => 'display' }
83 ]
84 }
85 }
86 ;
87 }
88
89 sub new {
90 my ($class, %options) = @_;
91 my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perdata => 1);
92 bless $self, $class;
93
94 $options{options}->add_options(arguments => {
95 'add-optical' => { name => 'add_optical' }
96 });
97
98 return $self;
99 }
100
101 sub reload_cache_custom {
102 my ($self, %options) = @_;
103
104 $options{datas}->{conn_unit_ports} = {};
105 my $oid_connUnitPortPhysicalNumber = '.1.3.6.1.3.94.1.10.1.18';
106 my $snmp_result = $self->{snmp}->get_table(oid => $oid_connUnitPortPhysicalNumber);
107 foreach (keys %$snmp_result) {
108 next if (! /^$oid_connUnitPortPhysicalNumber\.(.*)\.(\d+)$/);
109 $options{datas}->{conn_unit_ports}->{$2} = $1;
110 }
111 }
112
113 sub reload_get_fcportname {
114 my ($self, %options) = @_;
115
116 $options{snmp_get}->{fcportname} = { oid => $self->{oids_label}->{fcportname}->{oid} };
117 $options{snmp_get}->{ifname} = { oid => $self->{oids_label}->{ifname}->{oid} };
118 }
119
120 sub reload_cache_fcportname {
121 my ($self, %options) = @_;
122
123 # I cheat. Yes i can ;) change swFCPortIndex to ifIndex
124 my $store_index = defined($options{store_index}) && $options{store_index} == 1 ? 1 : 0;
125 foreach (keys %{$options{result}->{ $self->{oids_label}->{ifname}->{oid} }}) {
126 /^$self->{oids_label}->{ifname}->{oid}\.(.*)$/;
127 my $if_index = $1;
128 push @{$options{datas}->{all_ids}}, $if_index if ($store_index == 1);
129 if ($options{result}->{ $self->{oids_label}->{ifname}->{oid} }->{$_} =~ /\d+\/(\d+)$/) {
130 $options{datas}->{ $options{name} . '_' . $if_index } = $self->{output}->decode(
131 $options{result}->{ $self->{oids_label}->{ $options{name} }->{oid} }->{ $self->{oids_label}->{ $options{name} }->{oid} . '.' . ($1 + 1) }
132 );
133 } else {
134 # we use ifname if there is no fcportname
135 $options{datas}->{ $options{name} . '_' . $if_index } = $self->{output}->decode(
136 $options{result}->{ $self->{oids_label}->{ifname}->{oid} }->{$_}
137 );
138 }
139 }
140 }
141
142 sub map_brocade {
143 my ($self, %options) = @_;
144
145 return if (defined($self->{map_brocade}));
146
147 $self->{map_brocade} = {
148 port2if => {},
149 if2port => {}
150 };
151 # swFCPortIndex can be found with ifName ("0/2") or ifDesc ("FC port 0/2")
152 foreach (@{$self->{array_interface_selected}}) {
153 my $value = $self->{statefile_cache}->get(name => 'ifname_' . $_);
154 $value = $self->{statefile_cache}->get(name => 'ifdesc_' . $_) if (!defined($value));
155 if (defined($value) && $value =~ /\d+\/(\d+)$/) {
156 my $port_index = $1 + 1;
157 $self->{map_brocade}->{port2if}->{$port_index} = $_;
158 $self->{map_brocade}->{if2port}->{$_} = $port_index;
159 }
160 }
161 }
162
163 sub load_errors {
164 my ($self, %options) = @_;
165
166 $self->set_oids_errors();
167 $self->{snmp}->load(
168 oids => [
169 $self->{oid_ifInDiscards}, $self->{oid_ifInErrors},
170 $self->{oid_ifOutDiscards}, $self->{oid_ifOutErrors}
171 ],
172 instances => $self->{array_interface_selected}
173 );
174
175 $self->map_brocade();
176 my $indexes = [keys %{$self->{map_brocade}->{port2if}}];
177 $self->{snmp}->load(
178 oids => [ $self->{oid_in_crc} ],
179 instances => $indexes
180 ) if (scalar(@$indexes) > 0);
181 }
182
183 my $oid_optical_laser_temp = '.1.3.6.1.4.1.1588.2.1.1.1.28.1.1.1'; # swSfpTemperature
184 my $oid_optical_input_power = '.1.3.6.1.4.1.1588.2.1.1.1.28.1.1.4'; # swSfpRxPower
185 my $oid_optical_output_power = '.1.3.6.1.4.1.1588.2.1.1.1.28.1.1.5'; # swSfpTxPower
186
187 sub custom_load {
188 my ($self, %options) = @_;
189
190 return if (!defined($self->{option_results}->{add_optical}));
191
192 $self->map_brocade();
193 my $ports = $self->{statefile_cache}->get(name => 'conn_unit_ports');
194 my $instances = [];
195 foreach (keys %{$self->{map_brocade}->{port2if}}) {
196 push @$instances, $ports->{$_} . '.' . $_;
197 }
198
199 return if (scalar(@$instances) <= 0);
200
201 $self->{snmp}->load(
202 oids => [ $oid_optical_laser_temp, $oid_optical_input_power, $oid_optical_output_power ],
203 instances => $instances,
204 instance_regexp => '^(.*)$'
205 );
206 }
207
208 sub add_result_errors {
209 my ($self, %options) = @_;
210
211 $self->{int}->{$options{instance}}->{indiscard} = $self->{results}->{$self->{oid_ifInDiscards} . '.' . $options{instance}};
212 $self->{int}->{$options{instance}}->{inerror} = $self->{results}->{$self->{oid_ifInErrors} . '.' . $options{instance}};
213 $self->{int}->{$options{instance}}->{outdiscard} = $self->{results}->{$self->{oid_ifOutDiscards} . '.' . $options{instance}};
214 $self->{int}->{$options{instance}}->{outerror} = $self->{results}->{$self->{oid_ifOutErrors} . '.' . $options{instance}};
215 $self->{int}->{$options{instance}}->{incrc} = defined($self->{map_brocade}->{if2port}->{ $options{instance} }) ?
216 $self->{results}->{$self->{oid_in_crc} . '.' . $self->{map_brocade}->{if2port}->{ $options{instance} }} :
217 undef;
218 }
219
220 sub custom_add_result {
221 my ($self, %options) = @_;
222
223 return if (!defined($self->{option_results}->{add_optical}));
224
225 my $ports = $self->{statefile_cache}->get(name => 'conn_unit_ports');
226 my $port_index = defined($self->{map_brocade}->{if2port}->{ $options{instance} }) ?
227 $self->{map_brocade}->{if2port}->{ $options{instance} } : undef;
228
229 return if (!defined($ports) || !defined($port_index) || !defined($ports->{$port_index}));
230
231 my $index = $ports->{$port_index} . '.' . $port_index;
232 if (defined($self->{results}->{$oid_optical_laser_temp . '.' . $index}) &&
233 $self->{results}->{$oid_optical_laser_temp . '.' . $index} =~ /(\d+)/) {
234 $self->{int}->{ $options{instance} }->{laser_temp} = $1;
235 }
236
237 if (defined($self->{results}->{$oid_optical_input_power . '.' . $index}) &&
238 $self->{results}->{$oid_optical_input_power . '.' . $index} =~ /(-?\d+(?:\.?\d+)?)/) {
239 $self->{int}->{ $options{instance} }->{input_power} = $1;
240 }
241
242 if (defined($self->{results}->{$oid_optical_output_power . '.' . $index}) &&
243 $self->{results}->{$oid_optical_output_power . '.' . $index} =~ /(-?\d+(?:\.?\d+)?)/) {
244 $self->{int}->{ $options{instance} }->{output_power} = $1;
245 }
246 }
247
248 1;
249
250 __END__
251
252 =head1 MODE
253
254 Check interfaces.
255
256 =over 8
257
258 =item B<--add-global>
259
260 Check global port statistics (by default if no --add-* option is set).
261
262 =item B<--add-status>
263
264 Check interface status.
265
266 =item B<--add-duplex-status>
267
268 Check duplex status (with --warning-status and --critical-status).
269
270 =item B<--add-traffic>
271
272 Check interface traffic.
273
274 =item B<--add-errors>
275
276 Check interface errors.
277
278 =item B<--add-cast>
279
280 Check interface cast.
281
282 =item B<--add-speed>
283
284 Check interface speed.
285
286 =item B<--add-volume>
287
288 Check interface data volume between two checks (not supposed to be graphed, useful for BI reporting).
289
290 =item B<--add-optical>
291
292 Check interface optical.
293
294 =item B<--check-metrics>
295
296 If the expression is true, metrics are checked (default: '%{opstatus} eq "up"').
297
298 =item B<--warning-status>
299
300 Define the conditions to match for the status to be WARNING.
301 You can use the following variables: %{admstatus}, %{opstatus}, %{duplexstatus}, %{display}
302
303 =item B<--critical-status>
304
305 Define the conditions to match for the status to be CRITICAL (default: '%{admstatus} eq "up" and %{opstatus} ne "up"').
306 You can use the following variables: %{admstatus}, %{opstatus}, %{duplexstatus}, %{display}
307
308 =item B<--warning-*> B<--critical-*>
309
310 Thresholds.
311 Can be: 'total-port', 'total-admin-up', 'total-admin-down', 'total-oper-up', 'total-oper-down',
312 'in-traffic', 'out-traffic', 'in-crc', 'in-error', 'in-discard', 'out-error', 'out-discard',
313 'in-ucast', 'in-bcast', 'in-mcast', 'out-ucast', 'out-bcast', 'out-mcast',
314 'speed' (b/s), 'laser-temp', 'input-power', 'output-power'.
315
316 =item B<--units-traffic>
317
318 Units of thresholds for the traffic (default: 'percent_delta') ('percent_delta', 'bps', 'counter').
319
320 =item B<--units-errors>
321
322 Units of thresholds for errors/discards (default: 'percent_delta') ('percent_delta', 'percent', 'delta', 'deltaps', 'counter').
323
324 =item B<--units-cast>
325
326 Units of thresholds for communication types (default: 'percent_delta') ('percent_delta', 'percent', 'delta', 'deltaps', 'counter').
327
328 =item B<--nagvis-perfdata>
329
330 Display traffic perfdata to be compatible with nagvis widget.
331
332 =item B<--interface>
333
334 Set the interface (number expected) example: 1,2,... (empty means 'check all interfaces').
335
336 =item B<--name>
337
338 Allows you to define the interface (in option --interface) by name instead of OID index. The name matching mode supports regular expressions.
339
340 =item B<--speed>
341
342 Set interface speed for incoming/outgoing traffic (in Mb).
343
344 =item B<--speed-in>
345
346 Set interface speed for incoming traffic (in Mb).
347
348 =item B<--speed-out>
349
350 Set interface speed for outgoing traffic (in Mb).
351
352 =item B<--force-counters32>
353
354 Force to use 32 bits counters (even in snmp v2c and v3). Should be used when 64 bits counters are buggy.
355
356 =item B<--reload-cache-time>
357
358 Time in minutes before reloading cache file (default: 180).
359
360 =item B<--oid-filter>
361
362 Define the OID to be used to filter interfaces (default: ifName) (values: fcPortName, ifDesc, ifAlias, ifName, IpAddr).
363
364 =item B<--oid-display>
365
366 Define the OID that will be used to name the interfaces (default: ifName) (values: fcPortName, ifDesc, ifAlias, ifName, IpAddr).
367
368 =item B<--oid-extra-display>
369
370 Add an OID to display.
371
372 =item B<--display-transform-src> B<--display-transform-dst>
373
374 Modify the interface name displayed by using a regular expression.
375
376 Example: adding --display-transform-src='eth' --display-transform-dst='ens' will replace all occurrences of 'eth' with 'ens'
377
378 =item B<--show-cache>
379
380 Display cache interface data.
381
382 =back
383
384 =cut