Debian Codegraph @

src/hardware/sensors/apc/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::apc::snmp::mode::components::humidity;
22
23 use strict;
24 use warnings;
25 use hardware::sensors::apc::snmp::mode::components::resources qw($map_alarm_status $map_comm_status $map_comm_status3);
26
27 sub load {}
28
29 sub check_module_humidity {
30 my ($self) = @_;
31
32 my $oid_memSensorsStatusTable = '.1.3.6.1.4.1.318.1.1.10.4.2.3';
33 my $mapping = {
34 name => { oid => '.1.3.6.1.4.1.318.1.1.10.4.2.3.1.3' }, # memSensorsStatusSensorName
35 humidity => { oid => '.1.3.6.1.4.1.318.1.1.10.4.2.3.1.6' }, # memSensorsHumidity
36 commStatus => { oid => '.1.3.6.1.4.1.318.1.1.10.4.2.3.1.7', map => $map_comm_status }, # memSensorsCommStatus
37 alarmStatus => { oid => '.1.3.6.1.4.1.318.1.1.10.4.2.3.1.8', map => $map_alarm_status } # memSensorsAlarmStatus
38 };
39
40 my $snmp_result = $self->{snmp_module_sensors};
41 if ($self->{checked_module_sensors} == 0) {
42 $self->{snmp_module_sensors} = $self->{snmp}->get_table(oid => $oid_memSensorsStatusTable);
43 $self->{checked_module_sensors} = 1;
44 }
45
46 foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$self->{snmp_module_sensors}})) {
47 next if ($oid !~ /^$mapping->{alarmStatus}->{oid}\.(\d+)\.(\d+)$/);
48
49 my $module_name = $self->{modules_name}->{$1};
50 my $instance = $1 . '.' . $2;
51 my $result = $self->{snmp}->map_instance(
52 mapping => $mapping,
53 results => $self->{snmp_module_sensors},
54 instance => $instance
55 );
56
57 $instance = 'module.' . $instance;
58
59 next if ($self->check_filter(section => 'humidity', instance => $instance));
60 $self->{components}->{temperature}->{total}++;
61
62 my $name = $module_name . ':' . $result->{name};
63 $self->{output}->output_add(
64 long_msg => sprintf(
65 "humidity '%s' alarm status is %s [instance: %s] [value: %s] [comm: %s]",
66 $name,
67 $result->{alarmStatus},
68 $instance,
69 $result->{humidity},
70 $result->{commStatus}
71 )
72 );
73
74 my $exit = $self->get_severity(label => 'default', section => 'humidity.alarm', value => $result->{alarmStatus});
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' alarm status is %s",
80 $name,
81 $result->{alarmStatus}
82 )
83 );
84 }
85
86 $exit = $self->get_severity(label => 'default', section => 'humidity.comm', value => $result->{commStatus});
87 if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) {
88 $self->{output}->output_add(
89 severity => $exit,
90 short_msg => sprintf(
91 "Humidity '%s' communication status is %s",
92 $name,
93 $result->{commStatus}
94 )
95 );
96 }
97
98 my ($exit2, $warn, $crit, $checked) = $self->get_severity_numeric(section => 'humidity', instance => $instance, value => $result->{humidity});
99 if (!$self->{output}->is_status(value => $exit2, compare => 'ok', litteral => 1)) {
100 $self->{output}->output_add(
101 severity => $exit2,
102 short_msg => sprintf(
103 "Humidity '%s' is %s %%",
104 $name,
105 $result->{humidity}
106 )
107 );
108 }
109
110 $self->{output}->perfdata_add(
111 nlabel => 'hardware.sensor.humidity.percentage',
112 unit => '%',
113 instances => $name,
114 value => $result->{humidity},
115 warning => $warn,
116 critical => $crit,
117 min => 0,
118 max => 100
119 );
120 }
121 }
122
123 sub check_wireless_humidity {
124 my ($self) = @_;
125
126 my $oid_wirelessSensorStatusTable = '.1.3.6.1.4.1.318.1.1.10.5.1.1';
127 my $oid_wirelessSensorStatusMinHumidityThresh = '.1.3.6.1.4.1.318.1.1.10.5.1.1.1.15';
128 my $mapping = {
129 name => { oid => '.1.3.6.1.4.1.318.1.1.10.5.1.1.1.3' }, # wirelessSensorStatusName
130 humidity => { oid => '.1.3.6.1.4.1.318.1.1.10.5.1.1.1.8' }, # wirelessSensorStatusHumidity
131 highWarn => { oid => '.1.3.6.1.4.1.318.1.1.10.5.1.1.1.9' }, # wirelessSensorStatusHighHumidityThresh
132 lowWarn => { oid => '.1.3.6.1.4.1.318.1.1.10.5.1.1.1.10' }, # wirelessSensorStatusLowHumidityThresh
133 commStatus => { oid => '.1.3.6.1.4.1.318.1.1.10.5.1.1.1.11', map => $map_comm_status3 }, # wirelessSensorStatusCommStatus
134 highCrit => { oid => '.1.3.6.1.4.1.318.1.1.10.5.1.1.1.14' }, # wirelessSensorStatusMaxHumidityThresh
135 lowCrit => { oid => '.1.3.6.1.4.1.318.1.1.10.5.1.1.1.15' } # wirelessSensorStatusMinHumidityThresh
136 };
137
138 my $snmp_result = $self->{snmp_wireless_sensors};
139 if ($self->{checked_wireless_sensors} == 0) {
140 $self->{snmp_wireless_sensors} = $self->{snmp}->get_table(oid => $oid_wirelessSensorStatusTable, end => $oid_wirelessSensorStatusMinHumidityThresh);
141 $self->{checked_wireless_sensors} = 1;
142 }
143
144 foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$self->{snmp_wireless_sensors}})) {
145 next if ($oid !~ /^$mapping->{commStatus}->{oid}\.(\d+)$/);
146
147 my $instance = $1;
148 my $result = $self->{snmp}->map_instance(
149 mapping => $mapping,
150 results => $self->{snmp_wireless_sensors},
151 instance => $instance
152 );
153
154 $instance = 'wireless.' . $instance;
155
156 next if ($self->check_filter(section => 'humidity', instance => $instance));
157 $self->{components}->{humidity}->{total}++;
158
159 my $name = $result->{name};
160 $self->{output}->output_add(
161 long_msg => sprintf(
162 "humidity '%s' is %s %% [instance: %s] [comm: %s]",
163 $name,
164 $result->{humidity},
165 $instance,
166 $result->{commStatus}
167 )
168 );
169
170 my $exit = $self->get_severity(label => 'default', section => 'humdity.comm', value => $result->{commStatus});
171 if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) {
172 $self->{output}->output_add(
173 severity => $exit,
174 short_msg => sprintf(
175 "Humidity '%s' communication status is %s",
176 $name,
177 $result->{commStatus}
178 )
179 );
180 }
181
182 next if ($result->{humidity} == -1);
183
184 my ($exit2, $warn, $crit, $checked) = $self->get_severity_numeric(section => 'humidity', instance => $instance, value => $result->{humidity});
185 if ($checked == 0) {
186 my $warn_th = ($result->{lowWarn}) . ':' . ($result->{highCrit});
187 my $crit_th = ($result->{lowCrit}) . ':' . ($result->{highCrit});
188 $self->{perfdata}->threshold_validate(label => 'warning-humidity-instance-' . $instance, value => $warn_th);
189 $self->{perfdata}->threshold_validate(label => 'critical-humidity-instance-' . $instance, value => $crit_th);
190 $warn = $self->{perfdata}->get_perfdata_for_output(label => 'warning-humidity-instance-' . $instance);
191 $crit = $self->{perfdata}->get_perfdata_for_output(label => 'critical-humidity-instance-' . $instance);
192 $exit = $self->{perfdata}->threshold_check(
193 value => $result->{humidity},
194 threshold => [
195 { label => 'critical-humidity-instance-' . $instance, exit_litteral => 'critical' },
196 { label => 'warning-humidity-instance-' . $instance, exit_litteral => 'warning' }
197 ]
198 );
199 }
200
201 if (!$self->{output}->is_status(value => $exit2, compare => 'ok', litteral => 1)) {
202 $self->{output}->output_add(
203 severity => $exit2,
204 short_msg => sprintf(
205 "Humidity '%s' is %s %%",
206 $name,
207 $result->{humidity}
208 )
209 );
210 }
211
212 $self->{output}->perfdata_add(
213 nlabel => 'hardware.sensor.humidity.percentage',
214 unit => '%',
215 instances => $name,
216 value => $result->{humidity},
217 warning => $warn,
218 critical => $crit,
219 min => 0,
220 max => 100
221 );
222 }
223 }
224
225 sub check {
226 my ($self) = @_;
227
228 $self->{output}->output_add(long_msg => "Checking humidities");
229 $self->{components}->{humidity} = { name => 'humidity', total => 0, skip => 0 };
230 return if ($self->check_filter(section => 'humidity'));
231
232 check_module_humidity($self);
233 check_wireless_humidity($self);
234 }
235
236 1;