update brocade hardware mode

This commit is contained in:
qgarnier 2017-05-04 10:39:35 +02:00
parent 07b1cfa164
commit 203345f64a
1 changed files with 182 additions and 72 deletions

View File

@ -20,35 +20,44 @@
package network::brocade::snmp::mode::hardware;
use base qw(centreon::plugins::mode);
use base qw(centreon::plugins::templates::hardware);
use strict;
use warnings;
use centreon::plugins::misc;
my %operational_status = (
1 => ["switch operational status is online", 'OK'],
2 => ["switch operational status is offline", 'WARNING'],
3 => ["switch operational status is testing", 'WARNING'],
4 => ["switch operational status is faulty", 'CRITICAL'],
);
my %sensor_type_map = (
1 => {name => 'temperature', unit => 'C' },
2 => {name => 'fan', unit => 'rpm' },
3 => {name => 'power-supply', unit => undef }, # No voltage value available
);
my %sensor_status = (
1 => ["%s sensor '%s' is unknown", 'UNKNOWN'],
2 => ["%s sensor '%s' is faulty", 'CRITICAL'],
3 => ["%s sensor '%s' is below-min", 'WARNING'],
4 => ["%s sensor '%s' is nominal", 'OK'],
5 => ["%s sensor '%s' is above-max", 'WARNING'],
6 => ["%s sensor '%s' is absent", 'WARNING'],
);
sub set_system {
my ($self, %options) = @_;
$self->{regexp_threshold_overload_check_section_option} = '^(global|sensor)$';
$self->{regexp_threshold_numeric_check_section_option} = '^(temperature|fan)$';
$self->{cb_hook2} = 'snmp_execute';
$self->{thresholds} = {
sensor => [
['unknown', 'UNKNOWN'],
['faulty', 'CRITICAL'],
['below-min', 'WARNING'],
['nominal', 'OK'],
['above-max', 'CRITICAL'],
['absent', 'OK'],
],
global => [
['online', 'OK'],
['offline', 'WARNING'],
['testing', 'WARNING'],
['faulty', 'CRITICAL'],
['absent', 'OK'],
],
};
$self->{components_path} = 'network::brocade::snmp::mode::components';
$self->{components_module} = ['global', 'sensor'];
}
sub new {
my ($class, %options) = @_;
my $self = $class->SUPER::new(package => __PACKAGE__, %options);
my $self = $class->SUPER::new(package => __PACKAGE__, %options, no_load_components => 1);
bless $self, $class;
$self->{version} = '1.0';
@ -59,68 +68,169 @@ sub new {
return $self;
}
sub check_options {
my ($self, %options) = @_;
$self->SUPER::init(%options);
}
sub run {
sub snmp_execute {
my ($self, %options) = @_;
$self->{snmp} = $options{snmp};
my $oid_swFirmwareVersion = '.1.3.6.1.4.1.1588.2.1.1.1.1.6.0';
my $oid_swOperStatus = '.1.3.6.1.4.1.1588.2.1.1.1.1.7.0';
my $result = $self->{snmp}->get_leef(oids => [$oid_swFirmwareVersion, $oid_swOperStatus], nothing_quit => 1);
$self->{output}->output_add(severity => ${$operational_status{$result->{$oid_swOperStatus}}}[1],
short_msg => sprintf(${$operational_status{$result->{$oid_swOperStatus}}}[0] . " [firmware: %s]",
$result->{$oid_swFirmwareVersion}));
$self->{output}->output_add(severity => 'OK',
short_msg => "All sensors are ok.");
my $oid_swSensorEntry = '.1.3.6.1.4.1.1588.2.1.1.1.1.22.1';
my $oid_swSensorIndex = '.1.3.6.1.4.1.1588.2.1.1.1.1.22.1.1';
my $oid_swSensorType = '.1.3.6.1.4.1.1588.2.1.1.1.1.22.1.2';
my $oid_swSensorStatus = '.1.3.6.1.4.1.1588.2.1.1.1.1.22.1.3';
my $oid_swSensorValue = '.1.3.6.1.4.1.1588.2.1.1.1.1.22.1.4';
my $oid_swSensorInfo = '.1.3.6.1.4.1.1588.2.1.1.1.1.22.1.5';
$result = $self->{snmp}->get_table(oid => $oid_swSensorEntry);
foreach my $key ($self->{snmp}->oid_lex_sort(keys %$result)) {
next if ($key !~ /^$oid_swSensorIndex\.(\d+)/);
my $index = $1;
my $status = $result->{$oid_swSensorStatus . '.' . $index};
my $type = $result->{$oid_swSensorType . '.' . $index};
my $info = centreon::plugins::misc::trim($result->{$oid_swSensorInfo . '.' . $index});
my $value = $result->{$oid_swSensorValue . '.' . $index};
$self->{output}->output_add(long_msg => sprintf(${$sensor_status{$status}}[0], $sensor_type_map{$type}->{name}, $info));
if (${$sensor_status{$status}}[1] ne 'OK') {
$self->{output}->output_add(severity => ${$sensor_status{$status}}[1],
short_msg => sprintf(${$sensor_status{$status}}[0], $sensor_type_map{$type}->{name}, $info));
}
if ($value > 0 && $sensor_type_map{$type}->{name} ne 'power-supply') {
$self->{output}->perfdata_add(label => $info, unit => $sensor_type_map{$type}->{unit},
value => $value);
}
}
$self->{output}->display();
$self->{output}->exit();
$self->{results} = $self->{snmp}->get_multiple_table(oids => $self->{request});
}
1;
__END__
=head1 MODE
Check brocade operational status and hardware sensors (SW.mib).
=over 8
=item B<--component>
Which component to check (Default: '.*').
Can be: 'global', 'sensor'.
=item B<--filter>
Exclude some parts (comma seperated list)
Can also exclude specific instance: --filter=sensor,1.1
=item B<--absent-problem>
Return an error if an entity is not 'present' (default is skipping)
Can be specific or global: --absent-problem=sensor,1.2
=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='sensor,OK,unknown'
=item B<--warning>
Set warning threshold for 'temperature', 'fan' (syntax: type,regexp,threshold)
Example: --warning='temperature,.*,40'
=item B<--critical>
Set critical threshold for 'temperature', 'fan' (syntax: type,regexp,threshold)
Example: --critical='temperature,.*,50'
=back
=cut
package network::brocade::snmp::mode::components::sensor;
use strict;
use warnings;
use centreon::plugins::misc;
my %map_status = (1 => 'unknown', 2 => 'faulty', 3 => 'below-min', 4 => 'nominal', 5 => 'above-max', 6 => 'absent');
my %map_type = (1 => 'temperature', 2 => 'fan', 3 => 'power-supply');
my %map_unit = (temperature => 'C', fan => 'rpm'); # No voltage value available
my $mapping = {
swSensorType => { oid => '.1.3.6.1.4.1.1588.2.1.1.1.1.22.1.2', map => \%map_type },
swSensorStatus => { oid => '.1.3.6.1.4.1.1588.2.1.1.1.1.22.1.3', map => \%map_status },
swSensorValue => { oid => '.1.3.6.1.4.1.1588.2.1.1.1.1.22.1.4' },
swSensorInfo => { oid => '.1.3.6.1.4.1.1588.2.1.1.1.1.22.1.5' },
};
my $oid_swSensorEntry = '.1.3.6.1.4.1.1588.2.1.1.1.1.22.1';
sub load {
my ($self) = @_;
push @{$self->{request}}, { oid => $oid_swSensorEntry };
}
sub check {
my ($self) = @_;
$self->{output}->output_add(long_msg => "Checking sensors");
$self->{components}->{sensor} = {name => 'sensors', total => 0, skip => 0};
return if ($self->check_filter(section => 'sensor'));
foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$self->{results}->{$oid_swSensorEntry}})) {
next if ($oid !~ /^$mapping->{swSensorStatus}->{oid}\.(.*)$/);
my $instance = $1;
my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}->{$oid_swSensorEntry}, instance => $instance);
next if ($self->check_filter(section => 'sensor', instance => $instance));
next if ($result->{swSensorStatus} =~ /absent/i &&
$self->absent_problem(section => 'sensor', instance => $instance));
$result->{swSensorInfo} = centreon::plugins::misc::trim($result->{swSensorInfo});
$self->{components}->{sensor}->{total}++;
$self->{output}->output_add(long_msg => sprintf("%s sensor '%s' status is '%s' [instance = %s]",
$result->{swSensorType}, $result->{swSensorInfo}, $result->{swSensorStatus}, $instance));
my $exit = $self->get_severity(section => 'sensor', value => $result->{swSensorStatus});
if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) {
$self->{output}->output_add(severity => $exit,
short_msg => sprintf("%s sensor '%s' status is '%s'", $result->{swSensorType}, $result->{swSensorInfo}));
}
if ($result->{swSensorValue} > 0 && $result->{swSensorType} ne 'power-supply') {
my ($exit2, $warn, $crit, $checked) = $self->get_severity_numeric(section => $result->{swSensorType}, instance => $instance, value => $result->{swSensorValue});
if (!$self->{output}->is_status(value => $exit2, compare => 'ok', litteral => 1)) {
$self->{output}->output_add(severity => $exit2,
short_msg => sprintf("%s sensor '%s' is %s %s", $result->{swSensorType}, $result->{swSensorInfo}, $result->{swSensorValue},
$map_unit{$result->{swSensorType}}));
}
$self->{output}->perfdata_add(label => $result->{swSensorInfo}, unit => $map_unit{$result->{swSensorType}},
value => $result->{swSensorValue},
warning => $warn,
critical => $crit
);
}
}
}
1;
package network::brocade::snmp::mode::components::global;
use strict;
use warnings;
my %map_oper_status = (1 => 'online', 2 => 'offline', 3 => 'testing', 4 => 'faulty');
my $mapping_global = {
swFirmwareVersion => { oid => '.1.3.6.1.4.1.1588.2.1.1.1.1.6' },
swOperStatus => { oid => '.1.3.6.1.4.1.1588.2.1.1.1.1.7', map => \%map_oper_status },
};
my $oid_swSystem = '.1.3.6.1.4.1.1588.2.1.1.1.1';
sub load {
my ($self) = @_;
push @{$self->{request}}, { oid => $oid_swSystem, start => $mapping_global->{swFirmwareVersion}->{oid}, end => $mapping_global->{swOperStatus}->{oid} };
}
sub check {
my ($self) = @_;
$self->{output}->output_add(long_msg => "Checking global");
$self->{components}->{global} = {name => 'global', total => 0, skip => 0};
return if ($self->check_filter(section => 'global'));
my $result = $self->{snmp}->map_instance(mapping => $mapping_global, results => $self->{results}->{$oid_swSystem}, instance => '0');
return if (!defined($result->{swOperStatus}));
$self->{components}->{global}->{total}++;
$self->{output}->output_add(long_msg => sprintf("switch operational status is '%s' [firmware: %s].",
$result->{swOperStatus}, $result->{swFirmwareVersion}
));
my $exit = $self->get_severity(section => 'global', value => $result->{swOperStatus});
if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) {
$self->{output}->output_add(severity => $exit,
short_msg => sprintf("switch operational status is '%s'",
$result->{swOperStatus}));
}
}
1;