| 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::sensors::netbotz::snmp::mode::components::humidity; |
| 22 |
|
| 23 |
use strict; |
| 24 |
use warnings; |
| 25 |
use hardware::sensors::netbotz::snmp::mode::components::resources qw($map_status); |
| 26 |
|
| 27 |
sub load { |
| 28 |
my ($self) = @_; |
| 29 |
|
| 30 |
$self->{mapping_humidity} = { |
| 31 |
humiSensorId => { oid => '.1.3.6.1.4.1.' . $self->{netbotz_branch} . '.4.1.2.1.1' }, |
| 32 |
humiSensorValue => { oid => '.1.3.6.1.4.1.' . $self->{netbotz_branch} . '.4.1.2.1.2' }, |
| 33 |
humiSensorErrorStatus => { oid => '.1.3.6.1.4.1.' . $self->{netbotz_branch} . '.4.1.2.1.3', map => $map_status }, |
| 34 |
humiSensorLabel => { oid => '.1.3.6.1.4.1.' . $self->{netbotz_branch} . '.4.1.2.1.4' } |
| 35 |
}; |
| 36 |
$self->{oid_humiSensorEntry} = '.1.3.6.1.4.1.' . $self->{netbotz_branch} . '.4.1.2.1'; |
| 37 |
push @{$self->{request}}, { |
| 38 |
oid => $self->{oid_humiSensorEntry}, |
| 39 |
end => $self->{mapping_humidity}->{humiSensorLabel}->{oid} |
| 40 |
}; |
| 41 |
} |
| 42 |
|
| 43 |
sub check { |
| 44 |
my ($self) = @_; |
| 45 |
|
| 46 |
$self->{output}->output_add(long_msg => "Checking humidities"); |
| 47 |
$self->{components}->{humidity} = { name => 'humidity', total => 0, skip => 0 }; |
| 48 |
return if ($self->check_filter(section => 'humidity')); |
| 49 |
|
| 50 |
foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$self->{results}->{ $self->{oid_humiSensorEntry} }})) { |
| 51 |
next if ($oid !~ /^$self->{mapping_humidity}->{humiSensorErrorStatus}->{oid}\.(.*)$/); |
| 52 |
my $instance = $1; |
| 53 |
my $result = $self->{snmp}->map_instance( |
| 54 |
mapping => $self->{mapping_humidity}, |
| 55 |
results => $self->{results}->{ $self->{oid_humiSensorEntry} }, |
| 56 |
instance => $instance |
| 57 |
); |
| 58 |
|
| 59 |
next if ($self->check_filter(section => 'humidity', instance => $instance)); |
| 60 |
$self->{components}->{humidity}->{total}++; |
| 61 |
|
| 62 |
$result->{humiSensorValue} *= 0.1; |
| 63 |
my $label = defined($result->{humiSensorLabel}) && $result->{humiSensorLabel} ne '' ? $result->{humiSensorLabel} : $result->{humiSensorId}; |
| 64 |
$self->{output}->output_add( |
| 65 |
long_msg => sprintf( |
| 66 |
"humidity '%s' status is '%s' [instance = %s] [value = %s]", |
| 67 |
$label, |
| 68 |
$result->{humiSensorErrorStatus}, |
| 69 |
$instance, |
| 70 |
$result->{humiSensorValue} |
| 71 |
) |
| 72 |
); |
| 73 |
|
| 74 |
my $exit = $self->get_severity(label => 'default', section => 'humidity', value => $result->{humiSensorErrorStatus}); |
| 75 |
if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { |
| 76 |
$self->{output}->output_add( |
| 77 |
severity => $exit, |
| 78 |
short_msg => sprintf( |
| 79 |
"Humidity '%s' status is '%s'", |
| 80 |
$label, |
| 81 |
$result->{humiSensorErrorStatus} |
| 82 |
) |
| 83 |
); |
| 84 |
} |
| 85 |
|
| 86 |
my ($exit2, $warn, $crit, $checked) = $self->get_severity_numeric(section => 'humidity', instance => $instance, value => $result->{humiSensorValue}); |
| 87 |
if (!$self->{output}->is_status(value => $exit2, compare => 'ok', litteral => 1)) { |
| 88 |
$self->{output}->output_add( |
| 89 |
severity => $exit2, |
| 90 |
short_msg => sprintf( |
| 91 |
"Humidity '%s' is %s %%", |
| 92 |
$label, |
| 93 |
$result->{humiSensorValue} |
| 94 |
) |
| 95 |
); |
| 96 |
} |
| 97 |
|
| 98 |
$self->{output}->perfdata_add( |
| 99 |
label => 'humidity', unit => '%', |
| 100 |
nlabel => 'hardware.sensor.humidity.percentage', |
| 101 |
instances => $label, |
| 102 |
value => $result->{humiSensorValue}, |
| 103 |
warning => $warn, |
| 104 |
critical => $crit, min => 0, max => 100 |
| 105 |
); |
| 106 |
} |
| 107 |
} |
| 108 |
|
| 109 |
1; |