This commit is contained in:
garnier-quentin 2019-06-24 13:52:32 +02:00
parent 128c362687
commit 4f358b1765
4 changed files with 389 additions and 6 deletions

View File

@ -0,0 +1,91 @@
#
# Copyright 2019 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 network::huawei::snmp::mode::components::fan;
use strict;
use warnings;
my $map_present = { 1 => 'present', 2 => 'absent' };
my $map_state = { 1 => 'normal', 2 => 'abnormal' };
my $mapping = {
hwEntityFanSpeed => { oid => '.1.3.6.1.4.1.2011.5.25.31.1.1.10.1.5' },
hwEntityFanPresent => { oid => '.1.3.6.1.4.1.2011.5.25.31.1.1.10.1.6', map => $map_present },
hwEntityFanState => { oid => '.1.3.6.1.4.1.2011.5.25.31.1.1.10.1.7', map => $map_state },
};
my $oid_hwFanStatusEntry = '.1.3.6.1.4.1.2011.5.25.31.1.1.10';
sub load {
my ($self) = @_;
push @{$self->{request}}, { oid => $oid_hwFanStatusEntry, start => $mapping->{hwEntityFanSpeed}->{oid}, end => $mapping->{hwEntityFanState}->{oid} };
}
sub check {
my ($self) = @_;
$self->{output}->output_add(long_msg => "checking fans");
$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_hwFanStatusEntry}})) {
next if ($oid !~ /^$mapping->{hwEntityFanState}->{oid}\.(.*)$/);
my $instance = $1;
my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}->{$oid_hwFanStatusEntry}, instance => $instance);
next if ($self->check_filter(section => 'fan', instance => $instance));
next if ($result->{hwEntityFanPresent} =~ /absent/i &&
$self->absent_problem(section => 'fan', instance => $instance));
$self->{components}->{fan}->{total}++;
$self->{output}->output_add(long_msg =>
sprintf("fan '%s' state is '%s' [instance = %s, speed = %s]",
$instance, $result->{hwEntityFanState}, $instance,
defined($result->{hwEntityFanSpeed}) ? $result->{hwEntityFanSpeed} : '-')
);
my $exit = $self->get_severity(section => 'fan', value => $result->{hwEntityFanState});
if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) {
$self->{output}->output_add(severity => $exit,
short_msg => sprintf("fan '%s' state is '%s'", $instance, $result->{infoFanState}));
}
next if (!defined($result->{hwEntityFanSpeed}) || $result->{hwEntityFanSpeed} !~ /[0-9]/);
my ($exit2, $warn, $crit, $checked) = $self->get_severity_numeric(section => 'fan', instance => $instance, value => $result->{hwEntityFanSpeed});
if (!$self->{output}->is_status(value => $exit2, compare => 'ok', litteral => 1)) {
$self->{output}->output_add(severity => $exit2,
short_msg => sprintf("fan '%s' speed is %s %%", $instance, $result->{hwEntityFanSpeed}));
}
$self->{output}->perfdata_add(
label => 'fan', unit => '%',
nlabel => 'hardware.fan.speed.percentage',
instances => $instance,
value => $result->{hwEntityFanSpeed},
warning => $warn,
critical => $crit,
min => 0
);
}
}
1;

View File

