Debian Codegraph @

src/storage/dell/me4/restapi/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 storage::dell::me4::restapi::mode::interfaces;
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_status_output {
31 my ($self, %options) = @_;
32
33 return sprintf(
34 'status: %s [health: %s]',
35 $self->{result_values}->{status},
36 $self->{result_values}->{health}
37 );
38 }
39
40 sub port_long_output {
41 my ($self, %options) = @_;
42
43 return "checking port '" . $options{instance_value}->{display} . "'";
44 }
45
46 sub prefix_port_output {
47 my ($self, %options) = @_;
48
49 return "port '" . $options{instance_value}->{display} . "' ";
50 }
51
52 sub prefix_interface_output {
53 my ($self, %options) = @_;
54
55 return "interface '" . $options{instance_value}->{display} . "' ";
56 }
57
58 sub set_counters {
59 my ($self, %options) = @_;
60
61 $self->{maps_counters_type} = [
62 { name => 'ports', type => 3, cb_prefix_output => 'prefix_port_output', cb_long_output => 'port_long_output', indent_long_output => ' ', message_multiple => 'All interfaces are ok',
63 group => [
64 { name => 'port_global', type => 0, skipped_code => { -10 => 1 } },
65 { name => 'interfaces', display_long => 1, cb_prefix_output => 'prefix_interface_output', message_multiple => 'All interfaces are ok', type => 1, skipped_code => { -10 => 1 } }
66 ]
67 }
68 ];
69
70 $self->{maps_counters}->{port_global} = [
71 {
72 label => 'port-status',
73 type => 2,
74 unknown_default => '%{health} =~ /unknown/i',
75 warning_default => '%{health} =~ /degraded/i',
76 critical_default => '%{health} =~ /fault/i',
77 set => {
78 key_values => [ { name => 'status' }, { name => 'health'}, { name => 'display' } ],
79 closure_custom_output => $self->can('custom_status_output'),
80 closure_custom_perfdata => sub { return 0; },
81 closure_custom_threshold_check => \&catalog_status_threshold_ng
82 }
83 },
84 { label => 'read-iops', nlabel => 'port.io.read.usage.iops', set => {
85 key_values => [ { name => 'number_of_reads', per_second => 1 }, { name => 'display' } ],
86 output_template => 'read iops: %.2f',
87 perfdatas => [
88 { template => '%.2f', unit => 'iops', min => 0, label_extra_instance => 1 }
89 ]
90 }
91 },
92 { label => 'write-iops', nlabel => 'port.io.write.usage.iops', set => {
93 key_values => [ { name => 'number_of_writes', per_second => 1 }, { name => 'display' } ],
94 output_template => 'write iops: %.2f',
95 perfdatas => [
96 { template => '%.2f', unit => 'iops', min => 0, label_extra_instance => 1 }
97 ]
98 }
99 },
100 { label => 'read-traffic', nlabel => 'port.traffic.read.usage.bitspersecond', set => {
101 key_values => [ { name => 'data_read_numeric', per_second => 1 }, { name => 'display' } ],
102 output_template => 'read traffic: %s %s/s',
103 output_change_bytes => 2,
104 perfdatas => [
105 { template => '%d', unit => 'b/s', min => 0, label_extra_instance => 1 }
106 ]
107 }
108 },
109 { label => 'write-traffic', nlabel => 'port.traffic.write.usage.bitspersecond', set => {
110 key_values => [ { name => 'data_write_numeric', per_second => 1 }, { name => 'display' } ],
111 output_template => 'write traffic: %s %s/s',
112 output_change_bytes => 2,
113 perfdatas => [
114 { template => '%d', unit => 'b/s', min => 0, label_extra_instance => 1 }
115 ]
116 }
117 }
118 ];
119
120 $self->{maps_counters}->{interfaces} = [
121 { label => 'interface-disparity-errors', nlabel => 'port.interface.disparity.errors.count', set => {
122 key_values => [ { name => 'disparity_errors' }, { name => 'display' } ],
123 output_template => 'disparity errors: %s',
124 perfdatas => [
125 { template => '%d', min => 0, label_extra_instance => 1 }
126 ]
127 }
128 },
129 { label => 'interface-lost-dwords', nlabel => 'port.interface.lost.dwords.count', set => {
130 key_values => [ { name => 'lost_dwords' }, { name => 'display' } ],
131 output_template => 'lost dwords: %s',
132 perfdatas => [
133 { template => '%d', min => 0, label_extra_instance => 1 }
134 ]
135 }
136 },
137 { label => 'interface-invalid-dwords', nlabel => 'port.interface.invalid.dwords.count', set => {
138 key_values => [ { name => 'invalid_dwords' }, { name => 'display' } ],
139 output_template => 'invalid dwords: %s',
140 perfdatas => [
141 { template => '%d', min => 0, label_extra_instance => 1 }
142 ]
143 }
144 }
145 ];
146 }
147
148 sub new {
149 my ($class, %options) = @_;
150 my $self = $class->SUPER::new(package => __PACKAGE__, %options, statefile => 1, force_new_perfdata => 1);
151 bless $self, $class;
152
153 $options{options}->add_options(arguments => {
154 'filter-port-name:s' => { name => 'filter_port_name' }
155 });
156
157 return $self;
158 }
159
160 my $mapping_status = {
161 0 => 'up',
162 1 => 'down',
163 2 => 'notInstalled'
164 };
165 my $mapping_health = {
166 0 => 'ok', 1 => 'degraded', 2 => 'fault', 3 => 'unknown', 4 => 'notAvailable'
167 };
168
169 sub manage_selection {
170 my ($self, %options) = @_;
171
172 my $result_ports = $options{custom}->request_api(method => 'GET', url_path => '/api/show/ports');
173 my $result_ports_stats = $options{custom}->request_api(method => 'GET', url_path => '/api/show/host-port-statistics');
174 my $result_logical_interfaces = $options{custom}->request_api(method => 'GET', url_path => '/api/show/host-phy-statistics');
175
176 my $mapping_ports = {};
177
178 $self->{ports} = {};
179 foreach my $port (@{$result_ports->{port}}) {
180 my $port_name = $port->{port};
181
182 next if (defined($self->{option_results}->{filter_port_name}) && $self->{option_results}->{filter_port_name} ne ''
183 && $port_name !~ /$self->{option_results}->{filter_port_name}/);
184
185 $mapping_ports->{ $port->{'durable-id'} } = $port_name;
186
187 $self->{ports}->{$port_name} = {
188 display => $port_name,
189 port_global => {
190 display => $port_name,
191 health => $mapping_health->{ $port->{'health-numeric'} },
192 status => $mapping_status->{ $port->{'status-numeric'} }
193 },
194 interfaces => {}
195 };
196 }
197
198 foreach (@{$result_ports_stats->{'host-port-statistics'}}) {
199 next if (!defined($mapping_ports->{ $_->{'durable-id'} }));
200
201 $self->{ports}->{ $mapping_ports->{ $_->{'durable-id'} } }->{port_global}->{number_of_reads} = $_->{'number-of-reads'};
202 $self->{ports}->{ $mapping_ports->{ $_->{'durable-id'} } }->{port_global}->{number_of_writes} = $_->{'number-of-writes'};
203 $self->{ports}->{ $mapping_ports->{ $_->{'durable-id'} } }->{port_global}->{data_read_numeric} = $_->{'data-read-numeric'};
204 $self->{ports}->{ $mapping_ports->{ $_->{'durable-id'} } }->{port_global}->{data_write_numeric} = $_->{'data-write-numeric'};
205
206 }
207
208 foreach (@{$result_logical_interfaces->{'sas-host-phy-statistics'}}) {
209 next if (!defined($self->{ports}->{ $_->{port} }));
210
211 $self->{ports}->{ $_->{port} }->{interfaces}->{ $_->{phy} } = {
212 display => $_->{phy},
213 disparity_errors => int($_->{'disparity-errors'}),
214 invalid_dwords => int($_->{'invalid-dwords'}),
215 lost_dwords => int($_->{'lost-dwords'})
216 };
217 }
218
219 $self->{cache_name} = 'dell_me4_' . $self->{mode} . '_' . $options{custom}->get_hostname() . '_' .
220 (defined($self->{option_results}->{filter_counters}) ? md5_hex($self->{option_results}->{filter_counters}) : md5_hex('all')) . '_' .
221 (defined($self->{option_results}->{filter_port_name}) ? md5_hex($self->{option_results}->{filter_port_name}) : md5_hex('all'));
222 }
223
224 1;
225
226 __END__
227
228 =head1 MODE
229
230 Check interfaces.
231
232 =over 8
233
234 =item B<--filter-port-name>
235
236 Filter port name (can be a regexp).
237
238 =item B<--unknown-port-status>
239
240 Define the conditions to match for the status to be UNKNOWN (default: '%{status} =~ /unknown/i').
241 You can use the following variables: %{status}, %{health}, %{display}
242
243 =item B<--warning-port-status>
244
245 Define the conditions to match for the status to be WARNING (default: '%{status} =~ /degraded/i').
246 You can use the following variables: %{status}, %{health}, %{display}
247
248 =item B<--critical-port-status>
249
250 Define the conditions to match for the status to be CRITICAL (default: '%{status} =~ /fault/i').
251 You can use the following variables: %{status}, %{health}, %{display}
252
253 =item B<--warning-*> B<--critical-*>
254
255 Thresholds.
256 Can be: 'read-iops', 'write-iops', 'read-traffic', 'write-traffic',
257 'interface-disparity-errors', 'interface-lost-dwords', 'interface-invalid-dwords'.
258
259 =back
260
261 =cut