Debian Codegraph @

src/centreon/common/huawei/standard/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 centreon::common::huawei::standard::snmp::mode::interfaces;
22
23 use base qw(snmp_standard::mode::interfaces);
24
25 use strict;
26 use warnings;
27
28 sub set_counters {
29 my ($self, %options) = @_;
30
31 $self->SUPER::set_counters(%options);
32
33 push @{$self->{maps_counters}->{int}},
34 { label => 'input-power', filter => 'add_optical', nlabel => 'interface.input.power.dbm', set => {
35 key_values => [ { name => 'input_power' }, { name => 'display' } ],
36 output_template => 'Input Power: %s dBm',
37 perfdatas => [
38 { template => '%s', unit => 'dBm', label_extra_instance => 1, instance_use => 'display' }
39 ]
40 }
41 },
42 { label => 'bias-current', filter => 'add_optical', nlabel => 'interface.bias.current.milliampere', set => {
43 key_values => [ { name => 'bias_current' }, { name => 'display' } ],
44 output_template => 'Bias Current: %s mA',
45 perfdatas => [
46 { template => '%s', unit => 'mA', label_extra_instance => 1, instance_use => 'display' }
47 ]
48 }
49 },
50 { label => 'output-power', filter => 'add_optical', nlabel => 'interface.output.power.dbm', set => {
51 key_values => [ { name => 'output_power' }, { name => 'display' } ],
52 output_template => 'Output Power: %s dBm',
53 perfdatas => [
54 { template => '%s', unit => 'dBm', label_extra_instance => 1, instance_use => 'display' }
55 ]
56 }
57 },
58 { label => 'module-temperature', filter => 'add_optical', nlabel => 'interface.module.temperature.celsius', set => {
59 key_values => [ { name => 'module_temperature' }, { name => 'display' } ],
60 output_template => 'Module Temperature: %.2f C',
61 perfdatas => [
62 { template => '%.2f', unit => 'C', label_extra_instance => 1, instance_use => 'display' }
63 ]
64 }
65 }
66 ;
67 }
68
69 sub new {
70 my ($class, %options) = @_;
71 my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1);
72 bless $self, $class;
73
74 $options{options}->add_options(arguments => {
75 'add-optical' => { name => 'add_optical' }
76 }
77 );
78
79 return $self;
80 }
81
82 sub skip_interface {
83 my ($self, %options) = @_;
84
85 return ($self->{checking} =~ /cast|errors|traffic|status|volume|optical/ ? 0 : 1);
86 }
87
88 sub check_options {
89 my ($self, %options) = @_;
90 $self->SUPER::check_options(%options);
91
92 $self->{checking} = '';
93 foreach (('add_global', 'add_status', 'add_errors', 'add_traffic', 'add_cast', 'add_speed', 'add_volume', 'add_optical')) {
94 if (defined($self->{option_results}->{$_})) {
95 $self->{checking} .= $_;
96 }
97 }
98 }
99
100 my $mapping_optical = {
101 module_temperature => { oid => '.1.3.6.1.4.1.2011.5.25.31.1.1.3.1.5' }, # hwEntityOpticalTemperature
102 bias_current => { oid => '.1.3.6.1.4.1.2011.5.25.31.1.1.3.1.7' }, # hwEntityOpticalBiasCurrent
103 input_power => { oid => '.1.3.6.1.4.1.2011.5.25.31.1.1.3.1.8' }, # hwEntityOpticalRxPower
104 output_power => { oid => '.1.3.6.1.4.1.2011.5.25.31.1.1.3.1.9' } # hwEntityOpticalTxPower
105 };
106
107 sub reload_cache_custom {
108 my ($self, %options) = @_;
109
110 $options{datas}->{physical_index} = {};
111 my $oid_entAliasMappingIdentifier = '.1.3.6.1.2.1.47.1.3.2.1.2';
112 my $oid_ifIndex = '.1.3.6.1.2.1.2.2.1.1';
113 my $snmp_result = $self->{snmp}->get_table(oid => $oid_entAliasMappingIdentifier);
114 foreach (keys %$snmp_result) {
115 next if ($snmp_result->{$_} !~ /^$oid_ifIndex\.(\d+)/);
116 my $ifindex = $1;
117 /^$oid_entAliasMappingIdentifier\.(\d+)\./;
118
119 $options{datas}->{physical_index}->{$ifindex} = $1;
120 }
121 }
122
123 sub custom_load {
124 my ($self, %options) = @_;
125
126 return if (!defined($self->{option_results}->{add_optical}));
127
128 my $pindexes = $self->{statefile_cache}->get(name => 'physical_index');
129 my $instances = [];
130 foreach (@{$self->{array_interface_selected}}) {
131 push @$instances, $pindexes->{$_} if (defined($pindexes->{$_}));
132 }
133
134 $self->{snmp}->load(
135 oids => [ map($_->{oid}, values(%$mapping_optical)) ],
136 instances => $instances
137 );
138 }
139
140 sub custom_add_result {
141 my ($self, %options) = @_;
142
143 return if (!defined($self->{option_results}->{add_optical}));
144
145 my $ports = $self->{statefile_cache}->get(name => 'physical_index');
146 return if (!defined($ports->{ $options{instance} }));
147
148 my $result = $self->{snmp}->map_instance(mapping => $mapping_optical, results => $self->{results}, instance => $ports->{ $options{instance} });
149
150 if (defined($result->{module_temperature}) && $result->{module_temperature} != -255) {
151 $self->{int}->{$options{instance}}->{module_temperature} = $result->{module_temperature};
152 }
153 if (defined($result->{bias_current}) && $result->{bias_current} != -1) {
154 $self->{int}->{$options{instance}}->{bias_current} = $result->{bias_current};
155 }
156 if (defined($result->{input_power}) && $result->{input_power} != -1) {
157 $self->{int}->{$options{instance}}->{input_power} = $result->{input_power} / 100;
158 }
159 if (defined($result->{output_power}) && $result->{output_power} != -1) {
160 $self->{int}->{$options{instance}}->{output_power} = $result->{output_power} / 100;
161 }
162 }
163
164 1;
165
166 __END__
167
168 =head1 MODE
169
170 Check interfaces.
171
172 =over 8
173
174 =item B<--add-global>
175
176 Check global port statistics (by default if no --add-* option is set).
177
178 =item B<--add-status>
179
180 Check interface status.
181
182 =item B<--add-duplex-status>
183
184 Check duplex status (with --warning-status and --critical-status).
185
186 =item B<--add-traffic>
187
188 Check interface traffic.
189
190 =item B<--add-errors>
191
192 Check interface errors.
193
194 =item B<--add-cast>
195
196 Check interface cast.
197
198 =item B<--add-speed>
199
200 Check interface speed.
201
202 =item B<--add-volume>
203
204 Check interface data volume between two checks (not supposed to be graphed, useful for BI reporting).
205
206 =item B<--add-optical>
207
208 Check interfaces' optical metrics.
209
210 =item B<--check-metrics>
211
212 If the expression is true, metrics are checked (default: '%{opstatus} eq "up"').
213
214 =item B<--warning-status>
215
216 Define the conditions to match for the status to be WARNING.
217 You can use the following variables: %{admstatus}, %{opstatus}, %{duplexstatus}, %{display}
218
219 =item B<--critical-status>
220
221 Define the conditions to match for the status to be CRITICAL (default: '%{admstatus} eq "up" and %{opstatus} ne "up"').
222 You can use the following variables: %{admstatus}, %{opstatus}, %{duplexstatus}, %{display}
223
224 =item B<--warning-errors>
225
226 Set warning threshold for all error counters.
227
228 =item B<--critical-errors>
229
230 Set critical threshold for all error counters.
231
232 =item B<--warning-total-port>
233
234 Thresholds.
235
236 =item B<--critical-total-port>
237
238 Thresholds.
239
240 =item B<--warning-total-admin-up>
241
242 Thresholds.
243
244 =item B<--critical-total-admin-up>
245
246 Thresholds.
247
248 =item B<--warning-total-admin-down>
249
250 Thresholds.
251
252 =item B<--critical-total-admin-down>
253
254 Thresholds.
255
256 =item B<--warning-total-oper-up>
257
258 Thresholds.
259
260 =item B<--critical-total-oper-up>
261
262 Thresholds.
263
264 =item B<--warning-total-oper-down>
265
266 Thresholds.
267
268 =item B<--critical-total-oper-down>
269
270 Thresholds.
271
272 =item B<--warning-in-traffic>
273
274 Thresholds.
275
276 =item B<--critical-in-traffic>
277
278 Thresholds.
279
280 =item B<--warning-out-traffic>
281
282 Thresholds.
283
284 =item B<--critical-out-traffic>
285
286 Thresholds.
287
288 =item B<--warning-in-error>
289
290 Thresholds.
291
292 =item B<--critical-in-error>
293
294 Thresholds.
295
296 =item B<--warning-in-discard>
297
298 Thresholds.
299
300 =item B<--critical-in-discard>
301
302 Thresholds.
303
304 =item B<--warning-out-error>
305
306 Thresholds.
307
308 =item B<--critical-out-error>
309
310 Thresholds.
311
312 =item B<--warning-out-discard>
313
314 Thresholds.
315
316 =item B<--critical-out-discard>
317
318 Thresholds.
319
320 =item B<--warning-in-ucast>
321
322 Thresholds.
323
324 =item B<--critical-in-ucast>
325
326 Thresholds.
327
328 =item B<--warning-in-bcast>
329
330 Thresholds.
331
332 =item B<--critical-in-bcast>
333
334 Thresholds.
335
336 =item B<--warning-in-mcast>
337
338 Thresholds.
339
340 =item B<--critical-in-mcast>
341
342 Thresholds.
343
344 =item B<--warning-out-ucast>
345
346 Thresholds.
347
348 =item B<--critical-out-ucast>
349
350 Thresholds.
351
352 =item B<--warning-out-bcast>
353
354 Thresholds.
355
356 =item B<--critical-out-bcast>
357
358 Thresholds.
359
360 =item B<--warning-out-mcast>
361
362 Thresholds.
363
364 =item B<--critical-out-mcast>
365
366 Thresholds.
367
368 =item B<--warning-speed>
369
370 Thresholds in b/s.
371
372 =item B<--critical-speed>
373
374 Thresholds in b/s.
375
376 =item B<--warning-input-power>
377
378 Thresholds in C<dBm>.
379
380 =item B<--critical-input-power>
381
382 Thresholds in C<dBm>.
383
384 =item B<--warning-bias-current>
385
386 Thresholds in C<mA>.
387
388 =item B<--critical-bias-current>
389
390 Thresholds in C<mA>.
391
392 =item B<--warning-output-power>
393
394 Thresholds in C<dBm>.
395
396 =item B<--critical-output-power>
397
398 Thresholds in C<dBm>.
399
400 =item B<--warning-module-temperature>
401
402 Thresholds in °C.
403
404 =item B<--critical-module-temperature>
405
406 Thresholds in °C.
407
408
409 =item B<--units-traffic>
410
411 Units of thresholds for the traffic (default: 'percent_delta') ('percent_delta', 'bps', 'counter').
412
413 =item B<--units-errors>
414
415 Units of thresholds for errors/discards (default: 'percent_delta') ('percent_delta', 'percent', 'delta', 'deltaps', 'counter').
416
417 =item B<--units-cast>
418
419 Units of thresholds for communication types (default: 'percent_delta') ('percent_delta', 'percent', 'delta', 'deltaps', 'counter').
420
421 =item B<--nagvis-perfdata>
422
423 Display traffic perfdata to be compatible with NagVis widget.
424
425 =item B<--interface>
426
427 Check only the interfaces with the specified IDs (OID indexes, e.g.: 1,2,...). If empty, all interfaces will be monitored.
428 To filter on interface names, see --name.
429
430 =item B<--name>
431
432 With this option, the interfaces will be filtered by name (given in option --interface) instead of OID index. The name matching mode supports regular expressions.
433
434 =item B<--regex-id>
435
436 With this option, interface IDs will be filtered using the --interface parameter as a regular expression instead of a list of IDs.
437
438 =item B<--speed>
439
440 Set interface speed for incoming/outgoing traffic (in Mb).
441
442 =item B<--speed-in>
443
444 Set interface speed for incoming traffic (in Mb).
445
446 =item B<--speed-out>
447
448 Set interface speed for outgoing traffic (in Mb).
449
450 =item B<--force-counters32>
451
452 Force to use 32-bit counters (even with SNMP versions 2c and 3). To use when 64 bits counters are buggy.
453
454 =item B<--reload-cache-time>
455
456 Time in minutes before reloading cache file (default: 180).
457
458 =item B<--oid-filter>
459
460 Define the OID to be used to filter interfaces (default: ifName) (values: ifDesc, ifAlias, ifName, IpAddr).
461
462 =item B<--oid-display>
463
464 Define the OID that will be used to name the interfaces (default: ifName) (values: ifDesc, ifAlias, ifName, IpAddr).
465
466 =item B<--oid-extra-display>
467
468 Add an OID to display.
469
470 =item B<--display-transform-src> B<--display-transform-dst>
471
472 Modify the interface name displayed by using a regular expression.
473
474 Example: adding --display-transform-src='eth' --display-transform-dst='ens' will replace all occurrences of 'eth' with 'ens'
475
476 =item B<--show-cache>
477
478 Display cache interface data.
479
480 =back
481
482 =cut