| 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::celerra::local::mode::pools; |
| 22 |
|
| 23 |
use base qw(centreon::plugins::templates::counter); |
| 24 |
|
| 25 |
use strict; |
| 26 |
use warnings; |
| 27 |
|
| 28 |
sub custom_usage_output { |
| 29 |
my ($self, %options) = @_; |
| 30 |
|
| 31 |
my ($total_size_value, $total_size_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{total_space}); |
| 32 |
my ($total_used_value, $total_used_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{used_space}); |
| 33 |
my ($total_free_value, $total_free_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{free_space}); |
| 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_space}, |
| 38 |
$total_free_value . " " . $total_free_unit, $self->{result_values}->{prct_free_space} |
| 39 |
); |
| 40 |
} |
| 41 |
|
| 42 |
sub prefix_pool_output { |
| 43 |
my ($self, %options) = @_; |
| 44 |
|
| 45 |
return "Pool '" . $options{instance_value}->{name} . "' "; |
| 46 |
} |
| 47 |
|
| 48 |
sub set_counters { |
| 49 |
my ($self, %options) = @_; |
| 50 |
|
| 51 |
$self->{maps_counters_type} = [ |
| 52 |
{ name => 'pools', type => 1, cb_prefix_output => 'prefix_pool_output', message_multiple => 'All pools are ok', skipped_code => { -10 => 1 } } |
| 53 |
]; |
| 54 |
|
| 55 |
$self->{maps_counters}->{pools} = [ |
| 56 |
{ label => 'space-usage', nlabel => 'pool.space.usage.bytes', set => { |
| 57 |
key_values => [ { name => 'used_space' }, { name => 'free_space' }, { name => 'prct_used_space' }, { name => 'prct_free_space' }, { name => 'total_space' } ], |
| 58 |
closure_custom_output => $self->can('custom_usage_output'), |
| 59 |
perfdatas => [ |
| 60 |
{ template => '%d', min => 0, max => 'total_space', unit => 'B', cast_int => 1, label_extra_instance => 1 } |
| 61 |
] |
| 62 |
} |
| 63 |
}, |
| 64 |
{ label => 'space-usage-free', nlabel => 'pool.space.free.bytes', display_ok => 0, set => { |
| 65 |
key_values => [ { name => 'free_space' }, { name => 'used_space' }, { name => 'prct_used_space' }, { name => 'prct_free_space' }, { name => 'total_space' } ], |
| 66 |
closure_custom_output => $self->can('custom_usage_output'), |
| 67 |
perfdatas => [ |
| 68 |
{ template => '%d', min => 0, max => 'total_space', unit => 'B', cast_int => 1, label_extra_instance => 1 } |
| 69 |
] |
| 70 |
} |
| 71 |
}, |
| 72 |
{ label => 'space-usage-prct', nlabel => 'pool.space.usage.percentage', display_ok => 0, set => { |
| 73 |
key_values => [ { name => 'prct_used_space' }, { name => 'used_space' }, { name => 'free_space' }, { name => 'prct_free_space' }, { name => 'total_space' } ], |
| 74 |
closure_custom_output => $self->can('custom_usage_output'), |
| 75 |
perfdatas => [ |
| 76 |
{ template => '%.2f', min => 0, max => 100, unit => '%', label_extra_instance => 1 } |
| 77 |
] |
| 78 |
} |
| 79 |
} |
| 80 |
]; |
| 81 |
} |
| 82 |
|
| 83 |
sub new { |
| 84 |
my ($class, %options) = @_; |
| 85 |
my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1); |
| 86 |
bless $self, $class; |
| 87 |
|
| 88 |
$options{options}->add_options(arguments => { |
| 89 |
'filter-pool-name:s' => { name => 'filter_pool_name' } |
| 90 |
}); |
| 91 |
|
| 92 |
return $self; |
| 93 |
} |
| 94 |
|
| 95 |
sub manage_selection { |
| 96 |
my ($self, %options) = @_; |
| 97 |
|
| 98 |
my ($stdout) = $options{custom}->execute_command( |
| 99 |
command => 'NAS_DB=/nas /nas/bin/nas_pool -size -all', |
| 100 |
command_options => '2>&1', |
| 101 |
); |
| 102 |
|
| 103 |
$self->{pools} = {}; |
| 104 |
while ($stdout =~ /^(id\s+=\s.*?)(?=\nid|\Z$)/msg) { |
| 105 |
my $entry = $1; |
| 106 |
my $fields = {}; |
| 107 |
foreach (split(/\n/, $entry)) { |
| 108 |
next if (! /^(\S+)\s*=\s*(\S+)/); |
| 109 |
$fields->{$1} = $2; |
| 110 |
} |
| 111 |
|
| 112 |
next if ($fields->{total_mb} == 0); |
| 113 |
|
| 114 |
if (defined($self->{option_results}->{filter_pool_name}) && $self->{option_results}->{filter_pool_name} ne '' && |
| 115 |
$fields->{name} !~ /$self->{option_results}->{filter_pool_name}/) { |
| 116 |
$self->{output}->output_add(long_msg => "skipping pool '" . $fields->{name} . "': no matching filter.", debug => 1); |
| 117 |
next; |
| 118 |
} |
| 119 |
|
| 120 |
my $used_space = $fields->{used_mb} * 1024 * 1024; |
| 121 |
my $free_space = $fields->{avail_mb} * 1024 * 1024; |
| 122 |
my $total_space = $fields->{total_mb} * 1024 * 1024; |
| 123 |
my $potential_space = $fields->{potential_mb} * 1024 * 1024; |
| 124 |
$self->{pools}->{ $fields->{name} } = { |
| 125 |
name => $fields->{name}, |
| 126 |
total_space => $total_space + $potential_space, |
| 127 |
used_space => $used_space, |
| 128 |
free_space => $free_space + $potential_space, |
| 129 |
prct_used_space => $used_space * 100 / ($total_space + $potential_space), |
| 130 |
prct_free_space => 100 - ($used_space * 100 / ($total_space + $potential_space)) |
| 131 |
}; |
| 132 |
} |
| 133 |
} |
| 134 |
|
| 135 |
1; |
| 136 |
|
| 137 |
__END__ |
| 138 |
|
| 139 |
=head1 MODE |
| 140 |
|
| 141 |
Check pools. |
| 142 |
|
| 143 |
Command used: NAS_DB=/nas /nas/bin/nas_pool -size -all 2>&1 |
| 144 |
|
| 145 |
=over 8 |
| 146 |
|
| 147 |
=item B<--filter-counters> |
| 148 |
|
| 149 |
Only display some counters (regexp can be used). |
| 150 |
Example: --filter-counters='usage$' |
| 151 |
|
| 152 |
=item B<--filter-pool-name> |
| 153 |
|
| 154 |
Filter pools by pool name (can be a regexp). |
| 155 |
|
| 156 |
=item B<--warning-*> B<--critical-*> |
| 157 |
|
| 158 |
Thresholds. |
| 159 |
Can be: 'space-usage' (B), 'space-usage-free' (B), 'space-usage-prct' (%). |
| 160 |
|
| 161 |
=back |
| 162 |
|
| 163 |
=cut |