| 1 |
# |
| 2 |
# Copyright 2024 Centreon (http://www.centreon.com/) |
| 3 |
# |
| 4 |
# Centreon is a full-fledged industry-strength solution that meets |
| 5 |
# the needs in IT infrastructure and application monitoring for |
| 6 |
# service performance. |
| 7 |
# |
| 8 |
# Licensed under the Apache License, Version 2.0 (the "License"); |
| 9 |
# you may not use this file except in compliance with the License. |
| 10 |
# You may obtain a copy of the License at |
| 11 |
# |
| 12 |
# http://www.apache.org/licenses/LICENSE-2.0 |
| 13 |
# |
| 14 |
# Unless required by applicable law or agreed to in writing, software |
| 15 |
# distributed under the License is distributed on an "AS IS" BASIS, |
| 16 |
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 17 |
# See the License for the specific language governing permissions and |
| 18 |
# limitations under the License. |
| 19 |
# |
| 20 |
|
| 21 |
package hardware::pdu::schleifenbauer::gateway::snmp::mode::components::humidity; |
| 22 |
|
| 23 |
use strict; |
| 24 |
use warnings; |
| 25 |
use hardware::pdu::schleifenbauer::gateway::snmp::mode::components::resources qw($oid_pdumeasuresEntry $oid_deviceName $mapping); |
| 26 |
|
| 27 |
sub load {} |
| 28 |
|
| 29 |
sub check_humidity { |
| 30 |
my ($self, %options) = @_; |
| 31 |
|
| 32 |
my $description = $options{device_name}; |
| 33 |
$description .= '.' . ((defined($options{sensor_name}) && $options{sensor_name} ne '') ? $options{sensor_name} : $options{num}); |
| 34 |
|
| 35 |
next if ($self->check_filter(section => 'humidity', instance => $options{instance}, name => $description)); |
| 36 |
$self->{components}->{humidity}->{total}++; |
| 37 |
$self->{output}->output_add(long_msg => sprintf("humidity '%s' is %s %% [instance = %s]", |
| 38 |
$description, $options{value}, $options{instance})); |
| 39 |
|
| 40 |
my ($exit, $warn, $crit, $checked) = $self->get_severity_numeric(section => 'humidity', instance => $options{instance}, name => $description, value => $options{value}); |
| 41 |
|
| 42 |
if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { |
| 43 |
$self->{output}->output_add(severity => $exit, |
| 44 |
short_msg => sprintf("Humdity '%s' is %s %%", $description, $options{value})); |
| 45 |
} |
| 46 |
$self->{output}->perfdata_add( |
| 47 |
label => 'humidity', unit => '%', |
| 48 |
nlabel => 'hardware.sensor.humidity.percentage', |
| 49 |
instances => [$options{device_name}, (defined($options{sensor_name}) && $options{sensor_name} ne '') ? $options{sensor_name} : $options{num}], |
| 50 |
value => $options{value}, |
| 51 |
warning => $warn, |
| 52 |
critical => $crit, |
| 53 |
min => 0, max => 100 |
| 54 |
); |
| 55 |
} |
| 56 |
|
| 57 |
sub check { |
| 58 |
my ($self) = @_; |
| 59 |
|
| 60 |
$self->{output}->output_add(long_msg => "Checking humidity"); |
| 61 |
$self->{components}->{humidity} = { name => 'humidity', total => 0, skip => 0 }; |
| 62 |
return if ($self->check_filter(section => 'humidity')); |
| 63 |
|
| 64 |
foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$self->{results}->{$oid_deviceName}})) { |
| 65 |
$oid =~ /^$oid_deviceName.(.*)$/; |
| 66 |
my $instance = $1; |
| 67 |
my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}->{$oid_pdumeasuresEntry}, instance => $instance); |
| 68 |
|
| 69 |
for (my $i = 1; $i <= 16; $i++) { |
| 70 |
next if (!defined($result->{'sensor' . $i . 'Type'}) || $result->{'sensor' . $i . 'Type'} !~ /H/); |
| 71 |
check_humidity($self, |
| 72 |
instance => $instance, |
| 73 |
device_name => $self->{results}->{$oid_deviceName}->{$oid}, |
| 74 |
num => $i, |
| 75 |
value => $result->{'sensor' . $i . 'Value'}, |
| 76 |
sensor_name => $result->{'sensor' . $i . 'Name'}, |
| 77 |
); |
| 78 |
} |
| 79 |
} |
| 80 |
} |
| 81 |
|
| 82 |
1; |