| 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::ibm::fs900::snmp::mode::arraysusage; |
| 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 |
label => "used", unit => 'B', |
| 33 |
instances => $self->use_instances(extra_instance => $options{extra_instance}) ? $self->{result_values}->{display} : undef, |
| 34 |
value => $self->{result_values}->{used}, |
| 35 |
warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-' . $self->{thlabel}), |
| 36 |
critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-' . $self->{thlabel}), |
| 37 |
min => 0, max => $self->{result_values}->{total}, |
| 38 |
); |
| 39 |
} |
| 40 |
|
| 41 |
sub custom_usage_threshold { |
| 42 |
my ($self, %options) = @_; |
| 43 |
|
| 44 |
my $exit = $self->{perfdata}->threshold_check(value => $self->{result_values}->{used_prct}, |
| 45 |
threshold => [ { label => 'critical-' . $self->{thlabel}, exit_litteral => 'critical' }, |
| 46 |
{ label => 'warning-' . $self->{thlabel}, exit_litteral => 'warning' } ]); |
| 47 |
return $exit; |
| 48 |
} |
| 49 |
|
| 50 |
sub custom_usage_output { |
| 51 |
my ($self, %options) = @_; |
| 52 |
|
| 53 |
my ($total, $total_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{total}); |
| 54 |
my ($used, $used_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{used}); |
| 55 |
my ($free, $free_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{free}); |
| 56 |
|
| 57 |
my $msg = sprintf("Usage Total: %s %s, Used: %s %s (%.2f%%), Free: %s %s (%.2f%%)", $total, $total_unit, $used, $used_unit, $self->{result_values}->{used_prct}, $free, $free_unit, $self->{result_values}->{free_prct}); |
| 58 |
return $msg; |
| 59 |
} |
| 60 |
|
| 61 |
sub custom_usage_calc { |
| 62 |
my ($self, %options) = @_; |
| 63 |
|
| 64 |
($self->{result_values}->{total}, $self->{result_values}->{total_unit}) = (split(' ', $options{new_datas}->{$self->{instance} . '_arrayCapacity'})); |
| 65 |
($self->{result_values}->{used}, $self->{result_values}->{used_unit}) = (split(' ', $options{new_datas}->{$self->{instance} . '_arrayCapacityUsed'})); |
| 66 |
($self->{result_values}->{free}, $self->{result_values}->{free_unit}) = (split(' ', $options{new_datas}->{$self->{instance} . '_arrayCapacityFree'})); |
| 67 |
|
| 68 |
$self->{result_values}->{total} = storage::ibm::fs900::snmp::mode::arraysusage->change_to_bytes(value => $self->{result_values}->{total}, unit => $self->{result_values}->{total_unit}); |
| 69 |
$self->{result_values}->{used} = storage::ibm::fs900::snmp::mode::arraysusage->change_to_bytes(value => $self->{result_values}->{used}, unit => $self->{result_values}->{used_unit}); |
| 70 |
$self->{result_values}->{free} = storage::ibm::fs900::snmp::mode::arraysusage->change_to_bytes(value => $self->{result_values}->{free}, unit => $self->{result_values}->{free_unit}); |
| 71 |
|
| 72 |
$self->{result_values}->{used_prct} = $self->{result_values}->{used} * 100 / $self->{result_values}->{total}; |
| 73 |
$self->{result_values}->{free_prct} = 100 - $self->{result_values}->{used_prct}; |
| 74 |
|
| 75 |
return 0; |
| 76 |
} |
| 77 |
|
| 78 |
sub change_to_bytes { |
| 79 |
my ($self, %options) = @_; |
| 80 |
|
| 81 |
my $value = ''; |
| 82 |
|
| 83 |
if ($options{unit} =~ /KiB*/i) { |
| 84 |
$value = $options{value} * 1024; |
| 85 |
} elsif ($options{unit} =~ /MiB*/i) { |
| 86 |
$value = $options{value} * 1024 * 1024; |
| 87 |
} elsif ($options{unit} =~ /GiB*/i) { |
| 88 |
$value = $options{value} * 1024 * 1024 * 1024; |
| 89 |
} elsif ($options{unit} =~ /TiB*/i) { |
| 90 |
$value = $options{value} * 1024 * 1024 * 1024 * 1024; |
| 91 |
} |
| 92 |
|
| 93 |
return $value |
| 94 |
} |
| 95 |
|
| 96 |
sub set_counters { |
| 97 |
my ($self, %options) = @_; |
| 98 |
|
| 99 |
$self->{maps_counters_type} = [ |
| 100 |
{ name => 'global', type => 1, cb_prefix_output => 'prefix_output', message_multiple => "All arrays usage are ok" } |
| 101 |
]; |
| 102 |
|
| 103 |
$self->{maps_counters}->{global} = [ |
| 104 |
{ label => 'usage', set => { |
| 105 |
key_values => [ { name => 'arrayCapacity' }, { name => 'arrayCapacityUsed' }, { name => 'arrayCapacityFree' }, { name => 'arrayId' } ], |
| 106 |
closure_custom_calc => $self->can('custom_usage_calc'), |
| 107 |
closure_custom_output => $self->can('custom_usage_output'), |
| 108 |
closure_custom_perfdata => $self->can('custom_usage_perfdata'), |
| 109 |
closure_custom_threshold_check => $self->can('custom_usage_threshold'), |
| 110 |
} |
| 111 |
}, |
| 112 |
]; |
| 113 |
} |
| 114 |
|
| 115 |
sub prefix_output { |
| 116 |
my ($self, %options) = @_; |
| 117 |
|
| 118 |
return "Array '" . $options{instance_value}->{arrayId} . "' "; |
| 119 |
} |
| 120 |
|
| 121 |
sub new { |
| 122 |
my ($class, %options) = @_; |
| 123 |
my $self = $class->SUPER::new(package => __PACKAGE__, %options); |
| 124 |
bless $self, $class; |
| 125 |
|
| 126 |
$options{options}->add_options(arguments => |
| 127 |
{ |
| 128 |
}); |
| 129 |
|
| 130 |
return $self; |
| 131 |
} |
| 132 |
|
| 133 |
my $mapping = { |
| 134 |
arrayId => { oid => '.1.3.6.1.4.1.2.6.255.1.1.1.52.1.2' }, |
| 135 |
arrayCapacity => { oid => '.1.3.6.1.4.1.2.6.255.1.1.1.52.1.4' }, |
| 136 |
arrayCapacityUsed => { oid => '.1.3.6.1.4.1.2.6.255.1.1.1.52.1.5' }, |
| 137 |
arrayCapacityFree => { oid => '.1.3.6.1.4.1.2.6.255.1.1.1.52.1.6' }, |
| 138 |
}; |
| 139 |
|
| 140 |
my $oid_arrayIndex = '.1.3.6.1.4.1.2.6.255.1.1.1.52.1'; |
| 141 |
|
| 142 |
sub manage_selection { |
| 143 |
my ($self, %options) = @_; |
| 144 |
|
| 145 |
my $snmp_result = $options{snmp}->get_table(oid => $oid_arrayIndex, |
| 146 |
nothing_quit => 1); |
| 147 |
|
| 148 |
$self->{global} = {}; |
| 149 |
|
| 150 |
foreach my $oid (keys %{$snmp_result}) { |
| 151 |
next if ($oid !~ /^$mapping->{arrayId}->{oid}\.(.*)$/); |
| 152 |
my $instance = $1; |
| 153 |
my $result = $options{snmp}->map_instance(mapping => $mapping, results => $snmp_result, instance => $instance); |
| 154 |
|
| 155 |
$self->{global}->{$result->{arrayId}} = $result; |
| 156 |
} |
| 157 |
} |
| 158 |
|
| 159 |
1; |
| 160 |
|
| 161 |
__END__ |
| 162 |
|
| 163 |
=head1 MODE |
| 164 |
|
| 165 |
Check arrays usage. |
| 166 |
|
| 167 |
=over 8 |
| 168 |
|
| 169 |
=item B<--warning-usage> |
| 170 |
|
| 171 |
Warning threshold. |
| 172 |
|
| 173 |
=item B<--critical-usage> |
| 174 |
|
| 175 |
Critical threshold. |
| 176 |
|
| 177 |
=back |
| 178 |
|
| 179 |
=cut |