Debian Codegraph @

src/hardware/sensors/akcp/snmp/mode/components/humidity.pm

raw
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::akcp::snmp::mode::components::humidity;
22
23 use strict;
24 use warnings;
25 use hardware::sensors::akcp::snmp::mode::components::resources qw(%map_default1_status %map_online);
26
27 my $mapping = {
28 HumidityDescription => { oid => '.1.3.6.1.4.1.3854.1.2.2.1.17.1.1' }, # hhmsSensorArrayHumidityDescription
29 HumidityPercent => { oid => '.1.3.6.1.4.1.3854.1.2.2.1.17.1.3' }, # hhmsSensorArrayHumidityPercent
30 HumidityStatus => { oid => '.1.3.6.1.4.1.3854.1.2.2.1.17.1.4', map => \%map_default1_status }, # hhmsSensorArrayHumidityStatus
31 HumidityOnline => { oid => '.1.3.6.1.4.1.3854.1.2.2.1.17.1.5', map => \%map_online }, # hhmsSensorArrayHumidityOnline
32 HumidityHighWarning => { oid => '.1.3.6.1.4.1.3854.1.2.2.1.17.1.7' }, # hhmsSensorArrayHumidityHighWarning
33 HumidityHighCritical => { oid => '.1.3.6.1.4.1.3854.1.2.2.1.17.1.8' }, # hhmsSensorArrayHumidityHighCritical
34 HumidityLowWarning => { oid => '.1.3.6.1.4.1.3854.1.2.2.1.17.1.9' }, # hhmsSensorArrayHumidityLowWarning
35 HumidityLowCritical => { oid => '.1.3.6.1.4.1.3854.1.2.2.1.17.1.10' }, # hhmsSensorArrayHumidityLowCritical
36 };
37 my $mapping2 = {
38 HumidityDescription => { oid => '.1.3.6.1.4.1.3854.3.5.3.1.2' }, # humidityDescription
39 HumidityPercent => { oid => '.1.3.6.1.4.1.3854.3.5.3.1.4' }, # humidityPercent
40 HumidityStatus => { oid => '.1.3.6.1.4.1.3854.3.5.3.1.6', map => \%map_default1_status }, # humidityStatus
41 HumidityOnline => { oid => '.1.3.6.1.4.1.3854.3.5.3.1.8', map => \%map_online }, # humidityGoOffline
42 HumidityHighWarning => { oid => '.1.3.6.1.4.1.3854.3.5.3.1.11' }, # humidityHighWarning
43 HumidityHighCritical => { oid => '.1.3.6.1.4.1.3854.3.5.3.1.12' }, # humidityHighCritical
44 HumidityLowWarning => { oid => '.1.3.6.1.4.1.3854.3.5.3.1.10' }, # humidityLowWarning
45 HumidityLowCritical => { oid => '.1.3.6.1.4.1.3854.3.5.3.1.9' }, # humidityLowCritical
46 };
47
48 my $oid_hhmsSensorArrayHumidityEntry = '.1.3.6.1.4.1.3854.1.2.2.1.17.1';
49 my $oid_humidityEntry = '.1.3.6.1.4.1.3854.3.5.3.1';
50
51 sub load {
52 my ($self) = @_;
53
54 push @{$self->{request}}, { oid => $oid_hhmsSensorArrayHumidityEntry },
55 { oid => $oid_humidityEntry, end => $mapping2->{HumidityHighCritical}->{oid} };
56 }
57
58 sub check_humidity {
59 my ($self, %options) = @_;
60
61 foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$self->{results}->{$options{entry}}})) {
62 next if ($oid !~ /^$options{mapping}->{HumidityOnline}->{oid}\.(.*)$/);
63 my $instance = $1;
64 my $result = $self->{snmp}->map_instance(mapping => $options{mapping}, results => $self->{results}->{$options{entry}}, instance => $instance);
65
66 next if ($self->check_filter(section => 'humidity', instance => $instance));
67 if ($result->{HumidityOnline} eq 'offline') {
68 $self->{output}->output_add(long_msg => sprintf("skipping '%s': is offline", $result->{HumidityDescription}));
69 next;
70 }
71 $self->{components}->{humidity}->{total}++;
72
73 $self->{output}->output_add(long_msg => sprintf("humidity '%s' status is '%s' [instance = %s] [value = %s]",
74 $result->{HumidityDescription}, $result->{HumidityStatus}, $instance,
75 $result->{HumidityPercent}));
76
77 my $exit = $self->get_severity(label => 'default1', section => 'humidity', value => $result->{HumidityStatus});
78 if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) {
79 $self->{output}->output_add(severity => $exit,
80 short_msg => sprintf("Humdity '%s' status is '%s'", $result->{HumidityDescription}, $result->{HumidityStatus}));
81 }
82
83 my ($exit2, $warn, $crit, $checked) = $self->get_severity_numeric(section => 'humidity', instance => $instance, value => $result->{HumidityPercent});
84 if ($checked == 0) {
85 $result->{HumidityLowWarning} = (defined($result->{HumidityLowWarning}) && $result->{HumidityLowWarning} =~ /[0-9]/) ?
86 $result->{HumidityLowWarning} : '';
87 $result->{HumidityLowCritical} = (defined($result->{HumidityLowCritical}) && $result->{HumidityLowCritical} =~ /[0-9]/) ?
88 $result->{HumidityLowCritical} : '';
89 $result->{HumidityHighWarning} = (defined($result->{HumidityHighWarning}) && $result->{HumidityHighWarning} =~ /[0-9]/) ?
90 $result->{HumidityHighWarning} : '';
91 $result->{HumidityHighCritical} = (defined($result->{HumidityHighCritical}) && $result->{HumidityHighCritical} =~ /[0-9]/) ?
92 $result->{HumidityHighCritical} : '';
93 my $warn_th = $result->{HumidityLowWarning} . ':' . $result->{HumidityHighWarning};
94 my $crit_th = $result->{HumidityLowCritical} . ':' . $result->{HumidityHighCritical};
95 $self->{perfdata}->threshold_validate(label => 'warning-humidity-instance-' . $instance, value => $warn_th);
96 $self->{perfdata}->threshold_validate(label => 'critical-humidity-instance-' . $instance, value => $crit_th);
97
98 $warn = $self->{perfdata}->get_perfdata_for_output(label => 'warning-humidity-instance-' . $instance);
99 $crit = $self->{perfdata}->get_perfdata_for_output(label => 'critical-humidity-instance-' . $instance);
100 }
101
102 if (!$self->{output}->is_status(value => $exit2, compare => 'ok', litteral => 1)) {
103 $self->{output}->output_add(severity => $exit2,
104 short_msg => sprintf("Humdity '%s' is %s %%", $result->{HumidityDescription}, $result->{HumidityPercent}));
105 }
106 $self->{output}->perfdata_add(
107 label => 'humidity', unit => '%',
108 nlabel => 'hardware.sensor.humidity.percentage',
109 instances => $result->{HumidityDescription},
110 value => $result->{HumidityPercent},
111 warning => $warn,
112 critical => $crit,
113 min => 0, max => 100
114 );
115 }
116 }
117
118 sub check {
119 my ($self) = @_;
120
121 $self->{output}->output_add(long_msg => "Checking humidities");
122 $self->{components}->{humidity} = {name => 'humidities', total => 0, skip => 0};
123 return if ($self->check_filter(section => 'humidity'));
124
125 check_humidity($self, entry => $oid_hhmsSensorArrayHumidityEntry, mapping => $mapping);
126 check_humidity($self, entry => $oid_humidityEntry, mapping => $mapping2);
127 }
128
129 1;