Debian Codegraph @

src/storage/hp/3par/ssh/mode/cages.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::hp::3par::ssh::mode::cages;
22
23 use base qw(centreon::plugins::templates::counter);
24
25 use strict;
26 use warnings;
27 use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold_ng);
28
29 sub custom_status_calc {
30 my ($self, %options) = @_;
31
32 $self->{result_values}->{status} = $options{new_datas}->{$self->{instance} . '_' . $options{extra_options}->{label_ref} . '_status'};
33 $self->{result_values}->{cage_id} = $options{new_datas}->{$self->{instance} . '_cage_id'};
34 $self->{result_values}->{board_id} = $options{new_datas}->{$self->{instance} . '_board_id'};
35
36 return 0;
37 }
38
39 sub cage_long_output {
40 my ($self, %options) = @_;
41
42 return sprintf(
43 "checking cage '%s'",
44 $options{instance_value}->{cage_id}
45 );
46 }
47
48 sub prefix_cage_output {
49 my ($self, %options) = @_;
50
51 return sprintf(
52 "cage '%s' ",
53 $options{instance_value}->{cage_id}
54 );
55 }
56
57 sub prefix_board_output {
58 my ($self, %options) = @_;
59
60 return "board '" . $options{instance_value}->{board_id} . "' ";
61 }
62
63 sub prefix_psu_output {
64 my ($self, %options) = @_;
65
66 return "power supply '" . $options{instance_value}->{psu_id} . "' ";
67 }
68
69 sub prefix_drive_output {
70 my ($self, %options) = @_;
71
72 return "drive '" . $options{instance_value}->{drive_id} . "' ";
73 }
74
75 sub set_counters {
76 my ($self, %options) = @_;
77
78 $self->{maps_counters_type} = [
79 {
80 name => 'cages', type => 3, cb_prefix_output => 'prefix_cage_output', cb_long_output => 'cage_long_output', indent_long_output => ' ', message_multiple => 'All cages are ok',
81 group => [
82 { name => 'global', type => 0 },
83 { name => 'boards', display_long => 1, cb_prefix_output => 'prefix_board_output',
84 message_multiple => 'all boards are ok', type => 1, skipped_code => { -10 => 1 } },
85 { name => 'psu', display_long => 1, cb_prefix_output => 'prefix_psu_output',
86 message_multiple => 'all power supplies are ok', type => 1, skipped_code => { -10 => 1 } },
87 { name => 'drives', display_long => 1, cb_prefix_output => 'prefix_drive_output',
88 message_multiple => 'all drives are ok', type => 1, skipped_code => { -10 => 1 } }
89 ]
90 }
91 ];
92
93 $self->{maps_counters}->{global} = [
94 {
95 label => 'status',
96 type => 2,
97 critical_default => '%{status} !~ /Normal/i',
98 set => {
99 key_values => [ { name => 'status' }, { name => 'cage_id' } ],
100 output_template => 'overall status: %s',
101 closure_custom_perfdata => sub { return 0; },
102 closure_custom_threshold_check => \&catalog_status_threshold_ng
103 }
104 }
105 ];
106
107 $self->{maps_counters}->{boards} = [
108 {
109 label => 'board-firmware-status',
110 type => 2,
111 critical_default => '%{status} !~ /Current/i',
112 set => {
113 key_values => [ { name => 'firmware_status' }, { name => 'cage_id' }, { name => 'board_id' } ],
114 closure_custom_calc => $self->can('custom_status_calc'), closure_custom_calc_extra_options => { label_ref => 'firmware' },
115 output_template => 'firmware status: %s',
116 output_use => 'status',
117 closure_custom_perfdata => sub { return 0; },
118 closure_custom_threshold_check => \&catalog_status_threshold_ng
119 }
120 }
121 ];
122
123 foreach ('self', 'partner') {
124 push @{$self->{maps_counters}->{boards}},
125 {
126 label => 'board-' . $_ . '-status',
127 type => 2,
128 critical_default => '%{status} !~ /ok/i',
129 set => {
130 key_values => [ { name => $_ . '_status' }, { name => 'cage_id' }, { name => 'board_id' } ],
131 closure_custom_calc => $self->can('custom_status_calc'), closure_custom_calc_extra_options => { label_ref => $_ },
132 output_template => $_ . ' status: %s',
133 output_use => 'status',
134 closure_custom_perfdata => sub { return 0; },
135 closure_custom_threshold_check => \&catalog_status_threshold_ng
136 }
137 };
138 }
139
140 $self->{maps_counters}->{psu} = [
141 {
142 label => 'psu-status',
143 type => 2,
144 critical_default => '%{status} !~ /ok/i',
145 set => {
146 key_values => [ { name => 'status' }, { name => 'cage_id' }, { name => 'psu_id' } ],
147 output_template => 'status: %s',
148 closure_custom_perfdata => sub { return 0; },
149 closure_custom_threshold_check => \&catalog_status_threshold_ng
150 }
151 }
152 ];
153
154 foreach ('ac', 'dc', 'fan') {
155 push @{$self->{maps_counters}->{psu}},
156 {
157 label => 'psu-' . $_ . '-status',
158 type => 2,
159 critical_default => '%{status} !~ /ok/i',
160 set => {
161 key_values => [ { name => $_ . '_status' }, { name => 'cage_id' }, { name => 'psu_id' } ],
162 closure_custom_calc => $self->can('custom_status_calc'), closure_custom_calc_extra_options => { label_ref => $_ },
163 output_template => $_ . ' status: %s',
164 output_use => 'status',
165 closure_custom_perfdata => sub { return 0; },
166 closure_custom_threshold_check => \&catalog_status_threshold_ng
167 }
168 };
169 }
170
171 $self->{maps_counters}->{drives} = [
172 {
173 label => 'drive-status',
174 type => 2,
175 critical_default => '%{status} !~ /normal/i',
176 set => {
177 key_values => [ { name => 'status' }, { name => 'cage_id' }, { name => 'drive_id' } ],
178 output_template => 'status: %s',
179 closure_custom_perfdata => sub { return 0; },
180 closure_custom_threshold_check => \&catalog_status_threshold_ng
181 }
182 }
183 ];
184
185 foreach ('portA', 'portB') {
186 push @{$self->{maps_counters}->{drives}},
187 {
188 label => 'drive-' . lc($_) . '-status',
189 type => 2,
190 critical_default => '%{status} !~ /ok/i',
191 set => {
192 key_values => [ { name => $_ . '_status' }, { name => 'cage_id' }, { name => 'drive_id' } ],
193 closure_custom_calc => $self->can('custom_status_calc'), closure_custom_calc_extra_options => { label_ref => $_ },
194 output_template => $_ . ' status: %s',
195 output_use => 'status',
196 closure_custom_perfdata => sub { return 0; },
197 closure_custom_threshold_check => \&catalog_status_threshold_ng
198 }
199 };
200 }
201
202 push @{$self->{maps_counters}->{drives}},
203 { label => 'drive-temperature', nlabel => 'drive.temperature.celsius', set => {
204 key_values => [ { name => 'temperature' }, { name => 'cage_id' }, { name => 'drive_id' } ],
205 output_template => 'temperature: %s C',
206 closure_custom_perfdata => sub {
207 my ($self, %options) = @_;
208
209 $self->{output}->perfdata_add(
210 nlabel => $self->{nlabel},
211 unit => 'C',
212 instances => ['cage' . $self->{result_values}->{cage_id}, 'drive' . $self->{result_values}->{drive_id}],
213 value => sprintf('%s', $self->{result_values}->{temperature}),
214 warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-' . $self->{thlabel}),
215 critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-' . $self->{thlabel})
216 );
217 }
218 }
219 },
220 }
221
222 sub new {
223 my ($class, %options) = @_;
224 my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1);
225 bless $self, $class;
226
227 $options{options}->add_options(arguments => {
228 'filter-cage-id:s' => { name => 'filter_cage_id' }
229 });
230
231 return $self;
232 }
233
234 sub manage_selection {
235 my ($self, %options) = @_;
236
237 my ($content) = $options{custom}->execute_command(commands => ['showcage -d']);
238
239 $self->{cages} = {};
240 while ($content =~ /(Cage\s+detail\s+info\s+for\s+cage(\d+).*?)(?=Cage\s+detail\s+info\s+for\s+cage|\Z$)/msig) {
241 my ($cage_id, $entry) = ($2, $1);
242
243 next if (defined($self->{option_results}->{filter_cage_id}) && $self->{option_results}->{filter_cage_id} ne '' &&
244 $cage_id !~ /$self->{option_results}->{filter_cage_id}/);
245
246 $self->{cages}->{ 'cage' . $cage_id } = {
247 cage_id => $cage_id,
248 global => { cage_id => $cage_id },
249 boards => {},
250 psu => {},
251 drives => {}
252 };
253 $self->{cages}->{ 'cage' . $cage_id }->{global}->{status} = $1 if ($entry =~ /^OverallState:\s*(\S+)/msi);
254
255 if ($entry =~ /^Interface\s+Board\s+Info\s+(.*)/m) {
256 my @boards = split(/\s+/, $1);
257 my (@firmwares, @states);
258 @firmwares = split(/\s+/, $1) if ($entry =~ /^Firmware_status\s+(.*)/m);
259 @states = split(/\s+/, $1) if ($entry =~ /^State\(self,partner\)\s+(.*)/m);
260 for (my $i = 0; $i < scalar(@boards); $i++) {
261 next if ($boards[$i] !~ /(\d+)/);
262 my $board_id = $1;
263 $self->{cages}->{ 'cage' . $cage_id }->{boards}->{$board_id} = {
264 cage_id => $cage_id,
265 board_id => $board_id
266 };
267 $self->{cages}->{ 'cage' . $cage_id }->{boards}->{$board_id}->{firmware_status} = $firmwares[$i];
268 my ($itself, $partner) = split(/,/, $states[$i]);
269 $self->{cages}->{ 'cage' . $cage_id }->{boards}->{$board_id}->{self_status} = $itself;
270 $self->{cages}->{ 'cage' . $cage_id }->{boards}->{$board_id}->{partner_status} = $partner;
271 }
272 }
273
274 while ($entry =~ /^\s*ps(\d+)\s+(\S+)\s+(\S+)\s+(\S+)\s+(\S+)/mg) {
275 my ($psu_id, $status, $ac_status, $dc_status, $fan_status) = ($1, $2, $3, $4, $5);
276 $self->{cages}->{ 'cage' . $cage_id }->{psu}->{$psu_id} = {
277 cage_id => $cage_id,
278 psu_id => $psu_id,
279 status => $status,
280 ac_status => $ac_status,
281 dc_status => $dc_status,
282 fan_status => $fan_status
283 };
284 }
285
286 while ($entry =~ /^\s*(\d+:\d+)\s+\S+\s+(\S+)\s+(\S+)\s+(\S+)\s+(\S+)/mg) {
287 $self->{cages}->{ 'cage' . $cage_id }->{drives}->{$1} = {
288 cage_id => $cage_id,
289 drive_id => $1,
290 status => $2,
291 temperature => $3,
292 portA_status => $4,
293 portB_status => $5
294 };
295 }
296 }
297
298 if (scalar(keys %{$self->{cages}}) <= 0) {
299 $self->{output}->add_option_msg(short_msg => "Couldn't get cages information");
300 $self->{output}->option_exit();
301 }
302 }
303
304 1;
305
306 __END__
307
308 =head1 MODE
309
310 Check cages.
311
312 =over 8
313
314 =item B<--filter-cage-id>
315
316 Filter cages by ID (can be a regexp).
317
318 =item B<--unknown-status>
319
320 Define the conditions to match for the status to be UNKNOWN.
321
322 =item B<--warning-status>
323
324 Define the conditions to match for the status to be WARNING.
325
326 =item B<--critical-status>
327
328 Define the conditions to match for the status to be CRITICAL (default: '%{status} !~ /Normal/i')
329 You can use the following variables: %{status}, %{cage_id}
330
331 =item B<--unknown-board-firmware-status>
332
333 Define the conditions to match for the status to be UNKNOWN.
334
335 =item B<--warning-board-firmware-status>
336
337 Define the conditions to match for the status to be WARNING.
338
339 =item B<--critical-board-firmware-status>
340
341 Define the conditions to match for the status to be CRITICAL (default: '%{status} !~ /Current/i')
342 You can use the following variables: %{status}, %{cage_id}, %{board_id}
343
344 =item B<--unknown-board-[self|partner]-status>
345
346 Define the conditions to match for the status to be UNKNOWN.
347
348 =item B<--warning-board-[self|partner]-status>
349
350 Define the conditions to match for the status to be WARNING.
351
352 =item B<--critical-board-[self|partner]-status>
353
354 Define the conditions to match for the status to be CRITICAL (default: '%{status} !~ /ok/i')
355 You can use the following variables: %{status}, %{cage_id}, %{board_id}
356
357
358 =item B<--unknown-psu-status>
359
360 Define the conditions to match for the status to be UNKNOWN.
361
362 =item B<--warning-psu-status>
363
364 Define the conditions to match for the status to be WARNING.
365
366 =item B<--critical-psu-status>
367
368 Define the conditions to match for the status to be CRITICAL (default: '%{status} !~ /ok/i')
369 You can use the following variables: %{status}, %{cage_id}, %{psu_id}
370
371 =item B<--unknown-psu-[ac|dc|fan]-status>
372
373 Define the conditions to match for the status to be UNKNOWN.
374
375 =item B<--warning-psu-[ac|dc|fan]-status>
376
377 Define the conditions to match for the status to be WARNING.
378
379 =item B<--critical-psu-[ac|dc|fan]-status>
380
381 Define the conditions to match for the status to be CRITICAL (default: '%{status} !~ /ok/i')
382 You can use the following variables: %{status}, %{cage_id}, %{psu_id}
383
384 =item B<--unknown-drive-status>
385
386 Define the conditions to match for the status to be UNKNOWN.
387
388 =item B<--warning-drive-status>
389
390 Define the conditions to match for the status to be WARNING.
391
392 =item B<--critical-drive-status>
393
394 Define the conditions to match for the status to be CRITICAL (default: '%{status} !~ /normal/i')
395 You can use the following variables: %{status}, %{cage_id}, %{drive_id}
396
397 =item B<--unknown-drive-[porta|portb]-status>
398
399 Define the conditions to match for the status to be UNKNOWN.
400
401 =item B<--warning-drive-[porta|portb]-status>
402
403 Define the conditions to match for the status to be WARNING.
404
405 =item B<--critical-drive-[porta|portb]-status>
406
407 Define the conditions to match for the status to be CRITICAL (default: '%{status} !~ /ok/i')
408 You can use the following variables: %{status}, %{cage_id}, %{drive_id}
409
410 =item B<--warning-drive-temperature>
411
412 Define WARNING threshold for the temperature of the drives.
413
414 =item B<--critical-drive-temperature>
415
416 Define CRITICAL threshold for the temperature of the drives.
417
418 =back
419
420 =cut