Debian Codegraph @

src/storage/netapp/santricity/restapi/mode/storagepools.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::netapp::santricity::restapi::mode::storagepools;
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_output {
30 my ($self, %options) = @_;
31
32 return sprintf(
33 'state: %s [raid status: %s]',
34 $self->{result_values}->{state},
35 $self->{result_values}->{raid_status}
36 );
37 }
38
39 sub custom_space_usage_output {
40 my ($self, %options) = @_;
41
42 my ($total_size_value, $total_size_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{total});
43 my ($total_used_value, $total_used_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{used});
44 my ($total_free_value, $total_free_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{free});
45 return sprintf(
46 "space usage total: %s used: %s (%.2f%%) free: %s (%.2f%%)",
47 $total_size_value . " " . $total_size_unit,
48 $total_used_value . " " . $total_used_unit, $self->{result_values}->{prct_used},
49 $total_free_value . " " . $total_free_unit, $self->{result_values}->{prct_free}
50 );
51 }
52
53 sub ss_long_output {
54 my ($self, %options) = @_;
55
56 return "checking storage system '" . $options{instance_value}->{display} . "'";
57 }
58
59 sub prefix_ss_output {
60 my ($self, %options) = @_;
61
62 return "storage system '" . $options{instance_value}->{display} . "' ";
63 }
64
65 sub prefix_pool_output {
66 my ($self, %options) = @_;
67
68 return "pool '" . $options{instance_value}->{display} . "' ";
69 }
70
71 sub set_counters {
72 my ($self, %options) = @_;
73
74 $self->{maps_counters_type} = [
75 { name => 'ss', type => 3, cb_prefix_output => 'prefix_ss_output', cb_long_output => 'ss_long_output', indent_long_output => ' ', message_multiple => 'All storage systems are ok',
76 group => [
77 { name => 'pools', display_long => 1, cb_prefix_output => 'prefix_pool_output', message_multiple => 'pools are ok', type => 1, skipped_code => { -10 => 1 } }
78 ]
79 }
80 ];
81
82 $self->{maps_counters}->{pools} = [
83 {
84 label => 'pool-status',
85 type => 2,
86 warning_default => '%{raid_status} =~ /degraded/i',
87 critical_default => '%{raid_status} =~ /failed/i',
88 set => {
89 key_values => [ { name => 'raid_status' }, { name => 'state'}, { name => 'display' } ],
90 closure_custom_output => $self->can('custom_status_output'),
91 closure_custom_perfdata => sub { return 0; },
92 closure_custom_threshold_check => \&catalog_status_threshold_ng
93 }
94 },
95 { label => 'space-usage', nlabel => 'pool.space.usage.bytes', set => {
96 key_values => [ { name => 'used' }, { name => 'free' }, { name => 'prct_used' }, { name => 'prct_free' }, { name => 'total' } ],
97 closure_custom_output => $self->can('custom_space_usage_output'),
98 perfdatas => [
99 { template => '%d', min => 0, max => 'total', unit => 'B', cast_int => 1, label_extra_instance => 1 }
100 ]
101 }
102 },
103 { label => 'space-usage-free', display_ok => 0, nlabel => 'pool.space.free.bytes', set => {
104 key_values => [ { name => 'free' }, { name => 'used' }, { name => 'prct_used' }, { name => 'prct_free' }, { name => 'total' } ],
105 closure_custom_output => $self->can('custom_space_usage_output'),
106 perfdatas => [
107 { template => '%d', min => 0, max => 'total', unit => 'B', cast_int => 1, label_extra_instance => 1 }
108 ]
109 }
110 },
111 { label => 'space-usage-prct', display_ok => 0, nlabel => 'pool.space.usage.percentage', set => {
112 key_values => [ { name => 'prct_used' }, { name => 'used' }, { name => 'free' }, { name => 'prct_free' }, { name => 'total' } ],
113 closure_custom_output => $self->can('custom_space_usage_output'),
114 perfdatas => [
115 { template => '%.2f', min => 0, max => 100, unit => '%', label_extra_instance => 1 }
116 ]
117 }
118 }
119 ];
120 }
121
122 sub new {
123 my ($class, %options) = @_;
124 my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1);
125 bless $self, $class;
126
127 $options{options}->add_options(arguments => {
128 'filter-storage-name:s' => { name => 'filter_storage_name' },
129 'filter-pool-name:s' => { name => 'filter_pool_name' }
130 });
131
132 return $self;
133 }
134
135 sub manage_selection {
136 my ($self, %options) = @_;
137
138 my $results = $options{custom}->execute_storages_request(
139 endpoints => [ { endpoint => '/storage-pools' } ],
140 filter_name => $self->{option_results}->{filter_storage_name}
141 );
142
143 $self->{ss} = {};
144 foreach (@{$results->{storages}}) {
145 my $storage_name = $_->{name};
146
147 $self->{ss}->{$storage_name} = {
148 display => $storage_name,
149 pools => {}
150 };
151
152 next if (!defined($_->{'/storage-pools'}));
153
154 foreach my $entry (@{$_->{'/storage-pools'}}) {
155
156 next if (defined($self->{option_results}->{filter_pool_name}) && $self->{option_results}->{filter_pool_name} ne '' &&
157 $entry->{name} !~ /$self->{option_results}->{filter_pool_name}/);
158
159 $self->{ss}->{$storage_name}->{pools}->{ $entry->{name} } = {
160 display => $entry->{name},
161 state => $entry->{state},
162 raid_status => $entry->{raidStatus}
163 };
164 if (defined($entry->{totalRaidedSpace}) && $entry->{totalRaidedSpace} > 0) {
165 $self->{ss}->{$storage_name}->{pools}->{ $entry->{name} }->{total} = $entry->{totalRaidedSpace};
166 $self->{ss}->{$storage_name}->{pools}->{ $entry->{name} }->{free} = $entry->{freeSpace};
167 $self->{ss}->{$storage_name}->{pools}->{ $entry->{name} }->{used} = $entry->{totalRaidedSpace} - $entry->{freeSpace};
168 $self->{ss}->{$storage_name}->{pools}->{ $entry->{name} }->{prct_free} =
169 $entry->{freeSpace} * 100 / $entry->{totalRaidedSpace};
170 $self->{ss}->{$storage_name}->{pools}->{ $entry->{name} }->{prct_used} =
171 100 - $self->{ss}->{$storage_name}->{pools}->{ $entry->{name} }->{prct_free};
172 }
173 }
174 }
175 }
176
177 1;
178
179 __END__
180
181 =head1 MODE
182
183 Check storage pools.
184
185 =over 8
186
187 =item B<--filter-counters>
188
189 Only display some counters (regexp can be used).
190 Example: --filter-counters='^pool-status$'
191
192 =item B<--filter-storage-name>
193
194 Filter storage name (can be a regexp).
195
196 =item B<--filter-pool-name>
197
198 Filter pool name (can be a regexp).
199
200 =item B<--unknown-pool-status>
201
202 Define the conditions to match for the status to be UNKNOWN.
203 You can use the following variables: %{raid_status}, %{state}, %{display}
204
205 =item B<--warning-pool-status>
206
207 Define the conditions to match for the status to be WARNING (default: '%{raid_status} =~ /degraded/i').
208 You can use the following variables: %{raid_status}, %{state}, %{display}
209
210 =item B<--critical-pool-status>
211
212 Define the conditions to match for the status to be CRITICAL (default: '%{raid_status} =~ /failed/i').
213 You can use the following variables: %{raid_status}, %{state}, %{display}
214
215 =item B<--warning-*> B<--critical-*>
216
217 Thresholds.
218 Can be: 'space-usage-prct', 'space-usage', 'space-usage-free'.
219
220 =back
221
222 =cut