| 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::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 => 'dedup', nlabel => 'storage.space.deduplication.ratio.count', set => { |
| 128 |
key_values => [ { name => 'dedup' } ], |
| 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 ($content) = $options{custom}->execute_command( |
| 178 |
commands => [ |
| 179 |
'echo "===spaceTotal==="', |
| 180 |
'showsys -space', |
| 181 |
'echo "===spaceSSD==="', |
| 182 |
'showsys -space -devtype SSD', |
| 183 |
'echo "===spaceFC==="', |
| 184 |
'showsys -space -devtype FC', |
| 185 |
'echo "===spaceNL==="', |
| 186 |
'showsys -space -devtype NL' |
| 187 |
] |
| 188 |
); |
| 189 |
|
| 190 |
$self->{storages} = {}; |
| 191 |
while ($content =~ /(===space(.*?)=.*?)(?====space|\Z$)/msig) { |
| 192 |
my ($type, $entry) = ($2, $1); |
| 193 |
|
| 194 |
next if (defined($self->{option_results}->{filter_type}) && $self->{option_results}->{filter_type} ne '' && |
| 195 |
$type !~ /$self->{option_results}->{filter_type}/); |
| 196 |
|
| 197 |
my ($total, $free, $allocated, $unavailable, $failed); |
| 198 |
$total = $1 * 1024 * 1024 if ($entry =~ /^Total\s+Capacity\s+:\s*(\d+)/m); |
| 199 |
$free = $1 * 1024 * 1024 if ($entry =~ /^ Free\s+:\s*(\d+)/m); |
| 200 |
$allocated = $1 * 1024 * 1024 if ($entry =~ /^ Allocated\s+:\s*(\d+)/m); |
| 201 |
$unavailable = $1 * 1024 * 1024 if ($entry =~ /^ Unavailable\s+:\s*(\d+)/m); |
| 202 |
$failed = $1 * 1024 * 1024 if ($entry =~ /^ Failed\s+:\s*(\d+)/m); |
| 203 |
|
| 204 |
next if (!defined($total) || $total == 0); |
| 205 |
|
| 206 |
$self->{storages}->{$type} = { |
| 207 |
type => $type, |
| 208 |
space => { |
| 209 |
total => $total, |
| 210 |
free => $free, |
| 211 |
used => $total - $free, |
| 212 |
prct_used => ($total - $free) * 100 / $total, |
| 213 |
prct_free => $free * 100 / $total, |
| 214 |
unavailable => $unavailable, |
| 215 |
failed => $failed |
| 216 |
}, |
| 217 |
efficiency => {} |
| 218 |
}; |
| 219 |
|
| 220 |
$self->{storages}->{$type}->{efficiency}->{compaction} = $1 if ($entry =~ /^Compaction\s+:\s*([0-9\.]+)/m); |
| 221 |
$self->{storages}->{$type}->{efficiency}->{dedup} = $1 if ($entry =~ /^Dedup\s+:\s*([0-9\.]+)/m); |
| 222 |
$self->{storages}->{$type}->{efficiency}->{compression} = $1 if ($entry =~ /^Compression\s+:\s*([0-9\.]+)/m); |
| 223 |
$self->{storages}->{$type}->{efficiency}->{data_reduction} = $1 if ($entry =~ /^Data\s+Reduction\s+:\s*([0-9\.]+)/m); |
| 224 |
$self->{storages}->{$type}->{efficiency}->{overprovisioning} = $1 if ($entry =~ /^Overprovisioning\s+:\s*([0-9\.]+)/m); |
| 225 |
|
| 226 |
} |
| 227 |
|
| 228 |
if (scalar(keys %{$self->{storages}}) <= 0) { |
| 229 |
$self->{output}->add_option_msg(short_msg => "Couldn't get storages information"); |
| 230 |
$self->{output}->option_exit(); |
| 231 |
} |
| 232 |
} |
| 233 |
|
| 234 |
1; |
| 235 |
|
| 236 |
__END__ |
| 237 |
|
| 238 |
=head1 MODE |
| 239 |
|
| 240 |
Check storage capacities. |
| 241 |
|
| 242 |
=over 8 |
| 243 |
|
| 244 |
=item B<--filter-type> |
| 245 |
|
| 246 |
Filter storages by type (can be a regexp). |
| 247 |
|
| 248 |
=item B<--warning-*> B<--critical-*> |
| 249 |
|
| 250 |
Thresholds. |
| 251 |
Can be: 'space-usage', 'space-usage-free', 'space-usage-prct', |
| 252 |
'space-unavailable', 'space-failed', |
| 253 |
'compaction', 'dedup', 'compression', 'data-reduction', 'overprovisioning'. |
| 254 |
|
| 255 |
=back |
| 256 |
|
| 257 |
=cut |