Debian Codegraph @

src/storage/emc/unisphere/restapi/mode/pools.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::emc::unisphere::restapi::mode::pools;
22
23 use base qw(centreon::plugins::templates::counter);
24
25 use strict;
26 use warnings;
27 use storage::emc::unisphere::restapi::mode::components::resources qw($health_status);
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 'status : ' . $self->{result_values}->{status};
34 }
35
36 sub custom_usage_output {
37 my ($self, %options) = @_;
38
39 my ($total_size_value, $total_size_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{total_space});
40 my ($total_used_value, $total_used_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{used_space});
41 my ($total_free_value, $total_free_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{free_space});
42 return sprintf(
43 'space usage total: %s used: %s (%.2f%%) free: %s (%.2f%%)',
44 $total_size_value . " " . $total_size_unit,
45 $total_used_value . " " . $total_used_unit, $self->{result_values}->{prct_used_space},
46 $total_free_value . " " . $total_free_unit, $self->{result_values}->{prct_free_space}
47 );
48 }
49
50 sub custom_subscribed_output {
51 my ($self, %options) = @_;
52
53 my ($total_size_value, $total_size_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{total_space});
54 my ($total_used_value, $total_used_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{used_sub});
55 $self->{result_values}->{free_sub} = 0 if ($self->{result_values}->{free_sub} < 0);
56 $self->{result_values}->{prct_free_sub} = 0 if ($self->{result_values}->{prct_free_sub} < 0);
57 my ($total_free_value, $total_free_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{free_sub});
58 return sprintf(
59 'subscribed usage total: %s used: %s (%.2f%%) free: %s (%.2f%%)',
60 $total_size_value . " " . $total_size_unit,
61 $total_used_value . " " . $total_used_unit, $self->{result_values}->{prct_used_sub},
62 $total_free_value . " " . $total_free_unit, $self->{result_values}->{prct_free_sub}
63 );
64 }
65
66 sub set_counters {
67 my ($self, %options) = @_;
68
69 $self->{maps_counters_type} = [
70 { name => 'pool', type => 1, cb_prefix_output => 'prefix_pool_output', message_multiple => 'All pools are ok' }
71 ];
72
73 $self->{maps_counters}->{pool} = [
74 {
75 label => 'status',
76 type => 2,
77 unknown_default => '%{status} =~ /unknown/i',
78 warning_default => '%{status} =~ /ok_but|degraded|minor/i',
79 critical_default => '%{status} =~ /major|critical|non_recoverable/i',
80 set => {
81 key_values => [ { name => 'status' }, { name => 'display' } ],
82 closure_custom_output => $self->can('custom_status_output'),
83 closure_custom_perfdata => sub { return 0; },
84 closure_custom_threshold_check => \&catalog_status_threshold_ng
85 }
86 },
87 { label => 'usage', nlabel => 'pool.space.usage.bytes', set => {
88 key_values => [ { name => 'used_space' }, { name => 'free_space' }, { name => 'prct_used_space' }, { name => 'prct_free_space' }, { name => 'total_space' }, { name => 'display' }, ],
89 closure_custom_output => $self->can('custom_usage_output'),
90 perfdatas => [
91 { template => '%d', min => 0, max => 'total_space',
92 unit => 'B', cast_int => 1, label_extra_instance => 1, instance_use => 'display' }
93 ]
94 }
95 },
96 { label => 'usage-free', nlabel => 'pool.space.free.bytes', display_ok => 0, set => {
97 key_values => [ { name => 'free_space' }, { name => 'used_space' }, { name => 'prct_used_space' }, { name => 'prct_free_space' }, { name => 'total_space' }, { name => 'display' }, ],
98 closure_custom_output => $self->can('custom_usage_output'),
99 perfdatas => [
100 { template => '%d', min => 0, max => 'total_space',
101 unit => 'B', cast_int => 1, label_extra_instance => 1, instance_use => 'display' }
102 ]
103 }
104 },
105 { label => 'usage-prct', nlabel => 'pool.space.usage.percentage', display_ok => 0, set => {
106 key_values => [ { name => 'prct_used_space' }, { name => 'display' } ],
107 output_template => 'used : %.2f %%',
108 perfdatas => [
109 { template => '%.2f', min => 0, max => 100,
110 unit => '%', label_extra_instance => 1, instance_use => 'display' }
111 ]
112 }
113 },
114 { label => 'subscribed', nlabel => 'pool.subscribed.usage.bytes', display_ok => 0, set => {
115 key_values => [ { name => 'used_sub' }, { name => 'free_sub' }, { name => 'prct_used_sub' }, { name => 'prct_free_sub' }, { name => 'total_space' }, { name => 'display' }, ],
116 closure_custom_output => $self->can('custom_subscribed_output'),
117 perfdatas => [
118 { template => '%d', min => 0, max => 'total_space',
119 unit => 'B', cast_int => 1, label_extra_instance => 1, instance_use => 'display' }
120 ]
121 }
122 },
123 { label => 'subscribed-prct', display_ok => 0, nlabel => 'pool.subscribed.usage.percentage', set => {
124 key_values => [ { name => 'prct_used_sub' }, { name => 'display' } ],
125 output_template => 'subcribed used : %.2f %%',
126 perfdatas => [
127 { template => '%.2f', min => 0, max => 100,
128 unit => '%', label_extra_instance => 1, instance_use => 'display' }
129 ]
130 }
131 }
132 ];
133 }
134
135 sub new {
136 my ($class, %options) = @_;
137 my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1);
138 bless $self, $class;
139
140 $options{options}->add_options(arguments => {
141 'filter-name:s' => { name => 'filter_name' }
142 });
143
144 return $self;
145 }
146
147 sub prefix_pool_output {
148 my ($self, %options) = @_;
149
150 return "Pool '" . $options{instance_value}->{display} . "' ";
151 }
152
153 sub manage_selection {
154 my ($self, %options) = @_;
155
156 my $results = $options{custom}->request_api(url_path => '/api/types/pool/instances?fields=name,sizeFree,sizeSubscribed,sizeTotal,health');
157
158 $self->{pool} = {};
159 foreach (@{$results->{entries}}) {
160 if (defined($self->{option_results}->{filter_name}) && $self->{option_results}->{filter_name} ne '' &&
161 $_->{content}->{name} !~ /$self->{option_results}->{filter_name}/) {
162 $self->{output}->output_add(long_msg => "skipping pool '" . $_->{content}->{name} . "': no matching filter.", debug => 1);
163 next;
164 }
165
166 my $used = $_->{content}->{sizeTotal} - $_->{content}->{sizeFree};
167 $self->{pool}->{$_->{content}->{id}} = {
168 display => $_->{content}->{name},
169 status => $health_status->{ $_->{content}->{health}->{value} },
170 total_space => $_->{content}->{sizeTotal},
171 used_space => $used,
172 free_space => $_->{content}->{sizeFree},
173 prct_used_space => $used * 100 / $_->{content}->{sizeTotal},
174 prct_free_space => $_->{content}->{sizeFree} * 100 / $_->{content}->{sizeTotal},
175
176 used_sub => $_->{content}->{sizeSubscribed},
177 free_sub => $_->{content}->{sizeTotal} - $_->{content}->{sizeSubscribed},
178 prct_used_sub => $_->{content}->{sizeSubscribed} * 100 / $_->{content}->{sizeTotal},
179 prct_free_sub => 100 - ($_->{content}->{sizeSubscribed} * 100 / $_->{content}->{sizeTotal}),
180 };
181 }
182
183 if (scalar(keys %{$self->{pool}}) <= 0) {
184 $self->{output}->add_option_msg(short_msg => "No pool found");
185 $self->{output}->option_exit();
186 }
187 }
188
189 1;
190
191 __END__
192
193 =head1 MODE
194
195 Check pool usages.
196
197 =over 8
198
199 =item B<--filter-counters>
200
201 Only display some counters (regexp can be used).
202 Example: --filter-counters='^usage$'
203
204 =item B<--filter-name>
205
206 Filter pool name (can be a regexp).
207
208 =item B<--unknown-status>
209
210 Define the conditions to match for the status to be UNKNOWN (default: '%{status} =~ /unknown/i').
211 You can use the following variables: %{status}, %{display}
212
213 =item B<--warning-status>
214
215 Define the conditions to match for the status to be WARNING (default: '%{status} =~ /ok_but|degraded|minor/i').
216 You can use the following variables: %{status}, %{display}
217
218 =item B<--critical-status>
219
220 Define the conditions to match for the status to be CRITICAL (default: '%{status} =~ /major|critical|non_recoverable/i').
221 You can use the following variables: %{status}, %{display}
222
223 =item B<--warning-*> B<--critical-*>
224
225 Thresholds.
226 Can be: 'usage' (B), 'usage-free' (B), 'usage-prct' (%),
227 'subscribed', 'subscribed-prct'.
228
229 =back
230
231 =cut