| 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::hp::msl::snmp::mode::hardware; |
| 22 |
|
| 23 |
use base qw(centreon::plugins::templates::hardware); |
| 24 |
|
| 25 |
use strict; |
| 26 |
use warnings; |
| 27 |
|
| 28 |
sub set_system { |
| 29 |
my ($self, %options) = @_; |
| 30 |
|
| 31 |
$self->{cb_hook2} = 'snmp_execute'; |
| 32 |
|
| 33 |
$self->{thresholds} = { |
| 34 |
library => [ |
| 35 |
['unknown', 'UNKNOWN'], |
| 36 |
['unused', 'UNKNOWN'], |
| 37 |
['ok', 'OK'], |
| 38 |
['warning', 'WARNING'], |
| 39 |
['critical', 'CRITICAL'], |
| 40 |
['nonrecoverable', 'CRITICAL'], |
| 41 |
], |
| 42 |
}; |
| 43 |
|
| 44 |
$self->{components_path} = 'storage::hp::msl::snmp::mode::components'; |
| 45 |
$self->{components_module} = ['library']; |
| 46 |
} |
| 47 |
|
| 48 |
sub new { |
| 49 |
my ($class, %options) = @_; |
| 50 |
my $self = $class->SUPER::new(package => __PACKAGE__, %options, no_absent => 1, no_performance => 1, no_load_components => 1); |
| 51 |
bless $self, $class; |
| 52 |
|
| 53 |
$options{options}->add_options(arguments => {}); |
| 54 |
|
| 55 |
return $self; |
| 56 |
} |
| 57 |
|
| 58 |
sub snmp_execute { |
| 59 |
my ($self, %options) = @_; |
| 60 |
|
| 61 |
$self->{snmp} = $options{snmp}; |
| 62 |
$self->{results} = $self->{snmp}->get_multiple_table(oids => $self->{request}); |
| 63 |
} |
| 64 |
|
| 65 |
1; |
| 66 |
|
| 67 |
=head1 MODE |
| 68 |
|
| 69 |
Check hardware. |
| 70 |
|
| 71 |
=over 8 |
| 72 |
|
| 73 |
=item B<--component> |
| 74 |
|
| 75 |
Which component to check (default: '.*'). |
| 76 |
Can be: 'library'. |
| 77 |
|
| 78 |
=item B<--no-component> |
| 79 |
|
| 80 |
Define the expected status if no components are found (default: critical). |
| 81 |
|
| 82 |
=item B<--threshold-overload> |
| 83 |
|
| 84 |
Use this option to override the status returned by the plugin when the status label matches a regular expression (syntax: section,[instance,]status,regexp). |
| 85 |
Example: --threshold-overload='library,CRITICAL,^(?!(ok)$)' |
| 86 |
|
| 87 |
=back |
| 88 |
|
| 89 |
=cut |
| 90 |
|
| 91 |
package storage::hp::msl::snmp::mode::components::library; |
| 92 |
|
| 93 |
use strict; |
| 94 |
use warnings; |
| 95 |
|
| 96 |
my %map_health = (1 => 'unknown', 2 => 'unused', 3 => 'ok', |
| 97 |
4 => 'warning', 5 => 'critical', 6 => 'nonrecoverable', |
| 98 |
); |
| 99 |
|
| 100 |
my $mapping_library = { |
| 101 |
hpHttpMgDeviceHealth => { oid => '.1.3.6.1.4.1.11.2.36.1.1.5.1.1.3', map => \%map_health }, |
| 102 |
}; |
| 103 |
|
| 104 |
sub load { |
| 105 |
my ($self) = @_; |
| 106 |
|
| 107 |
push @{$self->{request}}, { oid => $mapping_library->{hpHttpMgDeviceHealth}->{oid} }; |
| 108 |
} |
| 109 |
|
| 110 |
sub check { |
| 111 |
my ($self) = @_; |
| 112 |
|
| 113 |
$self->{output}->output_add(long_msg => "Checking library"); |
| 114 |
$self->{components}->{library} = {name => 'library', total => 0, skip => 0}; |
| 115 |
return if ($self->check_filter(section => 'library')); |
| 116 |
|
| 117 |
foreach ($self->{snmp}->oid_lex_sort(keys %{$self->{results}->{ $mapping_library->{hpHttpMgDeviceHealth}->{oid} }})) { |
| 118 |
/^$mapping_library->{hpHttpMgDeviceHealth}->{oid}\.(.*)$/; |
| 119 |
my $instance = $1; |
| 120 |
my $result = $self->{snmp}->map_instance(mapping => $mapping_library, results => $self->{results}->{ $mapping_library->{hpHttpMgDeviceHealth}->{oid} }, instance => $instance); |
| 121 |
|
| 122 |
next if ($self->check_filter(section => 'library', instance => $instance)); |
| 123 |
|
| 124 |
$self->{components}->{library}->{total}++; |
| 125 |
$self->{output}->output_add(long_msg => sprintf("library '%s' status is '%s' [instance = %s]", |
| 126 |
$instance, $result->{hpHttpMgDeviceHealth}, $instance)); |
| 127 |
my $exit = $self->get_severity(section => 'library', value => $result->{hpHttpMgDeviceHealth}); |
| 128 |
if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { |
| 129 |
$self->{output}->output_add(severity => $exit, |
| 130 |
short_msg => sprintf("Library '%s' status is '%s'", $instance, $result->{hpHttpMgDeviceHealth})); |
| 131 |
} |
| 132 |
} |
| 133 |
} |
| 134 |
|
| 135 |
1; |