This commit is contained in:
garnier-quentin 2019-03-29 09:37:12 +01:00
parent 3f92e41141
commit 9be46dafa0
4 changed files with 49 additions and 33 deletions

View File

@ -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;
1;

View File

@ -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;
1;

View File

@ -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;
1;

View File

@ -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;
}