Debian Codegraph @

src/storage/fujitsu/eternus/dx/ssh/mode/raidgroups.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::fujitsu::eternus::dx::ssh::mode::raidgroups;
22
23 use base qw(centreon::plugins::templates::counter);
24
25 use strict;
26 use warnings;
27 use centreon::plugins::misc;
28
29 sub custom_threshold_output {
30 my ($self, %options) = @_;
31
32 return $self->{instance_mode}->get_severity(section => 'rg', value => $self->{result_values}->{status});
33 }
34
35 sub custom_usage_perfdata {
36 my ($self, %options) = @_;
37
38 $self->{output}->perfdata_add(
39 label => 'used', unit => 'B',
40 nlabel => $self->{nlabel},
41 instances => $self->use_instances(extra_instance => $options{extra_instance}) ? $self->{result_values}->{display} : undef,
42 value => $self->{result_values}->{used},
43 warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-' . $self->{thlabel}, total => $self->{result_values}->{total}, cast_int => 1),
44 critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-' . $self->{thlabel}, total => $self->{result_values}->{total}, cast_int => 1),
45 min => 0, max => $self->{result_values}->{total}
46 );
47 }
48
49 sub custom_usage_threshold {
50 my ($self, %options) = @_;
51
52 my $exit = $self->{perfdata}->threshold_check(value => $self->{result_values}->{prct_used}, threshold => [ { label => 'critical-' . $self->{thlabel}, exit_litteral => 'critical' }, { label => 'warning-' . $self->{thlabel}, exit_litteral => 'warning' } ]);
53 return $exit;
54 }
55
56 sub custom_usage_output {
57 my ($self, %options) = @_;
58
59 my ($total_size_value, $total_size_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{total});
60 my ($total_used_value, $total_used_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{used});
61 my ($total_free_value, $total_free_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{free});
62
63 my $msg = sprintf("Total: %s Used: %s (%.2f%%) Free: %s (%.2f%%)",
64 $total_size_value . " " . $total_size_unit,
65 $total_used_value . " " . $total_used_unit, $self->{result_values}->{prct_used},
66 $total_free_value . " " . $total_free_unit, $self->{result_values}->{prct_free});
67 return $msg;
68 }
69
70 sub custom_usage_calc {
71 my ($self, %options) = @_;
72
73 $self->{result_values}->{display} = $options{new_datas}->{$self->{instance} . '_display'};
74 $self->{result_values}->{total} = $options{new_datas}->{$self->{instance} . '_total'};
75 $self->{result_values}->{used} = $options{new_datas}->{$self->{instance} . '_used'};
76 $self->{result_values}->{free} = $self->{result_values}->{total} - $self->{result_values}->{used};
77 $self->{result_values}->{prct_free} = $self->{result_values}->{free} * 100 / $self->{result_values}->{total};
78 $self->{result_values}->{prct_used} = $self->{result_values}->{used} * 100 / $self->{result_values}->{total};
79 return 0;
80 }
81
82 sub prefix_rg_output {
83 my ($self, %options) = @_;
84
85 return "Raid Group '" . $options{instance_value}->{display} . "' ";
86 }
87
88 sub set_counters {
89 my ($self, %options) = @_;
90
91 $self->{maps_counters_type} = [
92 { name => 'rg', type => 1, cb_prefix_output => 'prefix_rg_output', message_multiple => 'All raid groups are ok' }
93 ];
94
95 $self->{maps_counters}->{rg} = [
96 { label => 'status', threshold => 0, set => {
97 key_values => [ { name => 'status' } ],
98 output_template => 'Status : %s', output_error_template => 'Status : %s',
99 output_use => 'status',
100 closure_custom_perfdata => sub { return 0; },
101 closure_custom_threshold_check => $self->can('custom_threshold_output')
102 }
103 },
104 { label => 'usage', nlabel => 'raidgroup.space.usage.bytes', set => {
105 key_values => [ { name => 'display' }, { name => 'total' }, { name => 'used' } ],
106 closure_custom_calc => $self->can('custom_usage_calc'),
107 closure_custom_output => $self->can('custom_usage_output'),
108 closure_custom_perfdata => $self->can('custom_usage_perfdata'),
109 closure_custom_threshold_check => $self->can('custom_usage_threshold')
110 }
111 }
112 ];
113 }
114
115 sub new {
116 my ($class, %options) = @_;
117 my $self = $class->SUPER::new(package => __PACKAGE__, %options);
118 bless $self, $class;
119
120 $options{options}->add_options(arguments => {
121 'threshold-overload:s@' => { name => 'threshold_overload' },
122 'filter-name:s' => { name => 'filter_name' },
123 'filter-level:s' => { name => 'filter_level' }
124 });
125
126 return $self;
127 }
128
129 sub check_options {
130 my ($self, %options) = @_;
131 $self->SUPER::check_options(%options);
132
133 $self->{overload_th} = {};
134 foreach my $val (@{$self->{option_results}->{threshold_overload}}) {
135 if ($val !~ /^(.*?),(.*?),(.*)$/) {
136 $self->{output}->add_option_msg(short_msg => "Wrong threshold-overload option '" . $val . "'.");
137 $self->{output}->option_exit();
138 }
139 my ($section, $status, $filter) = ($1, $2, $3);
140 if ($self->{output}->is_litteral_status(status => $status) == 0) {
141 $self->{output}->add_option_msg(short_msg => "Wrong threshold-overload status '" . $val . "'.");
142 $self->{output}->option_exit();
143 }
144 $self->{overload_th}->{$section} = [] if (!defined($self->{overload_th}->{$section}));
145 push @{$self->{overload_th}->{$section}}, {filter => $filter, status => $status};
146 }
147 }
148
149 sub manage_selection {
150 my ($self, %options) = @_;
151
152 my ($stdout) = $options{custom}->execute_command(
153 command => 'show',
154 command_options => "raid-groups -csv\n",
155 ssh_pipe => 1
156 );
157
158 #[RAID Group No.],[RAID Group Name],[RAID Level],[Assigned CM],[Status],[Total Capacity(MB)],[Free Capacity(MB)]
159 #1,RAIDGROUP001,RAID1+0,CM#0,Spare in Use,134656,132535
160 #2,RAIDGROUP002,RAID5,CM#1,Available,134656,132532
161 #3,RAIDGROUP003,RAID5,CM#1,SED Locked,134656,132532
162
163 $self->{rg} = {};
164 while ($stdout =~ /^(.*?),(.*?),(.*?),.*?,(.*?),(.*?),(.*?)$/msg) {
165 my ($raid_num, $raid_name, $raid_level, $raid_status, $raid_total, $raid_free) = ($1, $2, $3, $4, $5, $6);
166 next if ($raid_num =~ /\[.*?\]/);
167
168 if (defined($self->{option_results}->{filter_name}) && $self->{option_results}->{filter_name} ne '' &&
169 $raid_name !~ /$self->{option_results}->{filter_name}/) {
170 $self->{output}->output_add(long_msg => "Skipping '" . $raid_name . "': no matching filter name.");
171 next;
172 }
173 if (defined($self->{option_results}->{filter_level}) && $self->{option_results}->{filter_level} ne '' &&
174 $raid_level !~ /$self->{option_results}->{filter_level}/) {
175 $self->{output}->output_add(long_msg => "Skipping '" . $raid_name . "': no matching filter level.");
176 next;
177 }
178
179 $self->{rg}->{$raid_num} = {
180 status => $raid_status, total => $raid_total * 1024 * 1024,
181 used => ($raid_total * 1024 * 1024) - ($raid_free * 1024 * 1024),
182 display => $raid_name
183 };
184 }
185
186 if (scalar(keys %{$self->{rg}}) <= 0) {
187 $self->{output}->add_option_msg(short_msg => "No raid group found.");
188 $self->{output}->option_exit();
189 }
190 }
191
192 my $thresholds = {
193 rg => [
194 ['Available', 'OK'],
195 ['Spare in Use', 'WARNING']
196 ]
197 };
198
199 sub get_severity {
200 my ($self, %options) = @_;
201 my $status = 'UNKNOWN'; # default
202
203 if (defined($self->{overload_th}->{$options{section}})) {
204 foreach (@{$self->{overload_th}->{$options{section}}}) {
205 if ($options{value} =~ /$_->{filter}/i) {
206 $status = $_->{status};
207 return $status;
208 }
209 }
210 }
211 foreach (@{$thresholds->{$options{section}}}) {
212 if ($options{value} =~ /$$_[0]/i) {
213 $status = $$_[1];
214 return $status;
215 }
216 }
217
218 return $status;
219 }
220
221 1;
222
223 __END__
224
225 =head1 MODE
226
227 Check raid groups.
228
229 Command used: show raid-groups -csv
230
231 =over 8
232
233 =item B<--threshold-overload>
234
235 Use this option to override the status returned by the plugin when the status label matches a regular expression (syntax: section,status,regexp).
236 Example: --threshold-overload='rg,CRITICAL,^(?!(Available|Spare)$)'
237
238 =item B<--filter-name>
239
240 Filter by name (regexp can be used).
241
242 =item B<--filter-level>
243
244 Filter by raid level (regexp can be used).
245
246 =item B<--warning-usage>
247
248 Warning threshold (in percent).
249
250 =item B<--critical-usage>
251
252 Critical threshold (in percent).
253
254 =back
255
256 =cut