| 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::afc; |
| 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_space_usage_output { |
| 30 |
my ($self, %options) = @_; |
| 31 |
|
| 32 |
my ($total_size_value, $total_size_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{total}); |
| 33 |
my ($total_used_value, $total_used_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{used}); |
| 34 |
my ($total_free_value, $total_free_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{free}); |
| 35 |
return sprintf( |
| 36 |
'space usage total: %s used: %s (%.2f%%) free: %s (%.2f%%)', |
| 37 |
$total_size_value . " " . $total_size_unit, |
| 38 |
$total_used_value . " " . $total_used_unit, $self->{result_values}->{prct_used}, |
| 39 |
$total_free_value . " " . $total_free_unit, $self->{result_values}->{prct_free} |
| 40 |
); |
| 41 |
} |
| 42 |
|
| 43 |
sub node_long_output { |
| 44 |
my ($self, %options) = @_; |
| 45 |
|
| 46 |
return sprintf( |
| 47 |
"checking node '%s' afc", |
| 48 |
$options{instance_value}->{node_id} |
| 49 |
); |
| 50 |
} |
| 51 |
|
| 52 |
sub prefix_node_output { |
| 53 |
my ($self, %options) = @_; |
| 54 |
|
| 55 |
return sprintf( |
| 56 |
"node '%s' afc ", |
| 57 |
$options{instance_value}->{node_id} |
| 58 |
); |
| 59 |
} |
| 60 |
|
| 61 |
sub volume_long_output { |
| 62 |
my ($self, %options) = @_; |
| 63 |
|
| 64 |
return sprintf( |
| 65 |
"checking volume '%s' afc", |
| 66 |
$options{instance_value}->{volume_name} |
| 67 |
); |
| 68 |
} |
| 69 |
|
| 70 |
sub prefix_volume_output { |
| 71 |
my ($self, %options) = @_; |
| 72 |
|
| 73 |
return sprintf( |
| 74 |
"volume '%s' afc ", |
| 75 |
$options{instance_value}->{volume_name} |
| 76 |
); |
| 77 |
} |
| 78 |
|
| 79 |
sub set_counters { |
| 80 |
my ($self, %options) = @_; |
| 81 |
|
| 82 |
$self->{maps_counters_type} = [ |
| 83 |
{ |
| 84 |
name => 'nodes', type => 3, cb_prefix_output => 'prefix_node_output', cb_long_output => 'node_long_output', indent_long_output => ' ', message_multiple => 'All nodes afc are ok', |
| 85 |
group => [ |
| 86 |
{ name => 'global', type => 0 }, |
| 87 |
{ name => 'space', type => 0 }, |
| 88 |
{ name => 'node_fmp', type => 0 } |
| 89 |
] |
| 90 |
}, |
| 91 |
{ |
| 92 |
name => 'volumes', type => 3, cb_prefix_output => 'prefix_volume_output', cb_long_output => 'volume_long_output', indent_long_output => ' ', message_multiple => 'All volumes afc are ok', |
| 93 |
group => [ |
| 94 |
{ name => 'volume_fmp', type => 0 } |
| 95 |
] |
| 96 |
} |
| 97 |
]; |
| 98 |
|
| 99 |
$self->{maps_counters}->{global} = [ |
| 100 |
{ |
| 101 |
label => 'status', |
| 102 |
type => 2, |
| 103 |
critical_default => '%{status} !~ /normal/i', |
| 104 |
set => { |
| 105 |
key_values => [ { name => 'status' }, { name => 'node_id' } ], |
| 106 |
output_template => 'status: %s', |
| 107 |
closure_custom_perfdata => sub { return 0; }, |
| 108 |
closure_custom_threshold_check => \&catalog_status_threshold_ng |
| 109 |
} |
| 110 |
} |
| 111 |
]; |
| 112 |
|
| 113 |
$self->{maps_counters}->{space} = [ |
| 114 |
{ label => 'flashcache-usage', nlabel => 'node.flashcache.usage.bytes', set => { |
| 115 |
key_values => [ { name => 'used' }, { name => 'free' }, { name => 'prct_used' }, { name => 'prct_free' }, { name => 'total' } ], |
| 116 |
closure_custom_output => $self->can('custom_space_usage_output'), |
| 117 |
perfdatas => [ |
| 118 |
{ template => '%d', min => 0, max => 'total', unit => 'B', cast_int => 1, label_extra_instance => 1 } |
| 119 |
] |
| 120 |
} |
| 121 |
}, |
| 122 |
{ label => 'flashcache-usage-free', nlabel => 'node.flashcache.free.bytes', display_ok => 0, set => { |
| 123 |
key_values => [ { name => 'free' }, { name => 'used' }, { name => 'prct_used' }, { name => 'prct_free' }, { name => 'total' } ], |
| 124 |
closure_custom_output => $self->can('custom_space_usage_output'), |
| 125 |
perfdatas => [ |
| 126 |
{ template => '%d', min => 0, max => 'total', unit => 'B', cast_int => 1, label_extra_instance => 1 } |
| 127 |
] |
| 128 |
} |
| 129 |
}, |
| 130 |
{ label => 'flashcache-usage-prct', nlabel => 'node.flashcache.usage.percentage', display_ok => 0, set => { |
| 131 |
key_values => [ { name => 'prct_used' }, { name => 'used' }, { name => 'free' }, { name => 'prct_free' }, { name => 'total' } ], |
| 132 |
closure_custom_output => $self->can('custom_space_usage_output'), |
| 133 |
perfdatas => [ |
| 134 |
{ template => '%.2f', min => 0, max => 100, unit => '%', label_extra_instance => 1 } |
| 135 |
] |
| 136 |
} |
| 137 |
} |
| 138 |
]; |
| 139 |
|
| 140 |
$self->{maps_counters}->{node_fmp} = [ |
| 141 |
{ label => 'flashcache-node-readhits', nlabel => 'node.flashcache.readhits.percentage', set => { |
| 142 |
key_values => [ { name => 'readhits' } ], |
| 143 |
output_template => 'read hits: %s%%', |
| 144 |
perfdatas => [ |
| 145 |
{ template => '%s', min => 0, max => 100, unit => '%', label_extra_instance => 1 } |
| 146 |
] |
| 147 |
} |
| 148 |
} |
| 149 |
]; |
| 150 |
|
| 151 |
$self->{maps_counters}->{volume_fmp} = [ |
| 152 |
{ label => 'flashcache-volume-readhits', nlabel => 'volume.flashcache.readhits.percentage', set => { |
| 153 |
key_values => [ { name => 'readhits' } ], |
| 154 |
output_template => 'read hits: %s%%', |
| 155 |
perfdatas => [ |
| 156 |
{ template => '%s', min => 0, max => 100, unit => '%', label_extra_instance => 1 } |
| 157 |
] |
| 158 |
} |
| 159 |
} |
| 160 |
]; |
| 161 |
} |
| 162 |
|
| 163 |
sub new { |
| 164 |
my ($class, %options) = @_; |
| 165 |
my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1); |
| 166 |
bless $self, $class; |
| 167 |
|
| 168 |
$options{options}->add_options(arguments => { |
| 169 |
'filter-node-id:s' => { name => 'filter_node_id' }, |
| 170 |
'filter-volume-name:s' => { name => 'filter_volume_name' } |
| 171 |
}); |
| 172 |
|
| 173 |
return $self; |
| 174 |
} |
| 175 |
|
| 176 |
sub manage_selection { |
| 177 |
my ($self, %options) = @_; |
| 178 |
|
| 179 |
my ($content) = $options{custom}->execute_command( |
| 180 |
commands => [ |
| 181 |
'echo "===showflashcache==="', |
| 182 |
'showflashcache', |
| 183 |
'echo "===statcachenode==="', |
| 184 |
'statcache -iter 1 -d 1', |
| 185 |
'echo "===statcachevolume==="', |
| 186 |
'statcache -iter 1 -d 1 -v' |
| 187 |
] |
| 188 |
); |
| 189 |
|
| 190 |
#Node Mode State Size Used% |
| 191 |
# 0 SSD normal 393216 49 |
| 192 |
# 1 SSD normal 393216 49 |
| 193 |
|
| 194 |
$self->{nodes} = {}; |
| 195 |
if ($content =~ /===showflashcache===(.*?)(?====|\Z$)/msi) { |
| 196 |
my $entry = $1; |
| 197 |
while ($entry =~ /^\s*(\d+)\s+\S+\s+(\S+)\s+(\S+)\s+(\S+)/mg) { |
| 198 |
my ($node_id, $status, $size, $prct_used) = ($1, $2, $3 * 1024 * 1024, $4); |
| 199 |
|
| 200 |
next if (defined($self->{option_results}->{filter_node_id}) && $self->{option_results}->{filter_node_id} ne '' && |
| 201 |
$node_id !~ /$self->{option_results}->{filter_node_id}/); |
| 202 |
|
| 203 |
$self->{nodes}->{'node' . $node_id} = { |
| 204 |
node_id => $node_id, |
| 205 |
global => { |
| 206 |
node_id => $node_id, |
| 207 |
status => $status |
| 208 |
}, |
| 209 |
space => { |
| 210 |
total => $size, |
| 211 |
used => $prct_used * $size / 100, |
| 212 |
free => $size - ($prct_used * $size / 100), |
| 213 |
prct_used => $prct_used, |
| 214 |
prct_free => 100 - $prct_used |
| 215 |
} |
| 216 |
}; |
| 217 |
} |
| 218 |
} |
| 219 |
|
| 220 |
if ($content =~ /===statcachenode===(.*?)(?====|\Z$)/msi) { |
| 221 |
my $entry = $1; |
| 222 |
if ($entry =~ /CMP\s+FMP\s+Total(.*?)Internal\s+Flashcache\s+Activity/ms) { |
| 223 |
my $stat = $1; |
| 224 |
while ($stat =~ /^\s*(\d+)\s+Read\s+\d+\s+\d+\s+(\d+)/mg) { |
| 225 |
my ($node_id, $readhits) = ($1, $2); |
| 226 |
next if (!defined($self->{nodes}->{'node' . $node_id})); |
| 227 |
$self->{nodes}->{'node' . $node_id}->{node_fmp} = { readhits => $readhits }; |
| 228 |
} |
| 229 |
} |
| 230 |
} |
| 231 |
|
| 232 |
$self->{volumes} = {}; |
| 233 |
if ($content =~ /===statcachevolume===(.*?)(?====|\Z$)/msi) { |
| 234 |
my $entry = $1; |
| 235 |
if ($entry =~ /CMP\s+FMP\s+Total(.*?)Internal\s+Flashcache\s+Activity/ms) { |
| 236 |
my $stat = $1; |
| 237 |
while ($stat =~ /^\s*\d+\s+(\S+)\s+Read\s+\d+\s+\d+\s+(\d+)/mg) { |
| 238 |
my ($volume_name, $readhits) = ($1, $2); |
| 239 |
|
| 240 |
next if (defined($self->{option_results}->{filter_volume_name}) && $self->{option_results}->{filter_volume_name} ne '' && |
| 241 |
$volume_name !~ /$self->{option_results}->{filter_volume_name}/); |
| 242 |
|
| 243 |
$self->{volumes}->{$volume_name} = { |
| 244 |
volume_name => $volume_name, |
| 245 |
volume_fmp => { readhits => $readhits } |
| 246 |
}; |
| 247 |
} |
| 248 |
} |
| 249 |
} |
| 250 |
|
| 251 |
if (scalar(keys %{$self->{nodes}}) <= 0 && scalar(keys %{$self->{volumes}}) <= 0) { |
| 252 |
$self->{output}->add_option_msg(short_msg => "Couldn't get afc information"); |
| 253 |
$self->{output}->option_exit(); |
| 254 |
} |
| 255 |
} |
| 256 |
|
| 257 |
1; |
| 258 |
|
| 259 |
__END__ |
| 260 |
|
| 261 |
=head1 MODE |
| 262 |
|
| 263 |
Check adaptive flash cache. |
| 264 |
|
| 265 |
=over 8 |
| 266 |
|
| 267 |
=item B<--filter-node-id> |
| 268 |
|
| 269 |
Filter nodes by ID (can be a regexp). |
| 270 |
|
| 271 |
=item B<--filter-volume-name> |
| 272 |
|
| 273 |
Filter volumes by name (can be a regexp). |
| 274 |
|
| 275 |
=item B<--unknown-status> |
| 276 |
|
| 277 |
Define the conditions to match for the status to be UNKNOWN. |
| 278 |
|
| 279 |
=item B<--warning-status> |
| 280 |
|
| 281 |
Define the conditions to match for the status to be WARNING. |
| 282 |
|
| 283 |
=item B<--critical-status> |
| 284 |
|
| 285 |
Define the conditions to match for the status to be CRITICAL (default: '%{status} !~ /normal/i') |
| 286 |
You can use the following variables: %{status}, %{node_id} |
| 287 |
|
| 288 |
=item B<--warning-*> |
| 289 |
|
| 290 |
Define the WARNING thresholds for the following components: |
| 291 |
'flashcache-usage', 'flashcache-usage-free', 'flashcache-usage-prct', |
| 292 |
'flashcache-node-readhits', 'flashcache-volume-readhits'. |
| 293 |
|
| 294 |
=item B<--critical-*> |
| 295 |
|
| 296 |
Define the CRITICAL thresholds for the following components: |
| 297 |
'flashcache-usage', 'flashcache-usage-free', 'flashcache-usage-prct', |
| 298 |
'flashcache-node-readhits', 'flashcache-volume-readhits'. |
| 299 |
|
| 300 |
=back |
| 301 |
|
| 302 |
=cut |