Debian Codegraph @

src/os/picos/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 os::picos::snmp::mode::interfaces;
22
23 use base qw(snmp_standard::mode::interfaces);
24
25 use strict;
26 use warnings;
27
28 sub set_counters_errors {
29 my ($self, %options) = @_;
30
31 $self->SUPER::set_counters_errors(%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 => 'voltage', filter => 'add_optical', nlabel => 'interface.voltage.volt', set => {
59 key_values => [ { name => 'voltage' }, { name => 'display' } ],
60 output_template => 'Voltage : %s V',
61 perfdatas => [
62 { template => '%s', unit => 'V', label_extra_instance => 1, instance_use => 'display' }
63 ]
64 }
65 },
66 { label => 'interface-temperature', filter => 'add_optical', nlabel => 'interface.interface.temperature.celsius', set => {
67 key_values => [ { name => 'interface_temperature' }, { name => 'display' } ],
68 output_template => 'interface Temperature : %.2f C',
69 perfdatas => [
70 { template => '%.2f', unit => 'C', label_extra_instance => 1, instance_use => 'display' }
71 ]
72 }
73 }
74 ;
75 }
76
77 sub new {
78 my ($class, %options) = @_;
79 my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1);
80 bless $self, $class;
81
82 $options{options}->add_options(arguments => {
83 'add-optical' => { name => 'add_optical' }
84 });
85
86 return $self;
87 }
88
89 sub skip_interface {
90 my ($self, %options) = @_;
91
92 return ($self->{checking} =~ /cast|errors|traffic|status|volume|optical/ ? 0 : 1);
93 }
94
95 sub check_options {
96 my ($self, %options) = @_;
97 $self->SUPER::check_options(%options);
98
99 $self->{checking} = '';
100 foreach (('add_global', 'add_status', 'add_errors', 'add_traffic', 'add_cast', 'add_speed', 'add_volume', 'add_optical')) {
101 if (defined($self->{option_results}->{$_})) {
102 $self->{checking} .= $_;
103 }
104 }
105 }
106
107 sub reload_cache_custom {
108 my ($self, %options) = @_;
109
110 $options{datas}->{optical_ports} = {};
111 my $oid_picaSfpVendorName = '.1.3.6.1.4.1.35098.1.10.1.2';
112 my $snmp_result = $self->{snmp}->get_table(oid => $oid_picaSfpVendorName);
113
114 foreach (keys %$snmp_result) {
115 next if (! /^$oid_picaSfpVendorName\.(\d+)$/);
116 $options{datas}->{optical_ports}->{$1} = $snmp_result->{$_};
117 }
118 }
119
120 my $mapping_optical = {
121 output_power => { oid => '.1.3.6.1.4.1.35098.1.10.1.7' }, # picaSfpTXPower
122 input_power => { oid => '.1.3.6.1.4.1.35098.1.10.1.8' }, # picaSfpRXPower
123 interface_temperature => { oid => '.1.3.6.1.4.1.35098.1.10.1.4' }, # picaSfpTemperature
124 voltage => { oid => '.1.3.6.1.4.1.35098.1.10.1.5' }, # picaSfpVoltage
125 bias_current => { oid => '.1.3.6.1.4.1.35098.1.10.1.6' } # picaSfpBiasCurrent
126 };
127
128 sub custom_load {
129 my ($self, %options) = @_;
130
131 return if (!defined($self->{option_results}->{add_optical}));
132
133 my $optical_ports = $self->{statefile_cache}->get(name => 'optical_ports');
134 $self->{snmp}->load(
135 oids => [ map($_->{oid}, values(%$mapping_optical)) ],
136 instances => [keys %$optical_ports]
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 $optical_ports = $self->{statefile_cache}->get(name => 'optical_ports');
146 return if (!defined($optical_ports->{ $options{instance} }));
147
148 my $result = $self->{snmp}->map_instance(mapping => $mapping_optical, results => $self->{results}, instance => $options{instance});
149
150 $self->{int}->{ $options{instance} }->{input_power} = undef;
151 if (defined($result->{input_power}) && $result->{input_power} =~ /(^[+-]?\d+\.?\d+)/ ) {
152 $self->{int}->{ $options{instance} }->{input_power} = $1;
153 }
154
155 $self->{int}->{$options{instance}}->{bias_current} = undef;
156 if (defined($result->{bias_current}) && $result->{bias_current} =~ /(^[+-]?\d+\.?\d+)/ ) {
157 $self->{int}->{$options{instance}}->{bias_current} = $1;
158 }
159
160 $self->{int}->{$options{instance}}->{output_power} = undef;
161 if (defined($result->{output_power}) && $result->{output_power} =~ /(^[+-]?\d+\.?\d+)/ ) {
162 $self->{int}->{$options{instance}}->{output_power} = $1;
163 }
164
165 $self->{int}->{$options{instance}}->{interface_temperature} = undef;
166 if (defined($result->{interface_temperature}) && $result->{interface_temperature} =~ /(^[+-]?\d+\.?\d+)/ ) {
167 $self->{int}->{$options{instance}}->{interface_temperature} = $1;
168 }
169
170 $self->{int}->{$options{instance}}->{voltage} = undef;
171 if (defined($result->{voltage}) && $result->{voltage} =~ /(^[+-]?\d+\.?\d+)/ ) {
172 $self->{int}->{$options{instance}}->{voltage} = $1;
173 }
174 }
175
176 1;
177
178 __END__
179
180 =head1 MODE
181
182 Check interfaces.
183
184 =over 8
185
186 =item B<--add-global>
187
188 Check global port statistics (by default if no --add-* option is set).
189
190 =item B<--add-status>
191
192 Check interface status.
193
194 =item B<--add-duplex-status>
195
196 Check duplex status (with --warning-status and --critical-status).
197
198 =item B<--add-traffic>
199
200 Check interface traffic.
201
202 =item B<--add-errors>
203
204 Check interface errors.
205
206 =item B<--add-cast>
207
208 Check interface cast.
209
210 =item B<--add-speed>
211
212 Check interface speed.
213
214 =item B<--add-volume>
215
216 Check interface data volume between two checks (not supposed to be graphed, useful for BI reporting).
217
218 =item B<--add-optical>
219
220 Check interface optical metrics.
221
222 =item B<--check-metrics>
223
224 If the expression is true, metrics are checked (default: '%{opstatus} eq "up"').
225
226 =item B<--warning-status>
227
228 Define the conditions to match for the status to be WARNING.
229 You can use the following variables: %{admstatus}, %{opstatus}, %{duplexstatus}, %{display}
230
231 =item B<--critical-status>
232
233 Define the conditions to match for the status to be CRITICAL (default: '%{admstatus} eq "up" and %{opstatus} ne "up"').
234 You can use the following variables: %{admstatus}, %{opstatus}, %{duplexstatus}, %{display}
235
236 =item B<--warning-*> B<--critical-*>
237
238 Thresholds.
239 Can be: 'total-port', 'total-admin-up', 'total-admin-down', 'total-oper-up', 'total-oper-down',
240 'in-traffic', 'out-traffic', 'in-error', 'in-discard', 'out-error', 'out-discard',
241 'in-ucast', 'in-bcast', 'in-mcast', 'out-ucast', 'out-bcast', 'out-mcast',
242 'speed' (b/s).
243
244 And also: 'input-power' (dBm), 'bias-current' (mA), 'output-power' (dBm), 'voltage' (mV), 'interface-temperature' (C).
245
246 =item B<--units-traffic>
247
248 Units of thresholds for the traffic (default: 'percent_delta') ('percent_delta', 'bps', 'counter').
249
250 =item B<--units-errors>
251
252 Units of thresholds for errors/discards (default: 'percent_delta') ('percent_delta', 'percent', 'delta', 'deltaps', 'counter').
253
254 =item B<--units-cast>
255
256 Units of thresholds for communication types (default: 'percent_delta') ('percent_delta', 'percent', 'delta', 'deltaps', 'counter').
257
258 =item B<--nagvis-perfdata>
259
260 Display traffic perfdata to be compatible with nagvis widget.
261
262 =item B<--interface>
263
264 Set the interface (number expected) example: 1,2,... (empty means 'check all interfaces').
265
266 =item B<--name>
267
268 Allows you to define the interface (in option --interface) by name instead of OID index. The name matching mode supports regular expressions.
269
270 =item B<--speed>
271
272 Set interface speed for incoming/outgoing traffic (in Mb).
273
274 =item B<--speed-in>
275
276 Set interface speed for incoming traffic (in Mb).
277
278 =item B<--speed-out>
279
280 Set interface speed for outgoing traffic (in Mb).
281
282 =item B<--force-counters32>
283
284 Force to use 32 bits counters (even in snmp v2c and v3). Should be used when 64 bits counters are buggy.
285
286 =item B<--reload-cache-time>
287
288 Time in minutes before reloading cache file (default: 180).
289
290 =item B<--oid-filter>
291
292 Define the OID to be used to filter interfaces (default: ifName) (values: ifDesc, ifAlias, ifName, IpAddr).
293
294 =item B<--oid-display>
295
296 Define the OID that will be used to name the interfaces (default: ifName) (values: ifDesc, ifAlias, ifName, IpAddr).
297
298 =item B<--oid-extra-display>
299
300 Add an OID to display.
301
302 =item B<--display-transform-src> B<--display-transform-dst>
303
304 Modify the interface name displayed by using a regular expression.
305
306 Example: adding --display-transform-src='eth' --display-transform-dst='ens' will replace all occurrences of 'eth' with 'ens'
307
308 =item B<--show-cache>
309
310 Display cache interface data.
311
312 =back
313
314 =cut