| 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::purestorage::flashblade::v2::restapi::mode::filesystems; |
| 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}); |
| 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 filesystem_long_output { |
| 43 |
my ($self, %options) = @_; |
| 44 |
|
| 45 |
return "checking filesystem '" . $options{instance_value}->{name} . "'"; |
| 46 |
} |
| 47 |
|
| 48 |
sub prefix_filesystem_output { |
| 49 |
my ($self, %options) = @_; |
| 50 |
|
| 51 |
return "Filesystem '" . $options{instance_value}->{name} . "' "; |
| 52 |
} |
| 53 |
|
| 54 |
sub set_counters { |
| 55 |
my ($self, %options) = @_; |
| 56 |
|
| 57 |
$self->{maps_counters_type} = [ |
| 58 |
{ |
| 59 |
name => 'filesystems', type => 3, cb_prefix_output => 'prefix_filesystem_output', cb_long_output => 'filesystem_long_output', indent_long_output => ' ', |
| 60 |
message_multiple => 'All filesystems are ok', |
| 61 |
group => [ |
| 62 |
{ name => 'space', type => 0, skipped_code => { -10 => 1 } }, |
| 63 |
{ name => 'reduction', type => 0, skipped_code => { -10 => 1 } } |
| 64 |
] |
| 65 |
} |
| 66 |
]; |
| 67 |
|
| 68 |
$self->{maps_counters}->{space} = [ |
| 69 |
{ label => 'space-usage', nlabel => 'filesystem.space.usage.bytes', set => { |
| 70 |
key_values => [ { name => 'used' }, { name => 'free' }, { name => 'prct_used' }, { name => 'prct_free' }, { name => 'total' } ], |
| 71 |
closure_custom_output => $self->can('custom_usage_output'), |
| 72 |
perfdatas => [ |
| 73 |
{ template => '%d', min => 0, max => 'total', unit => 'B', cast_int => 1, label_extra_instance => 1 } |
| 74 |
] |
| 75 |
} |
| 76 |
}, |
| 77 |
{ label => 'space-usage-free', display_ok => 0, nlabel => 'filesystem.space.free.bytes', set => { |
| 78 |
key_values => [ { name => 'free' }, { name => 'used' }, { name => 'prct_used' }, { name => 'prct_free' }, { name => 'total' } ], |
| 79 |
closure_custom_output => $self->can('custom_usage_output'), |
| 80 |
perfdatas => [ |
| 81 |
{ template => '%d', min => 0, max => 'total', unit => 'B', cast_int => 1, label_extra_instance => 1 } |
| 82 |
] |
| 83 |
} |
| 84 |
}, |
| 85 |
{ label => 'space-usage-prct', display_ok => 0, nlabel => 'filesystem.space.usage.percentage', set => { |
| 86 |
key_values => [ { name => 'prct_used' }, { name => 'used' }, { name => 'free' }, { name => 'prct_free' }, { name => 'total' } ], |
| 87 |
closure_custom_output => $self->can('custom_usage_output'), |
| 88 |
perfdatas => [ |
| 89 |
{ template => '%.2f', min => 0, max => 100, unit => '%', label_extra_instance => 1 } |
| 90 |
] |
| 91 |
} |
| 92 |
} |
| 93 |
]; |
| 94 |
|
| 95 |
$self->{maps_counters}->{reduction} = [ |
| 96 |
{ label => 'data-reduction', nlabel => 'filesystem.data.reduction.count', set => { |
| 97 |
key_values => [ { name => 'data' } ], |
| 98 |
output_template => 'data reduction: %.3f', |
| 99 |
perfdatas => [ |
| 100 |
{ template => '%.3f', min => 0, label_extra_instance => 1 } |
| 101 |
] |
| 102 |
} |
| 103 |
} |
| 104 |
]; |
| 105 |
} |
| 106 |
|
| 107 |
sub new { |
| 108 |
my ($class, %options) = @_; |
| 109 |
my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1); |
| 110 |
bless $self, $class; |
| 111 |
|
| 112 |
$options{options}->add_options(arguments => { |
| 113 |
'filter-id:s' => { name => 'filter_id' }, |
| 114 |
'filter-name:s' => { name => 'filter_name' } |
| 115 |
}); |
| 116 |
|
| 117 |
return $self; |
| 118 |
} |
| 119 |
|
| 120 |
sub manage_selection { |
| 121 |
my ($self, %options) = @_; |
| 122 |
|
| 123 |
my $items = $options{custom}->request(endpoint => '/file-systems'); |
| 124 |
|
| 125 |
$self->{filesystems} = {}; |
| 126 |
foreach my $item (@$items) { |
| 127 |
next if (defined($self->{option_results}->{filter_id}) && $self->{option_results}->{filter_id} ne '' && |
| 128 |
$item->{id} !~ /$self->{option_results}->{filter_id}/); |
| 129 |
next if (defined($self->{option_results}->{filter_name}) && $self->{option_results}->{filter_name} ne '' && |
| 130 |
$item->{name} !~ /$self->{option_results}->{filter_name}/); |
| 131 |
|
| 132 |
$self->{filesystems}->{ $item->{name} } = { |
| 133 |
name => $item->{name}, |
| 134 |
reduction => { |
| 135 |
data => $item->{space}->{data_reduction} |
| 136 |
}, |
| 137 |
space => { |
| 138 |
total => $item->{provisioned}, |
| 139 |
used => $item->{space}->{virtual}, |
| 140 |
free => $item->{provisioned} - $item->{space}->{virtual}, |
| 141 |
prct_used => $item->{space}->{virtual} * 100 / $item->{provisioned}, |
| 142 |
prct_free => (100 - ($item->{space}->{virtual} * 100 / $item->{provisioned})) |
| 143 |
} |
| 144 |
}; |
| 145 |
} |
| 146 |
} |
| 147 |
|
| 148 |
1; |
| 149 |
|
| 150 |
__END__ |
| 151 |
|
| 152 |
=head1 MODE |
| 153 |
|
| 154 |
Check filesystems. |
| 155 |
|
| 156 |
=over 8 |
| 157 |
|
| 158 |
=item B<--filter-counters> |
| 159 |
|
| 160 |
Only display some counters (regexp can be used). |
| 161 |
Example: --filter-counters='data-reduction' |
| 162 |
|
| 163 |
=item B<--filter-id> |
| 164 |
|
| 165 |
Filter filesystems by ID (can be a regexp). |
| 166 |
|
| 167 |
=item B<--filter-name> |
| 168 |
|
| 169 |
Filter filesystems by name (can be a regexp). |
| 170 |
|
| 171 |
=item B<--warning-*> B<--critical-*> |
| 172 |
|
| 173 |
Thresholds. |
| 174 |
Can be: 'space-usage' (B), 'space-usage-free' (B), 'space-usage-prct' (%), |
| 175 |
'data-reduction'. |
| 176 |
|
| 177 |
=back |
| 178 |
|
| 179 |
=cut |