@ -0,0 +1,93 @@
#
# Copyright 2019 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 network::huawei::snmp::mode::components::temperature;
use strict;
use warnings;
my $mapping = {
hwEntityTemperature => { oid => '.1.3.6.1.4.1.2011.5.25.31.1.1.1.1.11' },
hwEntityTemperatureThreshold => { oid => '.1.3.6.1.4.1.2011.5.25.31.1.1.1.1.12' },
};
my $oid_hwEntityStateEntry = '.1.3.6.1.4.1.2011.5.25.31.1.1.1.1';
sub load {
my ($self) = @_;
push @{$self->{request}}, { oid => $oid_hwEntityStateEntry, start => $mapping->{hwEntityTemperature}->{oid}, end => $mapping->{hwEntityTemperatureThreshold}->{oid} };
}
sub check {
my ($self) = @_;
$self->{output}->output_add(long_msg => "checking temperatures");
$self->{components}->{temperature} = { name => 'temperatures', total => 0, skip => 0 };
return if ($self->check_filter(section => 'temperature'));
foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$self->{results}->{$oid_hwEntityStateEntry}})) {
next if ($oid !~ /^$mapping->{hwEntityTemperature}->{oid}\.(.*)$/);
my $instance = $1;
my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}->{$oid_hwEntityStateEntry}, instance => $instance);
next if (!defined($result->{hwEntityTemperature}) || $result->{hwEntityTemperature} <= 0);
next if ($self->check_filter(section => 'temperature', instance => $instance));
$self->{components}->{temperature}->{total}++;
my $name = '';
$name = $self->get_short_name(instance => $instance) if (defined($self->{short_name}) && $self->{short_name} == 1);
$name = $self->get_long_name(instance => $instance) unless (defined($self->{short_name}) && $self->{short_name} == 1 && defined($name) && $name ne '');
$self->{output}->output_add(long_msg =>
sprintf("temperature '%s' is '%s' C [instance = %s]",
$name, $result->{hwEntityTemperature}, $instance)
);
my ($exit, $warn, $crit, $checked) = $self->get_severity_numeric(section => 'temperature', instance => $instance, value => $result->{hwEntityTemperature});
if ($checked == 0 && defined($result->{hwEntityTemperatureThreshold}) && $result->{hwEntityTemperatureThreshold} > 0) {
my $warn_th = '';
my $crit_th = $result->{hwEntityTemperatureThreshold};
$self->{perfdata}->threshold_validate(label => 'warning-temperature-instance-' . $instance, value => $warn_th);
$self->{perfdata}->threshold_validate(label => 'critical-temperature-instance-' . $instance, value => $crit_th);
$exit = $self->{perfdata}->threshold_check(
value => $result->{hwEntityTemperature},
threshold => [ { label => 'critical-temperature-instance-' . $instance, exit_litteral => 'critical' },
{ label => 'warning-temperature-instance-' . $instance, exit_litteral => 'warning' } ]);
$warn = $self->{perfdata}->get_perfdata_for_output(label => 'warning-temperature-instance-' . $instance);
$crit = $self->{perfdata}->get_perfdata_for_output(label => 'critical-temperature-instance-' . $instance)
}
if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) {
$self->{output}->output_add(severity => $exit,
short_msg => sprintf("temperature '%s' is %s C", $name, $result->{hwEntityTemperature}));
}
$self->{output}->perfdata_add(
label => 'temperature', unit => 'C',
nlabel => 'hardware.temperature.celsius',
instances => $name,
value => $result->{hwEntityTemperature},
warning => $warn,
critical => $crit,
);
}
}
1;

View File

