Debian Codegraph @

src/storage/hp/primera/restapi/mode/capacity.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::primera::restapi::mode::capacity;
22
23 use base qw(centreon::plugins::templates::counter);
24
25 use strict;
26 use warnings;
27
28 sub custom_space_usage_output {
29 my ($self, %options) = @_;
30
31 my ($total_size_value, $total_size_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{total});
32 my ($total_used_value, $total_used_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{used});
33 my ($total_free_value, $total_free_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{free});
34 return sprintf(
35 'space usage total: %s used: %s (%.2f%%) free: %s (%.2f%%)',
36 $total_size_value . " " . $total_size_unit,
37 $total_used_value . " " . $total_used_unit, $self->{result_values}->{prct_used},
38 $total_free_value . " " . $total_free_unit, $self->{result_values}->{prct_free}
39 );
40 }
41
42 sub storage_long_output {
43 my ($self, %options) = @_;
44
45 return sprintf(
46 "checking storage '%s'",
47 $options{instance_value}->{type}
48 );
49 }
50
51 sub prefix_storage_output {
52 my ($self, %options) = @_;
53
54 return sprintf(
55 "storage '%s' ",
56 $options{instance_value}->{type}
57 );
58 }
59
60 sub set_counters {
61 my ($self, %options) = @_;
62
63 $self->{maps_counters_type} = [
64 {
65 name => 'storages', type => 3, cb_prefix_output => 'prefix_storage_output', cb_long_output => 'storage_long_output', indent_long_output => ' ', message_multiple => 'All storage capacities are ok',
66 group => [
67 { name => 'space', type => 0 },
68 { name => 'efficiency', type => 0, skipped_code => { -10 => 1 } }
69 ]
70 }
71 ];
72
73 $self->{maps_counters}->{space} = [
74 { label => 'space-usage', nlabel => 'storage.space.usage.bytes', set => {
75 key_values => [ { name => 'used' }, { name => 'free' }, { name => 'prct_used' }, { name => 'prct_free' }, { name => 'total' } ],
76 closure_custom_output => $self->can('custom_space_usage_output'),
77 perfdatas => [
78 { template => '%d', min => 0, max => 'total', unit => 'B', cast_int => 1, label_extra_instance => 1 }
79 ]
80 }
81 },
82 { label => 'space-usage-free', nlabel => 'storage.space.free.bytes', display_ok => 0, set => {
83 key_values => [ { name => 'free' }, { name => 'used' }, { name => 'prct_used' }, { name => 'prct_free' }, { name => 'total' } ],
84 closure_custom_output => $self->can('custom_space_usage_output'),
85 perfdatas => [
86 { template => '%d', min => 0, max => 'total', unit => 'B', cast_int => 1, label_extra_instance => 1 }
87 ]
88 }
89 },
90 { label => 'space-usage-prct', nlabel => 'storage.space.usage.percentage', display_ok => 0, set => {
91 key_values => [ { name => 'prct_used' }, { name => 'used' }, { name => 'free' }, { name => 'prct_free' }, { name => 'total' } ],
92 closure_custom_output => $self->can('custom_space_usage_output'),
93 perfdatas => [
94 { template => '%.2f', min => 0, max => 100, unit => '%', label_extra_instance => 1 }
95 ]
96 }
97 },
98 { label => 'space-unavailable', nlabel => 'storage.space.unavailable.bytes', set => {
99 key_values => [ { name => 'unavailable' } ],
100 output_template => 'unavailable: %s %s',
101 output_change_bytes => 1,
102 perfdatas => [
103 { template => '%s', unit => 'B', min => 0, label_extra_instance => 1 }
104 ]
105 }
106 },
107 { label => 'space-failed', nlabel => 'storage.space.failed.bytes', set => {
108 key_values => [ { name => 'failed' } ],
109 output_template => 'failed: %s %s',
110 output_change_bytes => 1,
111 perfdatas => [
112 { template => '%s', unit => 'B', min => 0, label_extra_instance => 1 }
113 ]
114 }
115 }
116 ];
117
118 $self->{maps_counters}->{efficiency} = [
119 { label => 'compaction', nlabel => 'storage.space.compaction.ratio.count', set => {
120 key_values => [ { name => 'compaction' } ],
121 output_template => 'compaction: %s',
122 perfdatas => [
123 { template => '%s', min => 0, label_extra_instance => 1 }
124 ]
125 }
126 },
127 { label => 'deduplication', nlabel => 'storage.space.deduplication.ratio.count', set => {
128 key_values => [ { name => 'deduplication' } ],
129 output_template => 'deduplication: %s',
130 perfdatas => [
131 { template => '%s', min => 0, label_extra_instance => 1 }
132 ]
133 }
134 },
135 { label => 'compression', nlabel => 'storage.space.compression.ratio.count', set => {
136 key_values => [ { name => 'compression' } ],
137 output_template => 'compression: %s',
138 perfdatas => [
139 { template => '%s', min => 0, label_extra_instance => 1 }
140 ]
141 }
142 },
143 { label => 'data-reduction', nlabel => 'storage.space.data_reduction.ratio.count', set => {
144 key_values => [ { name => 'data_reduction' } ],
145 output_template => 'data reduction: %s',
146 perfdatas => [
147 { template => '%s', min => 0, label_extra_instance => 1 }
148 ]
149 }
150 },
151 { label => 'overprovisioning', nlabel => 'storage.space.overprovisioning.ratio.count', set => {
152 key_values => [ { name => 'overprovisioning' } ],
153 output_template => 'overprovisioning: %s',
154 perfdatas => [
155 { template => '%s', min => 0, label_extra_instance => 1 }
156 ]
157 }
158 }
159 ];
160 }
161
162 sub new {
163 my ($class, %options) = @_;
164 my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1);
165 bless $self, $class;
166
167 $options{options}->add_options(arguments => {
168 'filter-type:s' => { name => 'filter_type' }
169 });
170
171 return $self;
172 }
173
174 sub manage_selection {
175 my ($self, %options) = @_;
176
177 my $response = $options{custom}->request_api(
178 endpoint => '/api/v1/capacity'
179 );
180
181 for my $type (keys %{$response}) {
182 next if (defined($self->{option_results}->{filter_type}) && $self->{option_results}->{filter_type} ne ''
183 && $type !~ /$self->{option_results}->{filter_type}/);
184
185 my $total = $response->{$type}->{totalMiB} * 1024 * 1024;
186 my $free = $response->{$type}->{freeMiB} * 1024 * 1024;
187 my $unavailable = $response->{$type}->{unavailableCapacityMiB} * 1024 * 1024;
188 my $failed = $response->{$type}->{failedCapacityMiB} * 1024 * 1024;
189
190 $self->{storages}->{$type} = {
191 type => $type,
192 space => {
193 total => $total,
194 free => $free,
195 used => $total - $free,
196 unavailable => $unavailable,
197 prct_used => ($total - $free) * 100 / $total,
198 prct_free => $free * 100 / $total,
199 failed => $failed
200 }
201 };
202
203 my $shortcut = $response->{$type}->{allocated}->{volumes}->{capacityEfficiency};
204
205 $self->{storages}->{$type}->{efficiency}->{compaction} = $shortcut->{compaction} if defined($shortcut->{compaction});
206 $self->{storages}->{$type}->{efficiency}->{deduplication} = $shortcut->{deduplication} if defined($shortcut->{deduplication});
207 $self->{storages}->{$type}->{efficiency}->{compression} = $shortcut->{compression} if defined($shortcut->{compression});
208 $self->{storages}->{$type}->{efficiency}->{data_reduction} = $shortcut->{dataReduction} if defined($shortcut->{dataReduction});
209 $self->{storages}->{$type}->{efficiency}->{overprovisioning} = $shortcut->{overProvisioning} if defined($shortcut->{overProvisioning});
210 }
211
212 if (scalar(keys %{$self->{storages}}) <= 0) {
213 $self->{output}->add_option_msg(short_msg => "Couldn't get capacity information");
214 $self->{output}->option_exit();
215 }
216 }
217
218 1;
219
220 __END__
221
222 =head1 MODE
223
224 Check storage capacity per storage type.
225
226 =over 8
227
228 =item B<--filter-type>
229
230 Filter storage by type (regular expression).
231 The known types are: allCapacity, FCCapacity, SSDCapacity and NLCapacity.
232
233 =item B<--warning-*> B<--critical-*>
234
235 Thresholds that can apply to:
236 - Space oriented metrics: 'space-usage', 'space-usage-free', 'space-usage-prct', 'space-unavailable', 'space-failed',
237 - Storage optimization metrics: 'compaction', 'deduplication', 'compression', 'data-reduction', 'overprovisioning'.
238
239 =back
240
241 =cut