centreon-plugins/snmp_standard/mode/hardwarefibrealliance.pm

242 lines
7.9 KiB
Perl
Raw Normal View History

#
2020-01-06 15:19:23 +01:00
# Copyright 2020 Centreon (http://www.centreon.com/)
2015-07-21 11:51:02 +02:00
#
# Centreon is a full-fledged industry-strength solution that meets
# the needs in IT infrastructure and application monitoring for
# service performance.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
package snmp_standard::mode::hardwarefibrealliance;
2019-06-25 14:00:22 +02:00
use base qw(centreon::plugins::templates::hardware);
use strict;
use warnings;
2019-06-25 14:00:22 +02:00
sub set_system {
my ($self, %options) = @_;
$self->{regexp_threshold_overload_check_section_option} = '^(sensors|port)$';
$self->{cb_hook2} = 'snmp_execute';
$self->{thresholds} = {
sensors => [
['unknown', 'UNKNOWN'],
['other', 'UNKNOWN'],
['warning', 'WARNING'],
['failed', 'CRITICAL'],
['ok', 'OK'],
],
port => [
['warning', 'WARNING'],
['failure', 'CRITICAL'],
['unused', 'OK'],
['initializing', 'OK'],
['ready', 'OK'],
['.*', 'UNKNOWN'],
],
};
$self->{components_path} = 'snmp_standard::mode::components';
$self->{components_module} = ['sensors', 'port'];
}
sub new {
my ($class, %options) = @_;
my $self = $class->SUPER::new(package => __PACKAGE__, %options,
2019-06-25 14:56:19 +02:00
no_absent => 1, no_performance => 1, no_load_components => 1, force_new_perfdata => 1);
2019-06-25 14:00:22 +02:00
bless $self, $class;
$options{options}->add_options(arguments => {});
return $self;
}
sub snmp_execute {
my ($self, %options) = @_;
$self->{snmp} = $options{snmp};
$self->{results} = $self->{snmp}->get_multiple_table(oids => $self->{request});
}
1;
=head1 MODE
Check status of SAN Hardware (Following FibreAlliance MIB: MIB40)
http://www.emc.com/microsites/fibrealliance/index.htm
=over 8
=item B<--component>
Which component to check (Default: '.*').
Can be: 'sensors', 'port'.
=item B<--filter>
Exclude some parts (comma seperated list)
Can also exclude specific instance: --filter=sensors,1
=item B<--no-component>
Return an error if no compenents are checked.
If total (with skipped) is 0. (Default: 'critical' returns).
=item B<--threshold-overload>
Set to overload default threshold values (syntax: section,[instance,]status,regexp)
It used before default thresholds (order stays).
Example: --threshold-overload='sensors,CRITICAL,^(?!(ok)$)'
=back
=cut
package snmp_standard::mode::components::sensors;
use strict;
use warnings;
my %map_sensor_status = (
2019-06-25 14:00:22 +02:00
1 => 'unknown', 2 => 'other',
3 => 'ok', 4 => 'warning',
5 => 'failed',
);
my %map_sensor_type = (
1 => 'unknown', 2 => 'other',
3 => 'battery', 4 => 'fan',
5 => 'power-supply', 6 => 'transmitter',
7 => 'enclosure', 8 => 'board', 9 => 'receiver',
);
my %map_sensor_chara = (
1 => 'unknown', 2 => 'other',
3 => 'temperature', 4 => 'pressure',
5 => 'emf', 6 => 'currentValue', 7 => 'airflow',
8 => 'frequency', 9 => 'power', 10 => 'door',
);
2019-06-25 14:00:22 +02:00
my $mapping = {
connUnitSensorName => { oid => '.1.3.6.1.3.94.1.8.1.3' },
connUnitSensorStatus => { oid => '.1.3.6.1.3.94.1.8.1.4', map => \%map_sensor_status },
connUnitSensorMessage => { oid => '.1.3.6.1.3.94.1.8.1.6' },
connUnitSensorType => { oid => '.1.3.6.1.3.94.1.8.1.7', map => \%map_sensor_type },
connUnitSensorCharacteristic => { oid => '.1.3.6.1.3.94.1.8.1.8', map => \%map_sensor_chara },
};
2019-06-25 14:00:22 +02:00
my $oid_connUnitSensorEntry = '.1.3.6.1.3.94.1.8.1';
2019-06-25 14:00:22 +02:00
sub load {
my ($self) = @_;
2019-06-25 14:00:22 +02:00
push @{$self->{request}}, { oid => $oid_connUnitSensorEntry, start => $mapping->{connUnitSensorName}->{oid}, end => $mapping->{connUnitSensorCharacteristic}->{oid} };
}
2019-06-25 14:00:22 +02:00
sub check {
my ($self) = @_;
2019-06-25 14:00:22 +02:00
$self->{output}->output_add(long_msg => "checking sensors");
$self->{components}->{sensors} = {name => 'sensors', total => 0, skip => 0};
2019-06-25 14:00:22 +02:00
return if ($self->check_filter(section => 'sensors'));
2019-06-25 14:00:22 +02:00
foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$self->{results}->{$oid_connUnitSensorEntry}})) {
next if ($oid !~ /^$mapping->{connUnitSensorName}->{oid}\.(.*)$/);
my $instance = $1;
2019-06-25 14:00:22 +02:00
my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}->{$oid_connUnitSensorEntry}, instance => $instance);
2019-06-25 14:00:22 +02:00
next if ($self->check_filter(section => 'sensors', instance => $instance, name => $result->{connUnitSensorName}));
$self->{components}->{sensors}->{total}++;
2019-06-25 14:00:22 +02:00
$self->{output}->output_add(long_msg => sprintf(
2019-06-25 14:01:31 +02:00
"sensor '%s' status is %s [msg: %s] [type: %s] [chara: %s] [instance: %s]",
2019-06-25 14:00:22 +02:00
$result->{connUnitSensorName}, $result->{connUnitSensorStatus},
2019-06-25 14:01:31 +02:00
$result->{connUnitSensorMessage}, $result->{connUnitSensorType}, $result->{connUnitSensorCharacteristic}, $instance)
2019-06-25 14:00:22 +02:00
);
my $exit = $self->get_severity(section => 'sensors', name => $result->{connUnitSensorName}, value => $result->{connUnitSensorStatus});
if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) {
2020-01-28 17:14:19 +01:00
$self->{output}->output_add(
severity => $exit,
short_msg => sprintf(
"Sensor '%s' status is %s",
$result->{connUnitSensorName},
$result->{connUnitSensorStatus}
)
);
}
}
}
2019-06-25 14:00:22 +02:00
package snmp_standard::mode::components::port;
use strict;
use warnings;
my %map_port_status = (
1 => 'unknown', 2 => 'unused',
3 => 'ready', 4 => 'warning',
5 => 'failure', 6 => 'notparticipating',
7 => 'initializing', 8 => 'bypass',
9 => 'ols', 10 => 'other',
);
my $mapping_port = {
connUnitPortName => { oid => '.1.3.6.1.3.94.1.10.1.17' },
connUnitPortStatus => { oid => '.1.3.6.1.3.94.1.10.1.7', map => \%map_port_status },
};
sub load {
my ($self) = @_;
push @{$self->{request}}, { oid => $mapping_port->{connUnitPortName}->{oid} }, { oid => $mapping_port->{connUnitPortStatus}->{oid} };
}
sub check {
my ($self) = @_;
2019-06-25 14:00:22 +02:00
$self->{output}->output_add(long_msg => "checking ports");
$self->{components}->{port} = {name => 'ports', total => 0, skip => 0};
2019-06-25 14:00:22 +02:00
return if ($self->check_filter(section => 'port'));
2019-06-25 14:00:22 +02:00
foreach my $key ($self->{snmp}->oid_lex_sort(keys %{$self->{results}->{ $mapping_port->{connUnitPortName}->{oid} }})) {
$key =~ /^$mapping_port->{connUnitPortName}->{oid}\.(.*)/;
my $instance = $1;
2019-06-25 14:00:22 +02:00
my $name = $self->{results}->{ $mapping_port->{connUnitPortName}->{oid} }->{$key};
my $result = $self->{snmp}->map_instance(mapping => $mapping_port, results => $self->{results}->{ $mapping_port->{connUnitPortStatus}->{oid} }, instance => $instance);
2019-06-25 14:00:22 +02:00
next if ($self->check_filter(section => 'port', instance => $instance, name => $name));
2020-01-28 17:14:19 +01:00
$self->{components}->{port}->{total}++;
2020-01-28 17:14:19 +01:00
$self->{output}->output_add(
long_msg => sprintf(
"port '%s' status is %s [instance: %s]",
$name, $result->{connUnitPortStatus}, $instance
)
);
2019-06-25 14:00:22 +02:00
my $exit = $self->get_severity(section => 'port', name => $name, value => $result->{connUnitPortStatus});
if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) {
2020-01-28 17:14:19 +01:00
$self->{output}->output_add(
severity => $exit,
short_msg => sprintf(
"Port '%s' status is %s",
$name,
$result->{connUnitPortStatus}
)
);
}
}
}