From 9be46dafa0c4b5b63faa7a5220057678d882fe9d Mon Sep 17 00:00:00 2001 From: garnier-quentin Date: Fri, 29 Mar 2019 09:37:12 +0100 Subject: [PATCH] Fix #585 --- .../hwgste/snmp/mode/components/humidity.pm | 22 +++++++++---------- .../hwgste/snmp/mode/components/resources.pm | 22 ++++++++++++++----- .../snmp/mode/components/temperature.pm | 22 +++++++++---------- hardware/sensors/hwgste/snmp/mode/sensors.pm | 16 +++++++++----- 4 files changed, 49 insertions(+), 33 deletions(-) diff --git a/hardware/sensors/hwgste/snmp/mode/components/humidity.pm b/hardware/sensors/hwgste/snmp/mode/components/humidity.pm index 3cbd60924..428ae676c 100644 --- a/hardware/sensors/hwgste/snmp/mode/components/humidity.pm +++ b/hardware/sensors/hwgste/snmp/mode/components/humidity.pm @@ -24,8 +24,6 @@ use strict; use warnings; use hardware::sensors::hwgste::snmp::mode::components::resources qw($mapping); -my $oid_sensEntry = '.1.3.6.1.4.1.21796.4.1.3.1'; - sub load {} sub check { @@ -35,17 +33,19 @@ sub check { $self->{components}->{humidity} = {name => 'humidity', total => 0, skip => 0}; return if ($self->check_filter(section => 'humidity')); - foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$self->{results}->{$oid_sensEntry}})) { - next if ($oid !~ /^$mapping->{sensState}->{oid}\.(.*)$/); + foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$self->{results}->{ $mapping->{branch_sensors}->{$self->{branch}} }})) { + next if ($oid !~ /^$mapping->{$self->{branch}}->{sensState}->{oid}\.(.*)$/); my $instance = $1; - my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}->{$oid_sensEntry}, instance => $instance); + my $result = $self->{snmp}->map_instance(mapping => $mapping->{$self->{branch}}, results => $self->{results}->{ $mapping->{branch_sensors}->{$self->{branch}} }, instance => $instance); next if (!(defined($result->{sensUnit}) && $result->{sensUnit} eq '%')); next if ($self->check_filter(section => 'humidity', instance => $instance)); $self->{components}->{humidity}->{total}++; + $result->{sensValue} /= 10 if ($result->{sensValue} =~ /\d+/); + $self->{output}->output_add(long_msg => sprintf("humidity '%s' state is '%s' [instance: %s, value: %s]", - $result->{sensName}, $result->{sensState}, $instance, $result->{sensTemp})); + $result->{sensName}, $result->{sensState}, $instance, $result->{sensValue})); my $exit = $self->get_severity(section => 'humidity', label => 'default', instance => $instance, value => $result->{sensState}); if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { @@ -53,18 +53,18 @@ sub check { short_msg => sprintf("humidity '%s' state is '%s'", $result->{sensName}, $result->{sensState})); } - if ($result->{sensTemp} =~ /\d+/) { - my ($exit2, $warn, $crit, $checked) = $self->get_severity_numeric(section => 'humidity', instance => $instance, value => $result->{sensTemp}); + if ($result->{sensValue} =~ /\d+/) { + my ($exit2, $warn, $crit, $checked) = $self->get_severity_numeric(section => 'humidity', instance => $instance, value => $result->{sensValue}); if (!$self->{output}->is_status(value => $exit2, compare => 'ok', litteral => 1)) { $self->{output}->output_add(severity => $exit2, - short_msg => sprintf("humidity '%s' value is %s %s", $result->{sensName}, $result->{sensTemp}, $result->{sensUnit})); + short_msg => sprintf("humidity '%s' value is %s %s", $result->{sensName}, $result->{sensValue}, $result->{sensUnit})); } $self->{output}->perfdata_add(label => 'sensor_' . $result->{sensName}, unit => $result->{sensUnit}, - value => $result->{sensTemp}, + value => $result->{sensValue}, warning => $warn, critical => $crit, min => 0, max => 100); } } } -1; \ No newline at end of file +1; diff --git a/hardware/sensors/hwgste/snmp/mode/components/resources.pm b/hardware/sensors/hwgste/snmp/mode/components/resources.pm index cacaad748..7456e15bb 100644 --- a/hardware/sensors/hwgste/snmp/mode/components/resources.pm +++ b/hardware/sensors/hwgste/snmp/mode/components/resources.pm @@ -48,10 +48,22 @@ our @EXPORT_OK = qw($mapping); ); $mapping = { - sensName => { oid => '.1.3.6.1.4.1.21796.4.1.3.1.2' }, - sensState => { oid => '.1.3.6.1.4.1.21796.4.1.3.1.3', map => \%map_sens_state }, - sensTemp => { oid => '.1.3.6.1.4.1.21796.4.1.3.1.4' }, - sensUnit => { oid => '.1.3.6.1.4.1.21796.4.1.3.1.7', map => \%map_sens_unit }, + branch_sensors => { + hwgste => '.1.3.6.1.4.1.21796.4.1.3', + hwgste2 => '.1.3.6.1.4.1.21796.4.9.3', + }, + hwgste => { + sensName => { oid => '.1.3.6.1.4.1.21796.4.1.3.1.2' }, + sensState => { oid => '.1.3.6.1.4.1.21796.4.1.3.1.3', map => \%map_sens_state }, + sensValue => { oid => '.1.3.6.1.4.1.21796.4.1.3.1.5' }, + sensUnit => { oid => '.1.3.6.1.4.1.21796.4.1.3.1.7', map => \%map_sens_unit }, + }, + hwgste2 => { + sensName => { oid => '.1.3.6.1.4.1.21796.4.9.3.1.2' }, + sensState => { oid => '.1.3.6.1.4.1.21796.4.9.3.1.3', map => \%map_sens_state }, + sensValue => { oid => '.1.3.6.1.4.1.21796.4.9.3.1.5' }, + sensUnit => { oid => '.1.3.6.1.4.1.21796.4.9.3.1.7', map => \%map_sens_unit }, + }, }; -1; \ No newline at end of file +1; diff --git a/hardware/sensors/hwgste/snmp/mode/components/temperature.pm b/hardware/sensors/hwgste/snmp/mode/components/temperature.pm index 6deb17546..9878eb62b 100644 --- a/hardware/sensors/hwgste/snmp/mode/components/temperature.pm +++ b/hardware/sensors/hwgste/snmp/mode/components/temperature.pm @@ -24,8 +24,6 @@ use strict; use warnings; use hardware::sensors::hwgste::snmp::mode::components::resources qw($mapping); -my $oid_sensEntry = '.1.3.6.1.4.1.21796.4.1.3.1'; - sub load {} sub check { @@ -35,17 +33,19 @@ sub check { $self->{components}->{temperature} = {name => 'temperature', total => 0, skip => 0}; return if ($self->check_filter(section => 'temperature')); - foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$self->{results}->{$oid_sensEntry}})) { - next if ($oid !~ /^$mapping->{sensState}->{oid}\.(.*)$/); + foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$self->{results}->{ $mapping->{branch_sensors}->{$self->{branch}} }})) { + next if ($oid !~ /^$mapping->{$self->{branch}}->{sensState}->{oid}\.(.*)$/); my $instance = $1; - my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}->{$oid_sensEntry}, instance => $instance); + my $result = $self->{snmp}->map_instance(mapping => $mapping->{$self->{branch}}, results => $self->{results}->{ $mapping->{branch_sensors}->{$self->{branch}} }, instance => $instance); next if (!(defined($result->{sensUnit}) && $result->{sensUnit} =~ /C|F|K/i)); next if ($self->check_filter(section => 'temperature', instance => $instance)); $self->{components}->{temperature}->{total}++; + $result->{sensValue} /= 10 if ($result->{sensValue} =~ /\d+/); + $self->{output}->output_add(long_msg => sprintf("temperature '%s' state is '%s' [instance: %s, value: %s]", - $result->{sensName}, $result->{sensState}, $instance, $result->{sensTemp})); + $result->{sensName}, $result->{sensState}, $instance, $result->{sensValue})); my $exit = $self->get_severity(section => 'temperature', label => 'default', instance => $instance, value => $result->{sensState}); if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { @@ -53,18 +53,18 @@ sub check { short_msg => sprintf("temperature '%s' state is '%s'", $result->{sensName}, $result->{sensState})); } - if ($result->{sensTemp} =~ /\d+/) { - my ($exit2, $warn, $crit, $checked) = $self->get_severity_numeric(section => 'temperature', instance => $instance, value => $result->{sensTemp}); + if ($result->{sensValue} =~ /\d+/) { + my ($exit2, $warn, $crit, $checked) = $self->get_severity_numeric(section => 'temperature', instance => $instance, value => $result->{sensValue}); if (!$self->{output}->is_status(value => $exit2, compare => 'ok', litteral => 1)) { $self->{output}->output_add(severity => $exit2, - short_msg => sprintf("temperature '%s' value is %s %s", $result->{sensName}, $result->{sensTemp}, $result->{sensUnit})); + short_msg => sprintf("temperature '%s' value is %s %s", $result->{sensName}, $result->{sensValue}, $result->{sensUnit})); } $self->{output}->perfdata_add(label => 'sensor_' . $result->{sensName}, unit => $result->{sensUnit}, - value => $result->{sensTemp}, + value => $result->{sensValue}, warning => $warn, critical => $crit); } } } -1; \ No newline at end of file +1; diff --git a/hardware/sensors/hwgste/snmp/mode/sensors.pm b/hardware/sensors/hwgste/snmp/mode/sensors.pm index 1f99d437e..e9842f010 100644 --- a/hardware/sensors/hwgste/snmp/mode/sensors.pm +++ b/hardware/sensors/hwgste/snmp/mode/sensors.pm @@ -24,6 +24,7 @@ use base qw(centreon::plugins::templates::hardware); use strict; use warnings; +use hardware::sensors::hwgste::snmp::mode::components::resources qw($mapping); sub set_system { my ($self, %options) = @_; @@ -52,9 +53,13 @@ sub snmp_execute { my ($self, %options) = @_; $self->{snmp} = $options{snmp}; - my $oid_sensEntry = '.1.3.6.1.4.1.21796.4.1.3.1'; - push @{$self->{request}}, { oid => $oid_sensEntry }; - $self->{results} = $self->{snmp}->get_multiple_table(oids => $self->{request}); + $self->{results} = $self->{snmp}->get_multiple_table( + oids => [{ oid => $mapping->{branch_sensors}->{hwgste} }, { oid => $mapping->{branch_sensors}->{hwgste2} }] + ); + $self->{branch} = 'hwgste'; + if (defined($self->{results}->{ $mapping->{branch_sensors}->{hwgste2} }) && scalar($self->{results}->{ $mapping->{branch_sensors}->{hwgste2} }) > 0) { + $self->{branch} = 'hwgste2'; + } } sub new { @@ -63,9 +68,8 @@ sub new { bless $self, $class; $self->{version} = '1.0'; - $options{options}->add_options(arguments => - { - }); + $options{options}->add_options(arguments => { + }); return $self; }