Debian Codegraph @

src/network/adva/fsp3000/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::adva::fsp3000::snmp::mode::interfaces;
22
23 use base qw(snmp_standard::mode::interfaces);
24
25 use strict;
26 use warnings;
27
28 sub set_oids_traffic {
29 my ($self, %options) = @_;
30
31 $self->{currentEthRx15minBytes} = '.1.3.6.1.4.1.2544.1.11.2.6.2.52.1.5'; # in B
32 $self->{currentEthRx1dayBytes} = '.1.3.6.1.4.1.2544.1.11.2.6.2.53.1.5'; # in B
33 $self->{currentEthTx15minBytes} = '.1.3.6.1.4.1.2544.1.11.2.6.2.56.1.3'; # in B
34 $self->{currentEthTx1dayBytes} = '.1.3.6.1.4.1.2544.1.11.2.6.2.57.1.3'; # in B
35 $self->{currentEthRxHighSpeed15minBytes} = '.1.3.6.1.4.1.2544.1.11.2.6.2.88.1.4'; # in B
36 $self->{currentEthRxHighSpeed1dayBytes} = '.1.3.6.1.4.1.2544.1.11.2.6.2.89.1.4'; # in B
37 }
38
39 sub set_counters_traffic {
40 my ($self, %options) = @_;
41
42 push @{$self->{maps_counters}->{int}},
43 { label => 'traffic-in', filter => 'add_traffic', nlabel => 'interface.traffic.in.bitspersecond', set => {
44 key_values => [ { name => 'traffic_in_15min', diff => 1 }, { name => 'traffic_in_1day', diff => 1 }, { name => 'speed_in'}, { name => 'display' } ],
45 closure_custom_calc => $self->can('custom_traffic_calc'), closure_custom_calc_extra_options => { label_ref => 'in' },
46 closure_custom_output => $self->can('custom_traffic_output'), output_error_template => 'Traffic In : %s',
47 closure_custom_perfdata => $self->can('custom_traffic_perfdata'),
48 closure_custom_threshold_check => $self->can('custom_traffic_threshold')
49 }
50 },
51 { label => 'traffic-out', filter => 'add_traffic', nlabel => 'interface.traffic.out.bitspersecond', set => {
52 key_values => [ { name => 'traffic_out_15min', diff => 1 }, { name => 'traffic_out_1day', diff => 1 }, { name => 'speed_out'}, { name => 'display' } ],
53 closure_custom_calc => $self->can('custom_traffic_calc'), closure_custom_calc_extra_options => { label_ref => 'out' },
54 closure_custom_output => $self->can('custom_traffic_output'), output_error_template => 'Traffic Out : %s',
55 closure_custom_perfdata => $self->can('custom_traffic_perfdata'),
56 closure_custom_threshold_check => $self->can('custom_traffic_threshold')
57 }
58 }
59 ;
60 }
61
62 sub set_counters {
63 my ($self, %options) = @_;
64
65 $self->SUPER::set_counters(%options);
66
67 push @{$self->{maps_counters}->{int}},
68 { label => 'laser-temp', filter => 'add_optical', nlabel => 'interface.laser.temperature.celsius', set => {
69 key_values => [ { name => 'laser_temp' }, { name => 'display' } ],
70 output_template => 'Laser Temperature : %.2f C', output_error_template => 'Laser Temperature : %.2f',
71 perfdatas => [
72 { label => 'laser_temp', template => '%.2f',
73 unit => 'C', label_extra_instance => 1, instance_use => 'display' }
74 ]
75 }
76 },
77 { label => 'input-power', filter => 'add_optical', nlabel => 'interface.input.power.dbm', set => {
78 key_values => [ { name => 'input_power' }, { name => 'display' } ],
79 output_template => 'Input Power : %s dBm', output_error_template => 'Input Power : %s',
80 perfdatas => [
81 { label => 'input_power', template => '%s',
82 unit => 'dBm', label_extra_instance => 1, instance_use => 'display' }
83 ]
84 }
85 },
86 { label => 'output-power', filter => 'add_optical', nlabel => 'interface.output.power.dbm', set => {
87 key_values => [ { name => 'output_power' }, { name => 'display' } ],
88 output_template => 'Output Power : %s dBm', output_error_template => 'Output Power : %s',
89 perfdatas => [
90 { label => 'output_power', template => '%s',
91 unit => 'dBm', label_extra_instance => 1, instance_use => 'display' }
92 ]
93 }
94 }
95 ;
96 }
97
98 sub custom_traffic_perfdata {
99 my ($self, %options) = @_;
100
101 my ($warning, $critical);
102 if ($self->{instance_mode}->{option_results}->{units_traffic} eq 'percent_delta' && defined($self->{result_values}->{speed})) {
103 $warning = $self->{perfdata}->get_perfdata_for_output(label => 'warning-' . $self->{thlabel}, total => $self->{result_values}->{speed}, cast_int => 1);
104 $critical = $self->{perfdata}->get_perfdata_for_output(label => 'critical-' . $self->{thlabel}, total => $self->{result_values}->{speed}, cast_int => 1);
105 } elsif ($self->{instance_mode}->{option_results}->{units_traffic} =~ /bps|counter/) {
106 $warning = $self->{perfdata}->get_perfdata_for_output(label => 'warning-' . $self->{thlabel});
107 $critical = $self->{perfdata}->get_perfdata_for_output(label => 'critical-' . $self->{thlabel});
108 }
109
110 if ($self->{instance_mode}->{option_results}->{units_traffic} eq 'counter') {
111 my $nlabel = $self->{nlabel};
112 $nlabel =~ s/bitspersecond/bits/;
113 $self->{output}->perfdata_add(
114 force_new_perfdata => 1,
115 nlabel => $nlabel,
116 unit => 'b',
117 instances => $self->{result_values}->{display},
118 value => $self->{result_values}->{traffic_counter},
119 warning => $warning,
120 critical => $critical,
121 min => 0
122 );
123 } else {
124 $self->{output}->perfdata_add(
125 label => 'traffic_' . $self->{result_values}->{label}, unit => 'b/s',
126 nlabel => $self->{nlabel},
127 instances => $self->use_instances(extra_instance => $options{extra_instance}) ? $self->{result_values}->{display} : undef,
128 value => sprintf('%.2f', $self->{result_values}->{traffic_per_seconds}),
129 warning => $warning,
130 critical => $critical,
131 min => 0, max => $self->{result_values}->{speed}
132 );
133 }
134 }
135
136 sub custom_traffic_threshold {
137 my ($self, %options) = @_;
138
139 my $exit = 'ok';
140 if ($self->{instance_mode}->{option_results}->{units_traffic} eq 'percent_delta' && defined($self->{result_values}->{speed})) {
141 $exit = $self->{perfdata}->threshold_check(value => $self->{result_values}->{traffic_prct}, threshold => [ { label => 'critical-' . $self->{thlabel}, exit_litteral => 'critical' }, { label => 'warning-' . $self->{thlabel}, exit_litteral => 'warning' } ]);
142 } elsif ($self->{instance_mode}->{option_results}->{units_traffic} eq 'bps') {
143 $exit = $self->{perfdata}->threshold_check(value => $self->{result_values}->{traffic_per_seconds}, threshold => [ { label => 'critical-' . $self->{thlabel}, exit_litteral => 'critical' }, { label => 'warning-' . $self->{thlabel}, exit_litteral => 'warning' } ]);
144 } elsif ($self->{instance_mode}->{option_results}->{units_traffic} eq 'counter') {
145 $exit = $self->{perfdata}->threshold_check(value => $self->{result_values}->{traffic_counter}, threshold => [ { label => 'critical-' . $self->{thlabel}, exit_litteral => 'critical' }, { label => 'warning-' . $self->{thlabel}, exit_litteral => 'warning' } ]);
146 }
147 return $exit;
148 }
149
150 sub custom_traffic_output {
151 my ($self, %options) = @_;
152
153 my $label = $self->{result_values}->{label};
154 $label =~ s/_/ /g;
155 $label =~ s/(\w+)/\u$1/g;
156 my ($traffic_value, $traffic_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{traffic_per_seconds}, network => 1);
157 my $msg = sprintf(
158 "Traffic %s : %s/s (%s)",
159 $label, $traffic_value . $traffic_unit,
160 defined($self->{result_values}->{traffic_prct}) ? sprintf('%.2f%%', $self->{result_values}->{traffic_prct}) : '-'
161 );
162 return $msg;
163 }
164
165 sub custom_traffic_calc {
166 my ($self, %options) = @_;
167
168 return -10 if (defined($self->{instance_mode}->{last_status}) && $self->{instance_mode}->{last_status} == 0);
169
170 # we choose the performance value (1day is updated every 15 minutes. 15min is updated all the time but reset every 15min
171 my $counter = 'traffic_' . $options{extra_options}->{label_ref} . '_15min';
172 if ($options{delta_time} >= 600) {
173 $counter = 'traffic_' . $options{extra_options}->{label_ref} . '_1day';
174 }
175
176 my $diff_traffic = ($options{new_datas}->{ $self->{instance} . '_' . $counter } - $options{old_datas}->{ $self->{instance} . '_' . $counter });
177
178 $self->{result_values}->{traffic_per_seconds} = $diff_traffic / $options{delta_time};
179 $self->{result_values}->{traffic_counter} = $options{new_datas}->{ $self->{instance} . '_' . $counter };
180 if (defined($options{new_datas}->{$self->{instance} . '_speed_' . $options{extra_options}->{label_ref}}) &&
181 $options{new_datas}->{$self->{instance} . '_speed_' . $options{extra_options}->{label_ref}} > 0) {
182 $self->{result_values}->{traffic_prct} = $self->{result_values}->{traffic_per_seconds} * 100 / $options{new_datas}->{$self->{instance} . '_speed_' . $options{extra_options}->{label_ref}};
183 $self->{result_values}->{speed} = $options{new_datas}->{$self->{instance} . '_speed_' . $options{extra_options}->{label_ref}};
184 }
185
186 $self->{result_values}->{label} = $options{extra_options}->{label_ref};
187 $self->{result_values}->{display} = $options{new_datas}->{$self->{instance} . '_display'};
188 return 0;
189 }
190
191 sub new {
192 my ($class, %options) = @_;
193 my $self = $class->SUPER::new(package => __PACKAGE__, %options, no_set_traffic => 1, no_errors => 1, no_cast => 1);
194 bless $self, $class;
195
196 $options{options}->add_options(arguments => {
197 'add-optical' => { name => 'add_optical' }
198 }
199 );
200
201 return $self;
202 }
203
204 sub check_options {
205 my ($self, %options) = @_;
206 $self->SUPER::check_options(%options);
207
208 $self->{checking} = '';
209 foreach (('add_global', 'add_status', 'add_traffic', 'add_speed', 'add_volume', 'add_optical')) {
210 if (defined($self->{option_results}->{$_})) {
211 $self->{checking} .= $_;
212 }
213 }
214 }
215
216 my $oid_opticalIfDiagLaserTemp = '.1.3.6.1.4.1.2544.1.11.2.4.3.5.1.2';
217 my $oid_opticalIfDiagInputPower = '.1.3.6.1.4.1.2544.1.11.2.4.3.5.1.3';
218 my $oid_opticalIfDiagOutputPower = '.1.3.6.1.4.1.2544.1.11.2.4.3.5.1.4';
219
220 sub custom_load {
221 my ($self, %options) = @_;
222
223 return if (!defined($self->{option_results}->{add_optical}));
224
225 $self->{snmp}->load(oids => [$oid_opticalIfDiagLaserTemp, $oid_opticalIfDiagInputPower, $oid_opticalIfDiagOutputPower],
226 instances => $self->{array_interface_selected});
227 }
228
229 sub custom_add_result {
230 my ($self, %options) = @_;
231
232 return if (!defined($self->{option_results}->{add_optical}));
233 $self->{int}->{$options{instance}}->{laser_temp} = undef;
234 if (defined($self->{results}->{$oid_opticalIfDiagLaserTemp . '.' . $options{instance}}) &&
235 $self->{results}->{$oid_opticalIfDiagLaserTemp . '.' . $options{instance}} != -2147483648) {
236 $self->{int}->{$options{instance}}->{laser_temp} = $self->{results}->{$oid_opticalIfDiagLaserTemp . '.' . $options{instance}} * 0.1;
237 }
238
239 $self->{int}->{$options{instance}}->{input_power} = undef;
240 if (defined($self->{results}->{$oid_opticalIfDiagInputPower . '.' . $options{instance}}) &&
241 $self->{results}->{$oid_opticalIfDiagInputPower . '.' . $options{instance}} != -65535) {
242 $self->{int}->{$options{instance}}->{input_power} = $self->{results}->{$oid_opticalIfDiagInputPower . '.' . $options{instance}} / 10;
243 }
244
245 $self->{int}->{$options{instance}}->{output_power} = undef;
246 if (defined($self->{results}->{$oid_opticalIfDiagOutputPower . '.' . $options{instance}}) &&
247 $self->{results}->{$oid_opticalIfDiagOutputPower . '.' . $options{instance}} != -65535) {
248 $self->{int}->{$options{instance}}->{output_power} = $self->{results}->{$oid_opticalIfDiagOutputPower . '.' . $options{instance}} / 10;
249 }
250 }
251
252 sub load_traffic {
253 my ($self, %options) = @_;
254
255 if ($self->{snmp}->is_snmpv1()) {
256 $self->{output}->add_option_msg(short_msg => "Can't check SNMP 64 bits counters with SNMPv1.");
257 $self->{output}->option_exit();
258 }
259
260 $self->set_oids_traffic();
261 $self->{snmp}->load(
262 oids => [
263 $self->{currentEthRx15minBytes}, $self->{currentEthRx1dayBytes},
264 $self->{currentEthTx15minBytes}, $self->{currentEthTx1dayBytes},
265 $self->{currentEthRxHighSpeed15minBytes}, $self->{currentEthRxHighSpeed1dayBytes}
266 ],
267 instances => $self->{array_interface_selected}
268 );
269 }
270
271 sub add_result_traffic {
272 my ($self, %options) = @_;
273
274 $self->{int}->{$options{instance}}->{traffic_in_15min} =
275 defined($self->{results}->{$self->{currentEthRxHighSpeed15minBytes} . '.' . $options{instance}}) ? $self->{results}->{$self->{currentEthRxHighSpeed15minBytes} . '.' . $options{instance}} * 8 :
276 (defined($self->{results}->{$self->{currentEthRx15minBytes} . '.' . $options{instance}}) ? $self->{results}->{$self->{currentEthRx15minBytes} . '.' . $options{instance}} * 8 : undef);
277 $self->{int}->{$options{instance}}->{traffic_in_1day} =
278 defined($self->{results}->{$self->{currentEthRxHighSpeed1dayBytes} . '.' . $options{instance}}) ? $self->{results}->{$self->{currentEthRxHighSpeed1dayBytes} . '.' . $options{instance}} * 8 :
279 (defined($self->{results}->{$self->{currentEthRx1dayBytes} . '.' . $options{instance}}) ? $self->{results}->{$self->{currentEthRx1dayBytes} . '.' . $options{instance}} * 8 : undef);
280 $self->{int}->{$options{instance}}->{traffic_out_15min} =
281 defined($self->{results}->{$self->{currentEthTx15minBytes} . '.' . $options{instance}}) ? $self->{results}->{$self->{currentEthTx15minBytes} . '.' . $options{instance}} * 8 : undef;
282 $self->{int}->{$options{instance}}->{traffic_out_1day} =
283 defined($self->{results}->{$self->{currentEthTx1dayBytes} . '.' . $options{instance}}) ? $self->{results}->{$self->{currentEthTx1dayBytes} . '.' . $options{instance}} * 8 : undef;
284
285 $self->{int}->{$options{instance}}->{speed_in} = 0;
286 $self->{int}->{$options{instance}}->{speed_out} = 0;
287 if ($self->{get_speed} == 0) {
288 if (defined($self->{option_results}->{speed}) && $self->{option_results}->{speed} ne '') {
289 $self->{int}->{$options{instance}}->{speed_in} = $self->{option_results}->{speed} * 1000000;
290 $self->{int}->{$options{instance}}->{speed_out} = $self->{option_results}->{speed} * 1000000;
291 }
292 $self->{int}->{$options{instance}}->{speed_in} = $self->{option_results}->{speed_in} * 1000000 if (defined($self->{option_results}->{speed_in}) && $self->{option_results}->{speed_in} ne '');
293 $self->{int}->{$options{instance}}->{speed_out} = $self->{option_results}->{speed_out} * 1000000 if (defined($self->{option_results}->{speed_out}) && $self->{option_results}->{speed_out} ne '');
294 }
295 }
296
297 1;
298
299 __END__
300
301 =head1 MODE
302
303 Check interfaces.
304
305 =over 8
306
307 =item B<--add-status>
308
309 Check interface status.
310
311 =item B<--add-traffic>
312
313 Check interface traffic.
314
315 =item B<--add-optical>
316
317 Check interface optical.
318
319 =item B<--check-metrics>
320
321 If the expression is true, metrics are checked (default: '%{opstatus} eq "up"').
322
323 =item B<--warning-status>
324
325 Define the conditions to match for the status to be WARNING.
326 You can use the following variables: %{admstatus}, %{opstatus}, %{display}
327
328 =item B<--critical-status>
329
330 Define the conditions to match for the status to be CRITICAL (default: '%{admstatus} eq "up" and %{opstatus} ne "up"').
331 You can use the following variables: %{admstatus}, %{opstatus}, %{display}
332
333 =item B<--warning-*> B<--critical-*>
334
335 Thresholds.
336 Can be: 'laser-temp', 'input-power', 'output-power', 'traffic-in', 'traffic-out'.
337
338 =item B<--units-traffic>
339
340 Units of thresholds for the traffic (default: 'percent_delta') ('percent_delta', 'bps', 'counter').
341
342 =item B<--interface>
343
344 Set the interface (number expected) example: 1,2,... (empty means 'check all interfaces').
345
346 =item B<--name>
347
348 Allows you to define the interface (in option --interface) by name instead of OID index. The name matching mode supports regular expressions.
349
350 =item B<--speed>
351
352 Set interface speed for incoming/outgoing traffic (in Mb).
353
354 =item B<--speed-in>
355
356 Set interface speed for incoming traffic (in Mb).
357
358 =item B<--speed-out>
359
360 Set interface speed for outgoing traffic (in Mb).
361
362 =item B<--reload-cache-time>
363
364 Time in minutes before reloading cache file (default: 180).
365
366 =item B<--oid-filter>
367
368 Define the OID to be used to filter interfaces (default: ifName) (values: ifDesc, ifAlias, ifName).
369
370 =item B<--oid-display>
371
372 Define the OID that will be used to name the interfaces (default: ifName) (values: ifDesc, ifAlias, ifName).
373
374 =item B<--oid-extra-display>
375
376 Add an OID to display.
377
378 =item B<--display-transform-src> B<--display-transform-dst>
379
380 Modify the interface name displayed by using a regular expression.
381
382 Example: adding --display-transform-src='eth' --display-transform-dst='ens' will replace all occurrences of 'eth' with 'ens'
383
384 =item B<--show-cache>
385
386 Display cache interface data.
387
388 =back
389
390 =cut