Merge pull request #2413 from centreon/fix-2376

Fix #2376
This commit is contained in:
qgarnier 2020-12-07 14:15:37 +01:00 committed by GitHub
commit e113338060
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 186 additions and 35 deletions

View File

@ -33,9 +33,9 @@ my $map_status_disk = {
# In MIB 'NAS.mib'
my $mapping = {
HdDescr => { oid => '.1.3.6.1.4.1.24681.1.2.11.1.2' },
HdDescr => { oid => '.1.3.6.1.4.1.24681.1.2.11.1.2' },
HdTemperature => { oid => '.1.3.6.1.4.1.24681.1.2.11.1.3' },
HdStatus => { oid => '.1.3.6.1.4.1.24681.1.2.11.1.4', map => $map_status_disk }
HdStatus => { oid => '.1.3.6.1.4.1.24681.1.2.11.1.4', map => $map_status_disk }
};
my $mapping2 = {
HdSmartInfo => { oid => '.1.3.6.1.4.1.24681.1.2.11.1.7' }

View File

@ -24,14 +24,20 @@ use strict;
use warnings;
# In MIB 'NAS.mib'
my $oid_SysFanDescr = '.1.3.6.1.4.1.24681.1.2.15.1.2';
my $oid_SysFanSpeed = '.1.3.6.1.4.1.24681.1.2.15.1.3';
my $mapping = {
description => { oid => '.1.3.6.1.4.1.24681.1.2.15.1.2' }, # sysFanDescr
speed => { oid => '.1.3.6.1.4.1.24681.1.2.15.1.3' } # sysFanSpeed
};
my $oid_systemFanTable = '.1.3.6.1.4.1.24681.1.2.15';
sub load {
my ($self) = @_;
push @{$self->{request}}, { oid => $oid_SysFanDescr };
push @{$self->{request}}, { oid => $oid_SysFanSpeed };
push @{$self->{request}}, {
oid => $oid_systemFanTable,
start => $mapping->{description}->{oid},
end => $mapping->{speed}->{oid}
};
}
sub check {
@ -41,39 +47,40 @@ sub check {
$self->{components}->{fan} = {name => 'fans', total => 0, skip => 0};
return if ($self->check_filter(section => 'fan'));
foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$self->{results}->{$oid_SysFanDescr}})) {
$oid =~ /\.(\d+)$/;
foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$self->{results}->{$oid_systemFanTable}})) {
next if ($oid !~ /^$mapping->{description}->{oid}\.(.*)$/);
my $instance = $1;
my $fan_descr = $self->{results}->{$oid_SysFanDescr}->{$oid};
my $fan_speed = defined($self->{results}->{$oid_SysFanSpeed}->{$oid_SysFanSpeed . '.' . $instance}) ?
$self->{results}->{$oid_SysFanSpeed}->{$oid_SysFanSpeed . '.' . $instance} : 'unknown';
my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}->{$oid_systemFanTable}, instance => $instance);
$result->{speed} = defined($result->{speed}) ? $result->{speed} : 'unknown';
next if ($self->check_filter(section => 'fan', instance => $instance));
$self->{components}->{fan}->{total}++;
$self->{output}->output_add(
long_msg => sprintf(
"fan '%s' [instance: %s] speed is '%s'.",
$fan_descr, $instance, $fan_speed
"fan '%s' speed is '%s' [instance: %s]",
$result->{description}, $result->{speed}, $instance
)
);
if ($fan_speed =~ /([0-9]+)\s*rpm/i) {
if ($result->{speed} =~ /([0-9]+)\s*rpm/i) {
my $fan_speed_value = $1;
my ($exit, $warn, $crit) = $self->get_severity_numeric(section => 'fan', instance => $instance, value => $fan_speed_value);
if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) {
$self->{output}->output_add(
severity => $exit,
short_msg => sprintf(
"Fan '%s' speed is %s rpm", $fan_descr, $fan_speed_value
"Fan '%s' speed is %s rpm", $result->{description}, $fan_speed_value
)
);
}
$self->{output}->perfdata_add(
label => 'fan', unit => 'rpm',
nlabel => 'hardware.fan.speed.rpm',
unit => 'rpm',
instances => $instance,
value => $fan_speed_value, min => 0
value => $fan_speed_value,
min => 0
);
}
}

View File

