| 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::luns; |
| 22 |
|
| 23 |
use base qw(centreon::plugins::templates::counter); |
| 24 |
|
| 25 |
use strict; |
| 26 |
use warnings; |
| 27 |
|
| 28 |
sub custom_space_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 |
my ($total_prot_value, $total_prot_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{prot_space}); |
| 35 |
return sprintf( |
| 36 |
'space usage total: %s used: %s (%.2f%%) free: %s (%.2f%%) protection: %s', |
| 37 |
$total_size_value . " " . $total_size_unit, |
| 38 |
$total_used_value . " " . $total_used_unit, $self->{result_values}->{prct_used_space}, |
| 39 |
$total_free_value . " " . $total_free_unit, $self->{result_values}->{prct_free_space}, |
| 40 |
$total_prot_value . " " . $total_prot_unit |
| 41 |
); |
| 42 |
} |
| 43 |
|
| 44 |
sub lun_long_output { |
| 45 |
my ($self, %options) = @_; |
| 46 |
|
| 47 |
return sprintf( |
| 48 |
"checking LUN '%s' [sp: %s]", |
| 49 |
$options{instance_value}->{name}, |
| 50 |
$options{instance_value}->{storage_pool} |
| 51 |
); |
| 52 |
} |
| 53 |
|
| 54 |
sub prefix_lun_output { |
| 55 |
my ($self, %options) = @_; |
| 56 |
|
| 57 |
return sprintf( |
| 58 |
"LUN '%s' [sp: %s] ", |
| 59 |
$options{instance_value}->{name}, |
| 60 |
$options{instance_value}->{storage_pool} |
| 61 |
); |
| 62 |
} |
| 63 |
|
| 64 |
sub set_counters { |
| 65 |
my ($self, %options) = @_; |
| 66 |
|
| 67 |
$self->{maps_counters_type} = [ |
| 68 |
{ name => 'lun', type => 3, cb_prefix_output => 'prefix_lun_output', cb_long_output => 'lun_long_output', |
| 69 |
indent_long_output => ' ', message_multiple => 'All LUNs are ok', |
| 70 |
group => [ |
| 71 |
#{ name => 'status', type => 0, skipped_code => { -10 => 1 } }, |
| 72 |
{ name => 'space', type => 0, skipped_code => { -10 => 1 } } |
| 73 |
] |
| 74 |
} |
| 75 |
]; |
| 76 |
|
| 77 |
$self->{maps_counters}->{space} = [ |
| 78 |
{ label => 'space-usage', nlabel => 'lun.space.usage.bytes', set => { |
| 79 |
key_values => [ { name => 'used_space' }, { name => 'free_space' }, { name => 'prct_used_space' }, { name => 'prct_free_space' }, { name => 'total_space' }, { name => 'prot_space' } ], |
| 80 |
closure_custom_output => $self->can('custom_space_usage_output'), |
| 81 |
perfdatas => [ |
| 82 |
{ template => '%d', min => 0, max => 'total_space', unit => 'B', cast_int => 1, label_extra_instance => 1 } |
| 83 |
] |
| 84 |
} |
| 85 |
}, |
| 86 |
{ label => 'space-usage-free', nlabel => 'lun.space.free.bytes', display_ok => 0, set => { |
| 87 |
key_values => [ { name => 'free_space' }, { name => 'used_space' }, { name => 'prct_used_space' }, { name => 'prct_free_space' }, { name => 'total_space' }, { name => 'prot_space' } ], |
| 88 |
closure_custom_output => $self->can('custom_space_usage_output'), |
| 89 |
perfdatas => [ |
| 90 |
{ template => '%d', min => 0, max => 'total_space', unit => 'B', cast_int => 1, label_extra_instance => 1 } |
| 91 |
] |
| 92 |
} |
| 93 |
}, |
| 94 |
{ label => 'space-usage-prct', nlabel => 'lun.space.usage.percentage', display_ok => 0, set => { |
| 95 |
key_values => [ { name => 'prct_used_space' }, { name => 'used_space' }, { name => 'free_space' }, { name => 'prct_free_space' }, { name => 'total_space' }, { name => 'prot_space' } ], |
| 96 |
closure_custom_output => $self->can('custom_space_usage_output'), |
| 97 |
perfdatas => [ |
| 98 |
{ template => '%.2f', min => 0, max => 100, unit => '%', label_extra_instance => 1 } |
| 99 |
] |
| 100 |
} |
| 101 |
}, |
| 102 |
{ label => 'space-usage-prot', nlabel => 'lun.space.prot.bytes', display_ok => 0, set => { |
| 103 |
key_values => [ { name => 'prot_space' }, { name => 'used_space' }, { name => 'prct_used_space' }, { name => 'prct_free_space' }, { name => 'total_space' }, { name => 'free_space' } ], |
| 104 |
closure_custom_output => $self->can('custom_space_usage_output'), |
| 105 |
perfdatas => [ |
| 106 |
{ template => '%d', min => 0, max => 'total_space', unit => 'B', cast_int => 1, label_extra_instance => 1 } |
| 107 |
] |
| 108 |
} |
| 109 |
} |
| 110 |
]; |
| 111 |
} |
| 112 |
|
| 113 |
sub new { |
| 114 |
my ($class, %options) = @_; |
| 115 |
my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1); |
| 116 |
bless $self, $class; |
| 117 |
|
| 118 |
$options{options}->add_options(arguments => { |
| 119 |
'filter-name:s' => { name => 'filter_name' }, |
| 120 |
'include-non-exposed-luns' => { name => 'include_non_exposed_luns' } |
| 121 |
}); |
| 122 |
|
| 123 |
return $self; |
| 124 |
} |
| 125 |
|
| 126 |
my $mapping = { |
| 127 |
name => { oid => '.1.3.6.1.4.1.34774.4.1.23.4.8.1.2' }, # hwInfoLunName |
| 128 |
storage_pool => { oid => '.1.3.6.1.4.1.34774.4.1.23.4.8.1.4' }, # hwInfoLunPoolName |
| 129 |
total_space => { oid => '.1.3.6.1.4.1.34774.4.1.23.4.8.1.5' }, # hwInfoLunCapacity (MB) |
| 130 |
used_space => { oid => '.1.3.6.1.4.1.34774.4.1.23.4.8.1.6' }, # hwInfoLunSubscribedCapacity (MB) |
| 131 |
prot_space => { oid => '.1.3.6.1.4.1.34774.4.1.23.4.8.1.7' }, # hwInfoLunProtectionCapacity (KB) |
| 132 |
exposed => { oid => '.1.3.6.1.4.1.34774.4.1.23.4.8.1.14' } # hwInfoLunExposedToInitiator |
| 133 |
}; |
| 134 |
|
| 135 |
sub manage_selection { |
| 136 |
my ($self, %options) = @_; |
| 137 |
|
| 138 |
if ($options{snmp}->is_snmpv1()) { |
| 139 |
$self->{output}->add_option_msg(short_msg => "Need to use SNMP v2c or v3."); |
| 140 |
$self->{output}->option_exit(); |
| 141 |
} |
| 142 |
|
| 143 |
my $oid_sp_entry = '.1.3.6.1.4.1.34774.4.1.23.4.8.1'; # hwInfoLunTable |
| 144 |
my $snmp_result = $options{snmp}->get_table( |
| 145 |
oid => $oid_sp_entry, |
| 146 |
nothing_quit => 1 |
| 147 |
); |
| 148 |
|
| 149 |
$self->{lun} = {}; |
| 150 |
foreach my $oid (keys %$snmp_result) { |
| 151 |
next if ($oid !~ /^$mapping->{name}->{oid}\.(.*)$/); |
| 152 |
|
| 153 |
my $result = $options{snmp}->map_instance(mapping => $mapping, results => $snmp_result, instance => $1); |
| 154 |
if (defined($self->{option_results}->{filter_name}) && $self->{option_results}->{filter_name} ne '' && |
| 155 |
$result->{name} !~ /$self->{option_results}->{filter_name}/) { |
| 156 |
$self->{output}->output_add(long_msg => "skipping LUN '" . $result->{name} . "'.", debug => 1); |
| 157 |
next; |
| 158 |
} |
| 159 |
|
| 160 |
if (!defined($self->{option_results}->{include_non_exposed_luns}) && $result->{exposed} == 0) { |
| 161 |
$self->{output}->output_add(long_msg => "skipping LUN '" . $result->{name} . "'.", debug => 1); |
| 162 |
next; |
| 163 |
} |
| 164 |
|
| 165 |
$result->{total_space} *= 1024 * 1024; |
| 166 |
$result->{used_space} *= 1024 * 1024; |
| 167 |
$result->{prot_space} *= 1024; |
| 168 |
$self->{lun}->{ $result->{name} } = { |
| 169 |
name => $result->{name}, |
| 170 |
storage_pool => $result->{storage_pool}, |
| 171 |
space => $result |
| 172 |
}; |
| 173 |
$self->{lun}->{ $result->{name} }->{space}->{free_space} = $result->{total_space} - $result->{used_space}; |
| 174 |
$self->{lun}->{ $result->{name} }->{space}->{prct_used_space} = $result->{used_space} * 100 / $result->{total_space}; |
| 175 |
$self->{lun}->{ $result->{name} }->{space}->{prct_free_space} = 100 - $result->{used_space}; |
| 176 |
} |
| 177 |
} |
| 178 |
|
| 179 |
1; |
| 180 |
|
| 181 |
__END__ |
| 182 |
|
| 183 |
=head1 MODE |
| 184 |
|
| 185 |
Check LUNs. |
| 186 |
|
| 187 |
=over 8 |
| 188 |
|
| 189 |
=item B<--filter-name> |
| 190 |
|
| 191 |
Filter LUN by name (can be a regexp). |
| 192 |
|
| 193 |
=item B<--include-non-exposed-luns> |
| 194 |
|
| 195 |
Include LUN not exposed to an iniator, usually LUN snapshots. |
| 196 |
|
| 197 |
=item B<--warning-*> B<--critical-*> |
| 198 |
|
| 199 |
Thresholds. |
| 200 |
Can be: 'space-usage', 'space-usage-free', 'space-usage-prct'. |
| 201 |
|
| 202 |
=back |
| 203 |
|
| 204 |
=cut |