@ -0,0 +1,198 @@
#
# Copyright 2019 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 network::huawei::snmp::mode::hardware;
use base qw(centreon::plugins::templates::hardware);
use strict;
use warnings;
use centreon::plugins::statefile;
sub set_system {
my ($self, %options) = @_;
$self->{regexp_threshold_overload_check_section_option} = '^(fan|temperature)$';
$self->{regexp_threshold_numeric_check_section_option} = '^(fan|temperature)$';
$self->{cb_hook1} = 'init_cache';
$self->{cb_hook2} = 'snmp_execute';
$self->{thresholds} = {
fan => [
['abnormal', 'CRITICAL'],
['normal', 'OK'],
],
};
$self->{components_path} = 'network::huawei::snmp::mode::components';
$self->{components_module} = ['fan', 'temperature'];
}
sub snmp_execute {
my ($self, %options) = @_;
$self->{snmp} = $options{snmp};
$self->{results} = $self->{snmp}->get_multiple_table(oids => $self->{request});
$self->write_cache();
}
sub init_cache {
my ($self, %options) = @_;
$self->check_cache(%options);
}
sub new {
my ($class, %options) = @_;
my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1);
bless $self, $class;
$self->{version} = '1.0';
$options{options}->add_options(arguments => {
'reload-cache-time:s' => { name => 'reload_cache_time', default => 180 },
'short-name' => { name => 'short_name' },
});
$self->{statefile_cache} = centreon::plugins::statefile->new(%options);
return $self;
}
sub check_options {
my ($self, %options) = @_;
$self->SUPER::check_options(%options);
$self->{short_name} = (defined($self->{option_results}->{short_name})) ? 1 : 0;
$self->{statefile_cache}->check_options(%options);
}
my $oid_entPhysicalEntry = '.1.3.6.1.2.1.47.1.1.1.1';
my $oid_entPhysicalDescr = '.1.3.6.1.2.1.47.1.1.1.1.2';
my $oid_entPhysicalContainedIn = '.1.3.6.1.2.1.47.1.1.1.1.4';
my $oid_entPhysicalClass = '.1.3.6.1.2.1.47.1.1.1.1.5';
my $oid_entPhysicalName = '.1.3.6.1.2.1.47.1.1.1.1.7';
sub check_cache {
my ($self, %options) = @_;
$self->{hostname} = $options{snmp}->get_hostname();
$self->{snmp_port} = $options{snmp}->get_port();
# init cache file
$self->{write_cache} = 0;
my $has_cache_file = $self->{statefile_cache}->read(statefile => 'cache_huawei_entity_' . $self->{hostname} . '_' . $self->{snmp_port});
my $timestamp_cache = $self->{statefile_cache}->get(name => 'last_timestamp');
if ($has_cache_file == 0 ||
!defined($timestamp_cache) || ((time() - $timestamp_cache) > (($self->{option_results}->{reload_cache_time}) * 60)) && $self->{option_results}->{reload_cache_time} != '-1') {
push @{$self->{request}}, { oid => $oid_entPhysicalEntry, start => $oid_entPhysicalDescr, end => $oid_entPhysicalName };
$self->{write_cache} = 1;
}
}
sub write_cache {
my ($self, %options) = @_;
if ($self->{write_cache} == 1) {
my $datas = {};
$datas->{last_timestamp} = time();
$datas->{oids} = $self->{results}->{$oid_entPhysicalEntry};
$self->{statefile_cache}->write(data => $datas);
} else {
$self->{results}->{$oid_entPhysicalEntry} = $self->{statefile_cache}->get(name => 'oids');
}
}
sub get_short_name {
my ($self, %options) = @_;
return $self->{results}->{$oid_entPhysicalEntry}->{$oid_entPhysicalName . '.' . $options{instance}};
}
sub get_long_name {
my ($self, %options) = @_;
my @names = ($self->{results}->{$oid_entPhysicalEntry}->{$oid_entPhysicalDescr . '.' . $options{instance}});
my %loop = ($options{instance} => 1);
my $child = $self->{results}->{$oid_entPhysicalEntry}->{$oid_entPhysicalContainedIn . '.' . $options{instance}};
while (1) {
last if (!defined($child) || defined($loop{$child}) || !defined($self->{results}->{$oid_entPhysicalEntry}->{$oid_entPhysicalDescr . '.' . $child}));
unshift @names, $self->{results}->{$oid_entPhysicalEntry}->{$oid_entPhysicalDescr . '.' . $child};
$loop{$child} = 1;
$child = $self->{results}->{$oid_entPhysicalEntry}->{$oid_entPhysicalContainedIn . '.' . $child};
}
return join(' > ', @names);
}
1;
__END__
=head1 MODE
Check hardware.
=over 8
=item B<--component>
Which component to check (Default: '.*').
Can be: 'fan'.
=item B<--filter>
Exclude some parts (comma seperated list) (Example: --filter=fan --filter=psu)
Can also exclude specific instance: --filter=fan,1.0
=item B<--absent-problem>
Return an error if an entity is not 'present' (default is skipping) (comma seperated list)
Can be specific or global: --absent-problem=fan,1.0
=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='fan,WARNING,abnormal'
=item B<--warning>
Set warning threshold for 'fan', 'temperature' (syntax: type,regexp,threshold)
Example: --warning='fan,.*,40'
=item B<--critical>
Set critical threshold for 'fan', 'temperature' (syntax: type,regexp,threshold)
Example: --critical='fan,.*,45'
=item B<--reload-cache-time>
Time in seconds before reloading cache file (Default: 180).
Use '-1' to disable cache reload.
=back
=cut

View File

@ -31,12 +31,13 @@ sub new {
$self->{version} = '1.0';
%{$self->{modes}} = (
'cpu' => 'network::huawei::snmp::mode::cpu',
'interfaces' => 'snmp_standard::mode::interfaces',
'list-interfaces' => 'snmp_standard::mode::listinterfaces',
'memory' => 'network::huawei::snmp::mode::memory',
'uptime' => 'snmp_standard::mode::uptime',
);
'cpu' => 'network::huawei::snmp::mode::cpu',
'hardware' => 'network::huawei::snmp::mode::hardware',
'interfaces' => 'snmp_standard::mode::interfaces',
'list-interfaces' => 'snmp_standard::mode::listinterfaces',
'memory' => 'network::huawei::snmp::mode::memory',
'uptime' => 'snmp_standard::mode::uptime',
);
return $self;
}