| 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::storagesystems; |
| 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 |
'status: %s', |
| 34 |
$self->{result_values}->{status} |
| 35 |
); |
| 36 |
} |
| 37 |
|
| 38 |
sub custom_usage_output { |
| 39 |
my ($self, %options) = @_; |
| 40 |
|
| 41 |
my ($total_size_value, $total_size_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{total_space}); |
| 42 |
my ($total_used_value, $total_used_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{used_space}); |
| 43 |
my ($total_free_value, $total_free_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{free_space}); |
| 44 |
my $msg = sprintf( |
| 45 |
'space usage total: %s used: %s (%.2f%%) free: %s (%.2f%%)', |
| 46 |
$total_size_value . " " . $total_size_unit, |
| 47 |
$total_used_value . " " . $total_used_unit, $self->{result_values}->{prct_used_space}, |
| 48 |
$total_free_value . " " . $total_free_unit, $self->{result_values}->{prct_free_space} |
| 49 |
); |
| 50 |
return $msg; |
| 51 |
} |
| 52 |
|
| 53 |
sub prefix_ss_output { |
| 54 |
my ($self, %options) = @_; |
| 55 |
|
| 56 |
return "storage system '" . $options{instance_value}->{display} . "' "; |
| 57 |
} |
| 58 |
|
| 59 |
sub set_counters { |
| 60 |
my ($self, %options) = @_; |
| 61 |
|
| 62 |
$self->{maps_counters_type} = [ |
| 63 |
{ name => 'ss', type => 1, cb_prefix_output => 'prefix_ss_output', message_multiple => 'All storage systems are ok' } |
| 64 |
]; |
| 65 |
|
| 66 |
$self->{maps_counters}->{ss} = [ |
| 67 |
{ label => 'status', type => 2, critical_default => '%{status} =~ /needsAttn/i', set => { |
| 68 |
key_values => [ { name => 'status' }, { name => 'display' } ], |
| 69 |
closure_custom_output => $self->can('custom_status_output'), |
| 70 |
closure_custom_perfdata => sub { return 0; }, |
| 71 |
closure_custom_threshold_check => \&catalog_status_threshold_ng |
| 72 |
} |
| 73 |
}, |
| 74 |
{ label => 'usage', nlabel => 'pool.space.usage.bytes', set => { |
| 75 |
key_values => [ { name => 'used_space' }, { name => 'free_space' }, { name => 'prct_used_space' }, { name => 'prct_free_space' }, { name => 'total_space' }, { name => 'display' }, ], |
| 76 |
closure_custom_output => $self->can('custom_usage_output'), |
| 77 |
perfdatas => [ |
| 78 |
{ value => 'used_space', template => '%d', min => 0, max => 'total_space', |
| 79 |
unit => 'B', cast_int => 1, label_extra_instance => 1 } |
| 80 |
] |
| 81 |
} |
| 82 |
}, |
| 83 |
{ label => 'usage-free', nlabel => 'pool.space.free.bytes', display_ok => 0, set => { |
| 84 |
key_values => [ { name => 'free_space' }, { name => 'used_space' }, { name => 'prct_used_space' }, { name => 'prct_free_space' }, { name => 'total_space' }, { name => 'display' }, ], |
| 85 |
closure_custom_output => $self->can('custom_usage_output'), |
| 86 |
perfdatas => [ |
| 87 |
{ value => 'free_space', template => '%d', min => 0, max => 'total_space', |
| 88 |
unit => 'B', cast_int => 1, label_extra_instance => 1 } |
| 89 |
] |
| 90 |
} |
| 91 |
}, |
| 92 |
{ label => 'usage-prct', nlabel => 'pool.space.usage.percentage', display_ok => 0, set => { |
| 93 |
key_values => [ { name => 'prct_used_space' }, { name => 'display' } ], |
| 94 |
output_template => 'used : %.2f %%', |
| 95 |
perfdatas => [ |
| 96 |
{ value => 'prct_used_space', template => '%.2f', min => 0, max => 100, |
| 97 |
unit => '%', label_extra_instance => 1 } |
| 98 |
] |
| 99 |
} |
| 100 |
} |
| 101 |
]; |
| 102 |
} |
| 103 |
|
| 104 |
sub new { |
| 105 |
my ($class, %options) = @_; |
| 106 |
my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1); |
| 107 |
bless $self, $class; |
| 108 |
|
| 109 |
$options{options}->add_options(arguments => { |
| 110 |
'filter-storage-name:s' => { name => 'filter_storage_name' } |
| 111 |
}); |
| 112 |
|
| 113 |
return $self; |
| 114 |
} |
| 115 |
|
| 116 |
sub manage_selection { |
| 117 |
my ($self, %options) = @_; |
| 118 |
|
| 119 |
my $results = $options{custom}->execute_storages_request(); |
| 120 |
|
| 121 |
$self->{ss} = {}; |
| 122 |
foreach (@{$results->{storages}}) { |
| 123 |
my $storage_name = $_->{name}; |
| 124 |
|
| 125 |
next if (defined($options{filter_storage_name}) && $options{filter_storage_name} ne '' && |
| 126 |
$storage_name !~ /$options{filter_storage_name}/); |
| 127 |
|
| 128 |
$self->{ss}->{$storage_name} = { |
| 129 |
display => $_->{name}, |
| 130 |
status => $_->{status}, |
| 131 |
total_space => $_->{usedPoolSpace} + $_->{freePoolSpace}, |
| 132 |
used_space => $_->{usedPoolSpace}, |
| 133 |
free_space => $_->{freePoolSpace}, |
| 134 |
prct_used_space => |
| 135 |
($_->{usedPoolSpace} * 100 / ($_->{usedPoolSpace} + $_->{freePoolSpace})), |
| 136 |
prct_free_space => |
| 137 |
($_->{freePoolSpace} * 100 / ($_->{usedPoolSpace} + $_->{freePoolSpace})) |
| 138 |
}; |
| 139 |
} |
| 140 |
} |
| 141 |
|
| 142 |
1; |
| 143 |
|
| 144 |
__END__ |
| 145 |
|
| 146 |
=head1 MODE |
| 147 |
|
| 148 |
Check storage systems. |
| 149 |
|
| 150 |
=over 8 |
| 151 |
|
| 152 |
=item B<--filter-counters> |
| 153 |
|
| 154 |
Only display some counters (regexp can be used). |
| 155 |
Example: --filter-counters='status' |
| 156 |
|
| 157 |
=item B<--filter-storage-name> |
| 158 |
|
| 159 |
Filter storage name (can be a regexp). |
| 160 |
|
| 161 |
=item B<--unknown-status> |
| 162 |
|
| 163 |
Define the conditions to match for the status to be UNKNOWN. |
| 164 |
You can use the following variables: %{status}, %{state}, %{display} |
| 165 |
|
| 166 |
=item B<--warning-status> |
| 167 |
|
| 168 |
Define the conditions to match for the status to be WARNING. |
| 169 |
You can use the following variables: %{status}, %{display} |
| 170 |
|
| 171 |
=item B<--critical-status> |
| 172 |
|
| 173 |
Define the conditions to match for the status to be CRITICAL (default: '%{status} =~ /needsAttn/i'). |
| 174 |
You can use the following variables: %{status}, %{display} |
| 175 |
|
| 176 |
=item B<--warning-*> B<--critical-*> |
| 177 |
|
| 178 |
Thresholds. |
| 179 |
Can be: 'usage' (B), 'usage-free' (B), 'usage-prct' (%). |
| 180 |
|
| 181 |
=back |
| 182 |
|
| 183 |
=cut |