Debian Codegraph @

src/hardware/sensors/apc/snmp/mode/components/temperature.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::temperature;
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_temp {
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 temp => { oid => '.1.3.6.1.4.1.318.1.1.10.4.2.3.1.5' }, # memSensorsTemperature
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 => 'temperature', 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 "temperature '%s' alarm status is %s [instance: %s] [value: %s] [comm: %s]",
66 $name,
67 $result->{alarmStatus},
68 $instance,
69 $result->{temp},
70 $result->{commStatus}
71 )
72 );
73
74 my $exit = $self->get_severity(label => 'default', section => 'temperature.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 "Temperature '%s' alarm status is %s",
80 $name,
81 $result->{alarmStatus}
82 )
83 );
84 }
85
86 $exit = $self->get_severity(label => 'default', section => 'temperature.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 "Temperature '%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 => 'temperature', instance => $instance, value => $result->{temp});
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 "Temperature '%s' is %s %s",
104 $name,
105 $result->{temp},
106 $self->{temp_unit}
107 )
108 );
109 }
110
111 $self->{output}->perfdata_add(
112 nlabel => 'hardware.sensor.temperature.' . ($self->{temp_unit} eq 'C' ? 'celsius' : 'fahrenheit'),
113 unit => $self->{temp_unit},
114 instances => $name,
115 value => $result->{temp},
116 warning => $warn,
117 critical => $crit
118 );
119 }
120 }
121
122 sub check_wireless_temp {
123 my ($self) = @_;
124
125 my $oid_wirelessSensorStatusTable = '.1.3.6.1.4.1.318.1.1.10.5.1.1';
126 my $oid_wirelessSensorStatusMinHumidityThresh = '.1.3.6.1.4.1.318.1.1.10.5.1.1.1.15';
127 my $mapping = {
128 name => { oid => '.1.3.6.1.4.1.318.1.1.10.5.1.1.1.3' }, # wirelessSensorStatusName
129 temp => { oid => '.1.3.6.1.4.1.318.1.1.10.5.1.1.1.5' }, # wirelessSensorStatusTemperature
130 highWarn => { oid => '.1.3.6.1.4.1.318.1.1.10.5.1.1.1.6' }, # wirelessSensorStatusHighTempThresh
131 lowWarn => { oid => '.1.3.6.1.4.1.318.1.1.10.5.1.1.1.7' }, # wirelessSensorStatusLowTempThresh
132 commStatus => { oid => '.1.3.6.1.4.1.318.1.1.10.5.1.1.1.11', map => $map_comm_status3 }, # wirelessSensorStatusCommStatus
133 highCrit => { oid => '.1.3.6.1.4.1.318.1.1.10.5.1.1.1.12' }, # wirelessSensorStatusHighTempThresh
134 lowCrit => { oid => '.1.3.6.1.4.1.318.1.1.10.5.1.1.1.13' } # wirelessSensorStatusLowTempThresh
135 };
136
137 my $snmp_result = $self->{snmp_wireless_sensors};
138 if ($self->{checked_wireless_sensors} == 0) {
139 $self->{snmp_wireless_sensors} = $self->{snmp}->get_table(oid => $oid_wirelessSensorStatusTable, end => $oid_wirelessSensorStatusMinHumidityThresh);
140 $self->{checked_wireless_sensors} = 1;
141 }
142
143 foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$self->{snmp_wireless_sensors}})) {
144 next if ($oid !~ /^$mapping->{commStatus}->{oid}\.(\d+)$/);
145
146 my $instance = $1;
147 my $result = $self->{snmp}->map_instance(
148 mapping => $mapping,
149 results => $self->{snmp_wireless_sensors},
150 instance => $instance
151 );
152
153 $instance = 'wireless.' . $instance;
154
155 next if ($self->check_filter(section => 'temperature', instance => $instance));
156 $self->{components}->{temperature}->{total}++;
157
158 my $name = $result->{name};
159 $result->{temp} *= 0.1;
160
161 $self->{output}->output_add(
162 long_msg => sprintf(
163 "temperature '%s' is %s %s [instance: %s] [comm: %s]",
164 $name,
165 $result->{temp},
166 $self->{temp_unit},
167 $instance,
168 $result->{commStatus}
169 )
170 );
171
172 my $exit = $self->get_severity(label => 'default', section => 'temperature.comm', value => $result->{commStatus});
173 if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) {
174 $self->{output}->output_add(
175 severity => $exit,
176 short_msg => sprintf(
177 "Temperature '%s' communication status is %s",
178 $name,
179 $result->{commStatus}
180 )
181 );
182 }
183
184 my ($exit2, $warn, $crit, $checked) = $self->get_severity_numeric(section => 'temperature', instance => $instance, value => $result->{temp});
185 if ($checked == 0) {
186 my $warn_th = ($result->{lowWarn} * 0.1) . ':' . ($result->{highCrit} * 0.1);
187 my $crit_th = ($result->{lowCrit} * 0.1) . ':' . ($result->{highCrit} * 0.1);
188 $self->{perfdata}->threshold_validate(label => 'warning-temperature-instance-' . $instance, value => $warn_th);
189 $self->{perfdata}->threshold_validate(label => 'critical-temperature-instance-' . $instance, value => $crit_th);
190 $warn = $self->{perfdata}->get_perfdata_for_output(label => 'warning-temperature-instance-' . $instance);
191 $crit = $self->{perfdata}->get_perfdata_for_output(label => 'critical-temperature-instance-' . $instance);
192 $exit = $self->{perfdata}->threshold_check(
193 value => $result->{temp},
194 threshold => [
195 { label => 'critical-temperature-instance-' . $instance, exit_litteral => 'critical' },
196 { label => 'warning-temperature-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 "Temperature '%s' is %s %s",
206 $name,
207 $result->{temp},
208 $self->{temp_unit}
209 )
210 );
211 }
212
213 $self->{output}->perfdata_add(
214 nlabel => 'hardware.sensor.temperature.' . ($self->{temp_unit} eq 'C' ? 'celsius' : 'fahrenheit'),
215 unit => $self->{temp_unit},
216 instances => $name,
217 value => $result->{temp},
218 warning => $warn,
219 critical => $crit
220 );
221 }
222 }
223
224 sub check {
225 my ($self) = @_;
226
227 $self->{output}->output_add(long_msg => "Checking temperatures");
228 $self->{components}->{temperature} = { name => 'temperatures', total => 0, skip => 0 };
229 return if ($self->check_filter(section => 'temperature'));
230
231 check_module_temp($self);
232 check_wireless_temp($self);
233 }
234
235 1;