@ -0,0 +1,120 @@
#
# Copyright 2020 Centreon (http://www.centreon.com/)
#
# 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 storage::qnap::snmp::mode::components::psu;
use strict;
use warnings;
my $map_status = {
0 => 'ok', -1 => 'fail'
};
my $mapping = {
status => { oid => '.1.3.6.1.4.1.24681.1.4.1.1.1.1.3.2.1.4', map => $map_status }, # systemPowerStatus
speed => { oid => '.1.3.6.1.4.1.24681.1.4.1.1.1.1.3.2.1.5' }, # systemPowerFanSpeed
temperature => { oid => '.1.3.6.1.4.1.24681.1.4.1.1.1.1.3.2.1.6' } # systemPowerTemp
};
my $oid_systemPowerTable = '.1.3.6.1.4.1.24681.1.4.1.1.1.1.3.2';
sub load {
my ($self) = @_;
push @{$self->{request}}, {
oid => $oid_systemPowerTable,
start => $mapping->{status}->{oid},
end => $mapping->{temperature}->{oid}
};
}
sub check {
my ($self) = @_;
$self->{output}->output_add(long_msg => "Checking power supplies");
$self->{components}->{psu} = { name => 'psu', total => 0, skip => 0 };
return if ($self->check_filter(section => 'psu'));
foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$self->{results}->{$oid_systemPowerTable}})) {
next if ($oid !~ /^$mapping->{status}->{oid}\.(.*)$/);
my $instance = $1;
my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}->{$oid_systemPowerTable}, instance => $instance);
next if ($self->check_filter(section => 'psu', instance => $instance));
$self->{components}->{psu}->{total}++;
$self->{output}->output_add(
long_msg => sprintf(
"power supply '%s' status is '%s' [instance: %s, fan speed: %s, temperature: %s]",
$instance, $result->{status}, $instance, $result->{speed}, $result->{temperature}
)
);
my $exit = $self->get_severity(section => 'psu', value => $result->{status});
if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) {
$self->{output}->output_add(
severity => $exit,
short_msg => sprintf(
"Power supply '%s' status is '%s'", $instance, $result->{status}
)
);
}
if ($result->{speed} =~ /[0-9]/) {
my ($exit2, $warn, $crit) = $self->get_severity_numeric(section => 'psu.fanspeed', instance => $instance, value => $result->{speed});
if (!$self->{output}->is_status(value => $exit2, compare => 'ok', litteral => 1)) {
$self->{output}->output_add(
severity => $exit,
short_msg => sprintf(
"Power supply '%s' fan speed is %s rpm", $instance, $result->{speed}
)
);
}
$self->{output}->perfdata_add(
nlabel => 'hardware.powersupply.fan.speed.rpm',
unit => 'rpm',
instances => $instance,
value => $result->{speed},
min => 0
);
}
if ($result->{temperature} =~ /[0-9]/) {
my ($exit2, $warn, $crit) = $self->get_severity_numeric(section => 'psu.temperature', instance => $instance, value => $result->{temperature});
if (!$self->{output}->is_status(value => $exit2, compare => 'ok', litteral => 1)) {
$self->{output}->output_add(
severity => $exit,
short_msg => sprintf(
"Power supply '%s' temperature is %s C", $instance, $result->{temperature}
)
);
}
$self->{output}->perfdata_add(
nlabel => 'hardware.powersupply.temperature.celsius',
unit => 'C',
instances => $instance,
value => $result->{temperature}
);
}
}
}
1;

View File

