| 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 centreon::common::aruba::snmp::mode::storage; |
| 22 |
|
| 23 |
use base qw(centreon::plugins::templates::counter); |
| 24 |
|
| 25 |
use strict; |
| 26 |
use warnings; |
| 27 |
|
| 28 |
sub custom_usage_perfdata { |
| 29 |
my ($self, %options) = @_; |
| 30 |
|
| 31 |
$self->{output}->perfdata_add( |
| 32 |
instances => $self->{instance}, |
| 33 |
label => 'usage', nlabel => 'storage.usage.bytes', |
| 34 |
unit => 'B', |
| 35 |
value => $self->{result_values}->{used}, |
| 36 |
warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-' . $self->{thlabel}, total => $self->{result_values}->{total}, cast_int => 1), |
| 37 |
critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-' . $self->{thlabel}, total => $self->{result_values}->{total}, cast_int => 1), |
| 38 |
min => 0, max => $self->{result_values}->{total}); |
| 39 |
} |
| 40 |
|
| 41 |
sub custom_usage_threshold { |
| 42 |
my ($self, %options) = @_; |
| 43 |
|
| 44 |
my $exit = $self->{perfdata}->threshold_check( |
| 45 |
value => $self->{result_values}->{prct_used}, |
| 46 |
threshold => [ |
| 47 |
{ label => 'critical-' . $self->{thlabel}, exit_litteral => 'critical' }, |
| 48 |
{ label => 'warning-' . $self->{thlabel}, exit_litteral => 'warning' } |
| 49 |
] |
| 50 |
); |
| 51 |
return $exit; |
| 52 |
} |
| 53 |
|
| 54 |
sub custom_usage_output { |
| 55 |
my ($self, %options) = @_; |
| 56 |
|
| 57 |
my ($total_size_value, $total_size_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{total}); |
| 58 |
my ($total_used_value, $total_used_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{used}); |
| 59 |
my ($total_free_value, $total_free_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{free}); |
| 60 |
|
| 61 |
my $msg = sprintf("Usage Total: %s Used: %s (%.2f%%) Free: %s (%.2f%%)", |
| 62 |
$total_size_value . " " . $total_size_unit, |
| 63 |
$total_used_value . " " . $total_used_unit, $self->{result_values}->{prct_used}, |
| 64 |
$total_free_value . " " . $total_free_unit, $self->{result_values}->{prct_free}); |
| 65 |
return $msg; |
| 66 |
} |
| 67 |
|
| 68 |
sub custom_usage_calc { |
| 69 |
my ($self, %options) = @_; |
| 70 |
|
| 71 |
$self->{result_values}->{total} = $options{new_datas}->{$self->{instance} . '_sysExtStorageSize'} * 1024 * 1024; |
| 72 |
$self->{result_values}->{used} = $options{new_datas}->{$self->{instance} . '_sysExtStorageUsed'} * 1024 * 1024; |
| 73 |
$self->{result_values}->{free} = $self->{result_values}->{total} - $self->{result_values}->{used}; |
| 74 |
$self->{result_values}->{prct_free} = $self->{result_values}->{free} * 100 / $self->{result_values}->{total}; |
| 75 |
$self->{result_values}->{prct_used} = $self->{result_values}->{used} * 100 / $self->{result_values}->{total}; |
| 76 |
return 0; |
| 77 |
} |
| 78 |
|
| 79 |
sub set_counters { |
| 80 |
my ($self, %options) = @_; |
| 81 |
|
| 82 |
$self->{maps_counters_type} = [ |
| 83 |
{ name => 'storage', type => 1, cb_prefix_output => 'prefix_output', |
| 84 |
message_multiple => 'All storages are ok' }, |
| 85 |
]; |
| 86 |
|
| 87 |
$self->{maps_counters}->{storage} = [ |
| 88 |
{ label => 'usage', set => { |
| 89 |
key_values => [ { name => 'sysExtStorageUsed' }, { name => 'sysExtStorageSize' }, |
| 90 |
{ name => 'sysExtStorageName' } ], |
| 91 |
closure_custom_calc => $self->can('custom_usage_calc'), |
| 92 |
closure_custom_output => $self->can('custom_usage_output'), |
| 93 |
closure_custom_perfdata => $self->can('custom_usage_perfdata'), |
| 94 |
closure_custom_threshold_check => $self->can('custom_usage_threshold') |
| 95 |
} |
| 96 |
} |
| 97 |
]; |
| 98 |
} |
| 99 |
|
| 100 |
sub prefix_output { |
| 101 |
my ($self, %options) = @_; |
| 102 |
|
| 103 |
return "Storage '" . $options{instance_value}->{sysExtStorageName} . "' "; |
| 104 |
} |
| 105 |
|
| 106 |
sub new { |
| 107 |
my ($class, %options) = @_; |
| 108 |
my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1); |
| 109 |
bless $self, $class; |
| 110 |
|
| 111 |
$options{options}->add_options(arguments => { |
| 112 |
'filter-name:s' => { name => 'filter_name' }, |
| 113 |
'filter-type:s' => { name => 'filter_type' } |
| 114 |
}); |
| 115 |
|
| 116 |
return $self; |
| 117 |
} |
| 118 |
|
| 119 |
my $oid_wlsxSysExtStorageEntry = '.1.3.6.1.4.1.14823.2.2.1.2.1.14.1'; |
| 120 |
|
| 121 |
my %map_storage_type = ( |
| 122 |
1 => 'ram', 2 => 'flashMemory' |
| 123 |
); |
| 124 |
|
| 125 |
my $mapping = { |
| 126 |
sysExtStorageType => { oid => '.1.3.6.1.4.1.14823.2.2.1.2.1.14.1.2', map => \%map_storage_type }, |
| 127 |
sysExtStorageSize => { oid => '.1.3.6.1.4.1.14823.2.2.1.2.1.14.1.3' }, # MB |
| 128 |
sysExtStorageUsed => { oid => '.1.3.6.1.4.1.14823.2.2.1.2.1.14.1.4' }, # MB |
| 129 |
sysExtStorageName => { oid => '.1.3.6.1.4.1.14823.2.2.1.2.1.14.1.5' } |
| 130 |
}; |
| 131 |
|
| 132 |
sub manage_selection { |
| 133 |
my ($self, %options) = @_; |
| 134 |
|
| 135 |
my $snmp_result = $options{snmp}->get_table( |
| 136 |
oid => $oid_wlsxSysExtStorageEntry, |
| 137 |
start => $mapping->{sysExtStorageType}->{oid}, |
| 138 |
end => $mapping->{sysExtStorageName}->{oid}, |
| 139 |
nothing_quit => 1 |
| 140 |
); |
| 141 |
|
| 142 |
$self->{storage} = {}; |
| 143 |
|
| 144 |
foreach my $oid (keys %{$snmp_result}) { |
| 145 |
next if ($oid !~ /^$mapping->{sysExtStorageType}->{oid}\.(.*)/); |
| 146 |
my $instance = $1; |
| 147 |
|
| 148 |
my $result = $options{snmp}->map_instance( |
| 149 |
mapping => $mapping, |
| 150 |
results => $snmp_result, |
| 151 |
instance => $instance |
| 152 |
); |
| 153 |
|
| 154 |
if (defined($self->{option_results}->{filter_name}) && $self->{option_results}->{filter_name} ne '' && |
| 155 |
$result->{sysExtStorageName} !~ /$self->{option_results}->{filter_name}/) { |
| 156 |
$self->{output}->output_add(long_msg => sprintf("Skipping storage '%s'.", $result->{sysExtStorageName}), debug => 1); |
| 157 |
next; |
| 158 |
} |
| 159 |
if (defined($self->{option_results}->{filter_type}) && $self->{option_results}->{filter_type} ne '' && |
| 160 |
$result->{sysExtStorageType} !~ /$self->{option_results}->{filter_type}/i) { |
| 161 |
$self->{output}->output_add(long_msg => sprintf("Skipping storage '%s'.", $result->{sysExtStorageType}), debug => 1); |
| 162 |
next; |
| 163 |
} |
| 164 |
|
| 165 |
$self->{storage}->{$result->{sysExtStorageName}} = { %{$result} }; |
| 166 |
} |
| 167 |
|
| 168 |
if (scalar(keys %{$self->{storage}}) <= 0) { |
| 169 |
$self->{output}->add_option_msg(short_msg => "No storage found"); |
| 170 |
$self->{output}->option_exit(); |
| 171 |
} |
| 172 |
} |
| 173 |
|
| 174 |
1; |
| 175 |
|
| 176 |
__END__ |
| 177 |
|
| 178 |
=head1 MODE |
| 179 |
|
| 180 |
Check storage device usage (WLSX-SYSTEMEXT-MIB). |
| 181 |
|
| 182 |
=over 8 |
| 183 |
|
| 184 |
=item B<--warning-usage> |
| 185 |
|
| 186 |
Warning threshold in percent. |
| 187 |
|
| 188 |
=item B<--critical-usage> |
| 189 |
|
| 190 |
Critical threshold in percent. |
| 191 |
|
| 192 |
=item B<--filter-name> |
| 193 |
|
| 194 |
Filter storage device name (regexp can be used). |
| 195 |
|
| 196 |
=item B<--filter-type> |
| 197 |
|
| 198 |
Filter storage device type (regexp can be used). |
| 199 |
Can use: 'ram', 'flashMemory' |
| 200 |
|
| 201 |
=back |
| 202 |
|
| 203 |
=cut |