| 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::huawei::oceanstor::snmp::mode::storagepools; |
| 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 |
use storage::huawei::oceanstor::snmp::mode::resources qw($health_status $running_status); |
| 29 |
|
| 30 |
sub custom_status_output { |
| 31 |
my ($self, %options) = @_; |
| 32 |
|
| 33 |
return sprintf( |
| 34 |
'health status: %s [running status: %s]', |
| 35 |
$self->{result_values}->{health_status}, |
| 36 |
$self->{result_values}->{running_status} |
| 37 |
); |
| 38 |
} |
| 39 |
|
| 40 |
sub custom_space_usage_output { |
| 41 |
my ($self, %options) = @_; |
| 42 |
|
| 43 |
my ($total_size_value, $total_size_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{total_space}); |
| 44 |
my ($total_used_value, $total_used_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{used_space}); |
| 45 |
my ($total_free_value, $total_free_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{free_space}); |
| 46 |
return sprintf( |
| 47 |
'space usage total: %s used: %s (%.2f%%) free: %s (%.2f%%)', |
| 48 |
$total_size_value . " " . $total_size_unit, |
| 49 |
$total_used_value . " " . $total_used_unit, $self->{result_values}->{prct_used_space}, |
| 50 |
$total_free_value . " " . $total_free_unit, $self->{result_values}->{prct_free_space} |
| 51 |
); |
| 52 |
} |
| 53 |
|
| 54 |
sub sp_long_output { |
| 55 |
my ($self, %options) = @_; |
| 56 |
|
| 57 |
return sprintf( |
| 58 |
"checking storage pool '%s' [domain: %s]", |
| 59 |
$options{instance_value}->{name}, |
| 60 |
$options{instance_value}->{domain_name} |
| 61 |
); |
| 62 |
} |
| 63 |
|
| 64 |
sub prefix_sp_output { |
| 65 |
my ($self, %options) = @_; |
| 66 |
|
| 67 |
return sprintf( |
| 68 |
"storage pool '%s' [domain: %s] ", |
| 69 |
$options{instance_value}->{name}, |
| 70 |
$options{instance_value}->{domain_name} |
| 71 |
); |
| 72 |
} |
| 73 |
|
| 74 |
sub set_counters { |
| 75 |
my ($self, %options) = @_; |
| 76 |
|
| 77 |
$self->{maps_counters_type} = [ |
| 78 |
{ name => 'sp', type => 3, cb_prefix_output => 'prefix_sp_output', cb_long_output => 'sp_long_output', |
| 79 |
indent_long_output => ' ', message_multiple => 'All storage pools are ok', |
| 80 |
group => [ |
| 81 |
{ name => 'status', type => 0, skipped_code => { -10 => 1 } }, |
| 82 |
{ name => 'space', type => 0, skipped_code => { -10 => 1 } } |
| 83 |
] |
| 84 |
} |
| 85 |
]; |
| 86 |
|
| 87 |
$self->{maps_counters}->{status} = [ |
| 88 |
{ |
| 89 |
label => 'status', |
| 90 |
type => 2, |
| 91 |
warning_default => '%{health_status} =~ /degraded|partially broken/i', |
| 92 |
critical_default => '%{health_status} =~ /fault|fail/i', |
| 93 |
set => { |
| 94 |
key_values => [ { name => 'health_status' }, { name => 'running_status' }, { name => 'id' } ], |
| 95 |
closure_custom_output => $self->can('custom_status_output'), |
| 96 |
closure_custom_perfdata => sub { return 0; }, |
| 97 |
closure_custom_threshold_check => \&catalog_status_threshold_ng |
| 98 |
} |
| 99 |
} |
| 100 |
]; |
| 101 |
|
| 102 |
$self->{maps_counters}->{space} = [ |
| 103 |
{ label => 'space-usage', nlabel => 'storage_pool.space.usage.bytes', set => { |
| 104 |
key_values => [ { name => 'used_space' }, { name => 'free_space' }, { name => 'prct_used_space' }, { name => 'prct_free_space' }, { name => 'total_space' } ], |
| 105 |
closure_custom_output => $self->can('custom_space_usage_output'), |
| 106 |
perfdatas => [ |
| 107 |
{ template => '%d', min => 0, max => 'total_space', unit => 'B', cast_int => 1, label_extra_instance => 1 } |
| 108 |
] |
| 109 |
} |
| 110 |
}, |
| 111 |
{ label => 'space-usage-free', nlabel => 'storage_pool.space.free.bytes', display_ok => 0, set => { |
| 112 |
key_values => [ { name => 'free_space' }, { name => 'used_space' }, { name => 'prct_used_space' }, { name => 'prct_free_space' }, { name => 'total_space' } ], |
| 113 |
closure_custom_output => $self->can('custom_space_usage_output'), |
| 114 |
perfdatas => [ |
| 115 |
{ template => '%d', min => 0, max => 'total_space', unit => 'B', cast_int => 1, label_extra_instance => 1 } |
| 116 |
] |
| 117 |
} |
| 118 |
}, |
| 119 |
{ label => 'space-usage-prct', nlabel => 'storage_pool.space.usage.percentage', display_ok => 0, set => { |
| 120 |
key_values => [ { name => 'prct_used_space' }, { name => 'used_space' }, { name => 'free_space' }, { name => 'prct_free_space' }, { name => 'total_space' } ], |
| 121 |
closure_custom_output => $self->can('custom_space_usage_output'), |
| 122 |
perfdatas => [ |
| 123 |
{ template => '%.2f', min => 0, max => 100, unit => '%', label_extra_instance => 1 } |
| 124 |
] |
| 125 |
} |
| 126 |
} |
| 127 |
]; |
| 128 |
} |
| 129 |
|
| 130 |
sub new { |
| 131 |
my ($class, %options) = @_; |
| 132 |
my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1); |
| 133 |
bless $self, $class; |
| 134 |
|
| 135 |
$options{options}->add_options(arguments => { |
| 136 |
'filter-name:s' => { name => 'filter_name' }, |
| 137 |
'filter-domain-name:s' => { name => 'filter_domain_name' } |
| 138 |
}); |
| 139 |
|
| 140 |
return $self; |
| 141 |
} |
| 142 |
|
| 143 |
my $mapping = { |
| 144 |
domain_name => { oid => '.1.3.6.1.4.1.34774.4.1.23.4.2.1.4' }, # hwInfoStoragePoolDiskDomainName |
| 145 |
health_status => { oid => '.1.3.6.1.4.1.34774.4.1.23.4.2.1.5', map => $health_status }, # hwInfoStoragePoolHealthStatus |
| 146 |
running_status => { oid => '.1.3.6.1.4.1.34774.4.1.23.4.2.1.6', map => $running_status }, # hwInfoStoragePoolRunningStatus |
| 147 |
total_space => { oid => '.1.3.6.1.4.1.34774.4.1.23.4.2.1.7' }, # hwInfoStoragePoolTotalCapacity (MB) |
| 148 |
free_space => { oid => '.1.3.6.1.4.1.34774.4.1.23.4.2.1.9' } # hwInfoStoragePoolFreeCapacity (MB) |
| 149 |
}; |
| 150 |
|
| 151 |
sub manage_selection { |
| 152 |
my ($self, %options) = @_; |
| 153 |
|
| 154 |
if ($options{snmp}->is_snmpv1()) { |
| 155 |
$self->{output}->add_option_msg(short_msg => "Need to use SNMP v2c or v3."); |
| 156 |
$self->{output}->option_exit(); |
| 157 |
} |
| 158 |
|
| 159 |
my $oid_sp_name = '.1.3.6.1.4.1.34774.4.1.23.4.2.1.2'; # hwInfoStoragePoolName |
| 160 |
my $snmp_result = $options{snmp}->get_table( |
| 161 |
oid => $oid_sp_name, |
| 162 |
nothing_quit => 1 |
| 163 |
); |
| 164 |
|
| 165 |
$self->{sp} = {}; |
| 166 |
foreach (keys %$snmp_result) { |
| 167 |
/^$oid_sp_name\.(.*)$/; |
| 168 |
my $instance = $1; |
| 169 |
|
| 170 |
if (defined($self->{option_results}->{filter_name}) && $self->{option_results}->{filter_name} ne '' && |
| 171 |
$snmp_result->{$_} !~ /$self->{option_results}->{filter_name}/) { |
| 172 |
$self->{output}->output_add(long_msg => "skipping storage pool '" . $snmp_result->{$_} . "'.", debug => 1); |
| 173 |
next; |
| 174 |
} |
| 175 |
|
| 176 |
$self->{sp}->{ $snmp_result->{$_} } = { |
| 177 |
name => $snmp_result->{$_}, |
| 178 |
instance => $instance |
| 179 |
}; |
| 180 |
} |
| 181 |
|
| 182 |
return if (scalar(keys %{$self->{sp}}) <= 0); |
| 183 |
|
| 184 |
$options{snmp}->load( |
| 185 |
oids => [ map($_->{oid}, values(%$mapping)) ], |
| 186 |
instances => [ map($_->{instance}, values(%{$self->{sp}})) ], |
| 187 |
instance_regexp => '^(.*)$' |
| 188 |
); |
| 189 |
$snmp_result = $options{snmp}->get_leef(); |
| 190 |
foreach (keys %{$self->{sp}}) { |
| 191 |
my $result = $options{snmp}->map_instance(mapping => $mapping, results => $snmp_result, instance => $self->{sp}->{$_}->{instance}); |
| 192 |
|
| 193 |
if (defined($self->{option_results}->{filter_domain_name}) && $self->{option_results}->{filter_domain_name} ne '' && |
| 194 |
$result->{domain_name} !~ /$self->{option_results}->{filter_domain_name}/) { |
| 195 |
$self->{output}->output_add(long_msg => "skipping storage pool '" . $_ . "'.", debug => 1); |
| 196 |
next; |
| 197 |
} |
| 198 |
|
| 199 |
$self->{sp}->{$_}->{domain_name} = $result->{domain_name}; |
| 200 |
$result->{total_space} *= 1024 * 1024; |
| 201 |
$result->{free_space} *= 1024 * 1024; |
| 202 |
$self->{sp}->{$_}->{space} = { |
| 203 |
name => $_, |
| 204 |
total_space => $result->{total_space}, |
| 205 |
used_space => $result->{total_space} - $result->{free_space}, |
| 206 |
free_space => $result->{free_space}, |
| 207 |
prct_used_space => 100 - ($result->{free_space} * 100 / $result->{total_space}), |
| 208 |
prct_free_space => ($result->{free_space} * 100 / $result->{total_space}) |
| 209 |
}; |
| 210 |
$self->{sp}->{$_}->{status} = { |
| 211 |
running_status => $result->{running_status}, |
| 212 |
health_status => $result->{health_status}, |
| 213 |
name => $_, |
| 214 |
domain_name => $result->{domain_name} |
| 215 |
}; |
| 216 |
} |
| 217 |
} |
| 218 |
|
| 219 |
1; |
| 220 |
|
| 221 |
__END__ |
| 222 |
|
| 223 |
=head1 MODE |
| 224 |
|
| 225 |
Check storage pools. |
| 226 |
|
| 227 |
=over 8 |
| 228 |
|
| 229 |
=item B<--filter-name> |
| 230 |
|
| 231 |
Filter storage pool by name (can be a regexp). |
| 232 |
|
| 233 |
=item B<--filter-domain-name> |
| 234 |
|
| 235 |
Filter storage pool by domain name (can be a regexp). |
| 236 |
|
| 237 |
=item B<--unknown-status> |
| 238 |
|
| 239 |
Define the conditions to match for the status to be UNKNOWN. |
| 240 |
You can use the following variables: %{health_status}, %{running_status}, %{name} |
| 241 |
|
| 242 |
=item B<--warning-status> |
| 243 |
|
| 244 |
Define the conditions to match for the status to be WARNING (default: '%{health_status} =~ /degraded|partially broken/i'). |
| 245 |
You can use the following variables: %{health_status}, %{running_status}, %{name} |
| 246 |
|
| 247 |
=item B<--critical-status> |
| 248 |
|
| 249 |
Define the conditions to match for the status to be CRITICAL (default: '%{health_status} =~ /fault|fail/i'). |
| 250 |
You can use the following variables: %{health_status}, %{running_status}, %{name} |
| 251 |
|
| 252 |
=item B<--warning-*> B<--critical-*> |
| 253 |
|
| 254 |
Thresholds. |
| 255 |
Can be: 'space-usage', 'space-usage-free', 'space-usage-prct'. |
| 256 |
|
| 257 |
=back |
| 258 |
|
| 259 |
=cut |