@ -29,10 +29,21 @@ my $oid_CPU_Temperature = '.1.3.6.1.4.1.24681.1.2.5.0';
my $oid_SystemTemperature_entry = '.1.3.6.1.4.1.24681.1.2.6';
my $oid_SystemTemperature = '.1.3.6.1.4.1.24681.1.2.6.0';
my $mapping = {
cpu_temp => { oid => '.1.3.6.1.4.1.24681.1.2.5' }, # cpu-Temperature
system_temp => { oid => '.1.3.6.1.4.1.24681.1.2.6' }, # systemTemperature
};
my $oid_systemInfo = '.1.3.6.1.4.1.24681.1.2';
sub load {
my ($self) = @_;
push @{$self->{request}}, { oid => $oid_CPU_Temperature_entry }, { oid => $oid_SystemTemperature_entry };
push @{$self->{request}}, {
oid => $oid_systemInfo,
start => $mapping->{cpu_temp}->{oid},
end => $mapping->{system_temp}->{oid}
};
}
sub check {
@ -42,9 +53,10 @@ sub check {
$self->{components}->{temperature} = {name => 'temperatures', total => 0, skip => 0};
return if ($self->check_filter(section => 'temperature'));
my $cpu_temp = defined($self->{results}->{$oid_CPU_Temperature_entry}->{$oid_CPU_Temperature}) ?
$self->{results}->{$oid_CPU_Temperature_entry}->{$oid_CPU_Temperature} : 'unknown';
if ($cpu_temp =~ /([0-9]+)\s*C/ && !$self->check_filter(section => 'temperature', instance => 'cpu')) {
my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}->{$oid_systemInfo}, instance => 0);
$result->{cpu_temp} = defined($result->{cpu_temp}) ? $result->{cpu_temp} : 'unknown';
if ($result->{cpu_temp} =~ /([0-9]+)\s*C/ && !$self->check_filter(section => 'temperature', instance => 'cpu')) {
my $value = $1;
$self->{components}->{temperature}->{total}++;
$self->{output}->output_add(
@ -63,28 +75,35 @@ sub check {
);
}
$self->{output}->perfdata_add(
label => 'temp', unit => 'C',
nlabel => 'hardware.temperature.celsius',
unit => 'C',
instances => 'cpu',
value => $value
);
}
my $system_temp = defined($self->{results}->{$oid_SystemTemperature_entry}->{$oid_SystemTemperature}) ?
$self->{results}->{$oid_SystemTemperature_entry}->{$oid_SystemTemperature} : 'unknown';
if ($system_temp =~ /([0-9]+)\s*C/ && !$self->check_filter(section => 'temperature', instance => 'system')) {
$result->{system_temp} = defined($result->{system_temp}) ? $result->{system_temp} : 'unknown';
if ($result->{system_temp} =~ /([0-9]+)\s*C/ && !$self->check_filter(section => 'temperature', instance => 'system')) {
my $value = $1;
$self->{components}->{temperature}->{total}++;
$self->{output}->output_add(long_msg => sprintf("System Temperature is '%s' degree centigrade",
$value));
$self->{output}->output_add(
long_msg => sprintf(
"system Temperature is '%s' degree centigrade",
$value
)
);
my ($exit, $warn, $crit) = $self->get_severity_numeric(section => 'temperature', instance => 'system', value => $value);
if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) {
$self->{output}->output_add(severity => $exit,
short_msg => sprintf("System Temperature is '%s' degree centigrade", $value));
$self->{output}->output_add(
severity => $exit,
short_msg => sprintf(
"System Temperature is '%s' degree centigrade", $value
)
);
}
$self->{output}->perfdata_add(
label => 'temp', unit => 'C',
nlabel => 'hardware.temperature.celsius',
unit => 'C',
instances => 'system',
value => $value
);

View File

@ -28,7 +28,8 @@ use warnings;
sub set_system {
my ($self, %options) = @_;
$self->{regexp_threshold_numeric_check_section_option} = '^(temperature|disk|smartdisk|fan)$';
$self->{regexp_threshold_numeric_check_section_option} =
'^(?:temperature|disk|smartdisk|fan|psu\.fanspeed|psu\.temperature)$';
$self->{cb_hook2} = 'snmp_execute';
@ -51,11 +52,15 @@ sub set_system {
['Synchronizing', 'OK'],
['degraded', 'WARNING'],
['.*', 'CRITICAL']
],
psu => [
['ok', 'OK'],
['fail', 'CRITICAL']
]
};
$self->{components_path} = 'storage::qnap::snmp::mode::components';
$self->{components_module} = ['temperature', 'disk', 'fan', 'raid'];
$self->{components_module} = ['disk', 'fan', 'psu', 'raid', 'temperature'];
}
sub snmp_execute {
@ -67,7 +72,7 @@ sub snmp_execute {
sub new {
my ($class, %options) = @_;
my $self = $class->SUPER::new(package => __PACKAGE__, %options);
my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1);
bless $self, $class;
$options{options}->add_options(arguments => {});
@ -88,7 +93,7 @@ Check hardware (NAS.mib) (Fans, Temperatures, Disks, Raid).
=item B<--component>
Which component to check (Default: '.*').
Can be: 'fan', 'disk', 'temperature', 'raid'.
Can be: 'disk', 'fan', 'psu', 'raid', 'temperature'.
=item B<--filter>