Debian Codegraph @

src/hardware/sensors/jacarta/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::jacarta::snmp::mode::components::temperature;
22
23 use strict;
24 use warnings;
25 use hardware::sensors::jacarta::snmp::mode::components::resources qw(%map_default_status %map_state);
26
27 sub load {}
28
29 sub check_inSeptPro {
30 my ($self) = @_;
31
32 my $mapping = {
33 name => { oid => '.1.3.6.1.4.1.19011.1.3.2.1.3.1.1.1.2' }, # isDeviceMonitorTemperatureName
34 current => { oid => '.1.3.6.1.4.1.19011.1.3.2.1.3.1.1.1.3' }, # isDeviceMonitorTemperature
35 alarm => { oid => '.1.3.6.1.4.1.19011.1.3.2.1.3.1.1.1.4', map => \%map_default_status } # isDeviceMonitorTemperatureAlarm
36 };
37 my $mapping_config = {
38 lowWarning => { oid => '.1.3.6.1.4.1.19011.1.3.2.1.3.2.2.1.3' }, # isDeviceConfigTemperatureLowWarning
39 lowCritical => { oid => '.1.3.6.1.4.1.19011.1.3.2.1.3.2.2.1.4' }, # isDeviceConfigTemperatureLowCritical
40 highWarning => { oid => '.1.3.6.1.4.1.19011.1.3.2.1.3.2.2.1.5' }, # isDeviceConfigTemperatureHighWarning
41 highCritical => { oid => '.1.3.6.1.4.1.19011.1.3.2.1.3.2.2.1.6' }, # isDeviceConfigTemperatureHighCritical
42 lowWarningState => { oid => '.1.3.6.1.4.1.19011.1.3.2.1.3.2.2.1.9', map => \%map_state }, # isDeviceConfigTemperatureLowWarningState
43 lowCriticalState => { oid => '.1.3.6.1.4.1.19011.1.3.2.1.3.2.2.1.10', map => \%map_state }, # isDeviceConfigTemperatureLowCriticalState
44 highWarningState => { oid => '.1.3.6.1.4.1.19011.1.3.2.1.3.2.2.1.11', map => \%map_state }, # isDeviceConfigTemperatureHighWarningState
45 highCriticalState => { oid => '.1.3.6.1.4.1.19011.1.3.2.1.3.2.2.1.12', map => \%map_state } # isDeviceConfigTemperatureHighCriticalState
46 };
47
48 my $oid_tempEntry = '.1.3.6.1.4.1.19011.1.3.2.1.3.1.1.1'; # isDeviceMonitorTemperatureEntry
49 my $oid_configTempEntry = '.1.3.6.1.4.1.19011.1.3.2.1.3.2.2.1'; # isDeviceConfigTemperatureEntry
50
51 my $snmp_result = $self->{snmp}->get_multiple_table(
52 oids => [
53 { oid => $oid_tempEntry, end => $mapping->{alarm}->{oid} } ,
54 { oid => $oid_configTempEntry, start => $mapping_config->{lowWarning}->{oid}, end => $mapping_config->{lowWarning}->{highCriticalState} }
55 ]
56 );
57
58 foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$snmp_result->{$oid_tempEntry}})) {
59 next if ($oid !~ /^$mapping->{alarm}->{oid}\.(.*)$/);
60 my $instance = $1;
61 my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $snmp_result->{$oid_tempEntry}, instance => $instance);
62 my $result2 = $self->{snmp}->map_instance(mapping => $mapping_config, results => $snmp_result->{$oid_configTempEntry}, instance => $instance);
63
64 next if ($self->check_filter(section => 'temperature', instance => $instance));
65 $self->{components}->{temperature}->{total}++;
66
67 $result->{current} *= 0.01;
68 $self->{output}->output_add(
69 long_msg => sprintf(
70 "temperature '%s' status is '%s' [instance: %s] [value: %s]",
71 $result->{name}, $result->{alarm}, $instance,
72 $result->{current}
73 )
74 );
75
76 my $exit = $self->get_severity(label => 'default', section => 'temperature', value => $result->{alarm});
77 if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) {
78 $self->{output}->output_add(
79 severity => $exit,
80 short_msg => sprintf("Temperature '%s' status is '%s'", $result->{name}, $result->{alarm})
81 );
82 }
83
84 my ($exit2, $warn, $crit, $checked) = $self->get_severity_numeric(section => 'temperature', instance => $instance, value => $result->{current});
85 if ($checked == 0) {
86 $result2->{lowWarning} = ($result2->{lowWarningState} eq 'enabled') ? $result2->{lowWarning} * 0.01 : '';
87 $result2->{lowCritical} = ($result2->{lowCriticalState} eq 'enabled') ? $result2->{lowCritical} * 0.01 : '';
88 $result2->{highWarning} = ($result2->{highWarningState} eq 'enabled') ? $result2->{highWarning} * 0.01 : '';
89 $result2->{highCritical} = ($result2->{highCriticalState} eq 'enabled') ? $result2->{highCritical} * 0.01 : '';
90 my $warn_th = $result2->{lowWarning} . ':' . $result2->{highWarning};
91 my $crit_th = $result2->{lowCritical} . ':' . $result2->{highCritical};
92 $self->{perfdata}->threshold_validate(label => 'warning-temperature-instance-' . $instance, value => $warn_th);
93 $self->{perfdata}->threshold_validate(label => 'critical-temperature-instance-' . $instance, value => $crit_th);
94
95 $warn = $self->{perfdata}->get_perfdata_for_output(label => 'warning-temperature-instance-' . $instance);
96 $crit = $self->{perfdata}->get_perfdata_for_output(label => 'critical-temperature-instance-' . $instance);
97 }
98
99 if (!$self->{output}->is_status(value => $exit2, compare => 'ok', litteral => 1)) {
100 $self->{output}->output_add(
101 severity => $exit2,
102 short_msg => sprintf("Temperature '%s' is %s %s", $result->{name}, $result->{current}, $self->{temperature_unit})
103 );
104 }
105 $self->{output}->perfdata_add(
106 nlabel => 'hardware.temperature.' . (($self->{temperature_unit} eq 'C') ? 'celsius' : 'fahrenheit'),
107 unit => $self->{temperature_unit},
108 instances => $result->{name},
109 value => $result->{current},
110 warning => $warn,
111 critical => $crit
112 );
113 }
114 }
115
116 sub check_inSept {
117 my ($self) = @_;
118
119 my $devices = $self->getInSeptDevices();
120
121 my $mapping = {
122 current => { oid => '.1.3.6.1.4.1.19011.1.3.1.1.3.2.1.3' }, # inSeptsensorMonitorDeviceTemperature
123 alarm => { oid => '.1.3.6.1.4.1.19011.1.3.1.1.3.2.1.4', map => \%map_default_status } # inSeptsensorMonitorDeviceTemperatureAlarm
124 };
125 my $mapping_config = {
126 1 => {
127 name => { oid => '.1.3.6.1.4.1.19011.1.3.1.1.4.3.3.1' }, # inSeptsensorConfigSensor1TemperatureName
128 lowWarning => { oid => '.1.3.6.1.4.1.19011.1.3.1.1.4.3.3.2' }, # inSeptsensorConfigSensor1TemperatureLowWarning
129 lowCritical => { oid => '.1.3.6.1.4.1.19011.1.3.1.1.4.3.3.3' }, # inSeptsensorConfigSensor1TemperatureLowCritical
130 highWarning => { oid => '.1.3.6.1.4.1.19011.1.3.1.1.4.3.3.4' }, # inSeptsensorConfigSensor1TemperatureHighWarning
131 highCritical => { oid => '.1.3.6.1.4.1.19011.1.3.1.1.4.3.3.5' }, # inSeptsensorConfigSensor1TemperatureHighCritical
132 lowWarningState => { oid => '.1.3.6.1.4.1.19011.1.3.1.1.4.3.3.8', map => \%map_state }, # inSeptsensorConfigSensor1TemperatureLowWarningStatus
133 lowCriticalState => { oid => '.1.3.6.1.4.1.19011.1.3.1.1.4.3.3.9', map => \%map_state }, # inSeptsensorConfigSensor1TemperatureLowCriticalStatus
134 highWarningState => { oid => '.1.3.6.1.4.1.19011.1.3.1.1.4.3.3.10', map => \%map_state }, # inSeptsensorConfigSensor1TemperatureHighWarningStatus
135 highCriticalState => { oid => '.1.3.6.1.4.1.19011.1.3.1.1.4.3.3.11', map => \%map_state } # inSeptsensorConfigSensor1TemperatureHighCriticalStatus
136 },
137 2 => {
138 name => { oid => '.1.3.6.1.4.1.19011.1.3.1.1.4.4.3.1' }, # inSeptsensorConfigSensor2TemperatureName
139 lowWarning => { oid => '.1.3.6.1.4.1.19011.1.3.1.1.4.4.3.2' }, # inSeptsensorConfigSensor2TemperatureLowWarning
140 lowCritical => { oid => '.1.3.6.1.4.1.19011.1.3.1.1.4.4.3.3' }, # inSeptsensorConfigSensor2TemperatureLowCritical
141 highWarning => { oid => '.1.3.6.1.4.1.19011.1.3.1.1.4.4.3.4' }, # inSeptsensorConfigSensor2TemperatureHighWarning
142 highCritical => { oid => '.1.3.6.1.4.1.19011.1.3.1.1.4.4.3.5' }, # inSeptsensorConfigSensor2TemperatureHighCritical
143 lowWarningState => { oid => '.1.3.6.1.4.1.19011.1.3.1.1.4.4.3.8', map => \%map_state }, # inSeptsensorConfigSensor2TemperatureLowWarningStatus
144 lowCriticalState => { oid => '.1.3.6.1.4.1.19011.1.3.1.1.4.4.3.9', map => \%map_state }, # inSeptsensorConfigSensor2TemperatureLowCriticalStatus
145 highWarningState => { oid => '.1.3.6.1.4.1.19011.1.3.1.1.4.4.3.10', map => \%map_state }, # inSeptsensorConfigSensor2TemperatureHighWarningStatus
146 highCriticalState => { oid => '.1.3.6.1.4.1.19011.1.3.1.1.4.4.3.11', map => \%map_state } # inSeptsensorConfigSensor2TemperatureHighCriticalStatus
147 }
148 };
149 my $oid_sensorEntry = '.1.3.6.1.4.1.19011.1.3.1.1.3.2.1'; # inSeptsensorMonitorSensorEntry
150
151 my $snmp_result = $self->{snmp}->get_table(oid => $oid_sensorEntry, start => $mapping->{current}->{oid}, end => $mapping->{alarm}->{oid});
152 foreach my $oid ($self->{snmp}->oid_lex_sort(keys %$snmp_result)) {
153 next if ($oid !~ /^$mapping->{alarm}->{oid}\.(.*)$/);
154 my $instance = $1;
155
156 next if (!defined($devices->{$instance}) || $devices->{$instance}->{state} eq 'disabled');
157
158 my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $snmp_result, instance => $instance);
159
160 my $snmp_config = $self->{snmp}->get_leef(oids => [ map($_->{oid} . '.0', values(%{$mapping_config->{$instance}})) ]);
161 my $result2 = $self->{snmp}->map_instance(mapping => $mapping_config->{$instance}, results => $snmp_config, instance => 0);
162
163 next if ($self->check_filter(section => 'temperature', instance => $instance));
164 $self->{components}->{temperature}->{total}++;
165
166 $result->{current} *= 0.1;
167 $self->{output}->output_add(
168 long_msg => sprintf(
169 "temperature '%s' status is '%s' [instance: %s] [value: %s]",
170 $result2->{name}, $result->{alarm}, $instance,
171 $result->{current}
172 )
173 );
174
175 my $exit = $self->get_severity(label => 'default', section => 'temperature', value => $result->{alarm});
176 if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) {
177 $self->{output}->output_add(
178 severity => $exit,
179 short_msg => sprintf("Temperature '%s' status is '%s'", $result2->{name}, $result->{alarm})
180 );
181 }
182
183 my ($exit2, $warn, $crit, $checked) = $self->get_severity_numeric(section => 'temperature', instance => $instance, value => $result->{current});
184 if ($checked == 0) {
185 $result2->{lowWarning} = ($result2->{lowWarningState} eq 'enabled') ? $result2->{lowWarning} * 0.1 : '';
186 $result2->{lowCritical} = ($result2->{lowCriticalState} eq 'enabled') ? $result2->{lowCritical} * 0.1 : '';
187 $result2->{highWarning} = ($result2->{highWarningState} eq 'enabled') ? $result2->{highWarning} * 0.1 : '';
188 $result2->{highCritical} = ($result2->{highCriticalState} eq 'enabled') ? $result2->{highCritical} * 0.1 : '';
189 my $warn_th = $result2->{lowWarning} . ':' . $result2->{highWarning};
190 my $crit_th = $result2->{lowCritical} . ':' . $result2->{highCritical};
191 $self->{perfdata}->threshold_validate(label => 'warning-temperature-instance-' . $instance, value => $warn_th);
192 $self->{perfdata}->threshold_validate(label => 'critical-temperature-instance-' . $instance, value => $crit_th);
193
194 $warn = $self->{perfdata}->get_perfdata_for_output(label => 'warning-temperature-instance-' . $instance);
195 $crit = $self->{perfdata}->get_perfdata_for_output(label => 'critical-temperature-instance-' . $instance);
196 }
197
198 if (!$self->{output}->is_status(value => $exit2, compare => 'ok', litteral => 1)) {
199 $self->{output}->output_add(
200 severity => $exit2,
201 short_msg => sprintf("Temperature '%s' is %s %s", $result2->{name}, $result->{current}, $self->{temperature_unit})
202 );
203 }
204 $self->{output}->perfdata_add(
205 nlabel => 'hardware.temperature.' . (($self->{temperature_unit} eq 'C') ? 'celsius' : 'fahrenheit'),
206 unit => $self->{temperature_unit},
207 instances => $result2->{name},
208 value => $result->{current},
209 warning => $warn,
210 critical => $crit
211 );
212 }
213 }
214
215 sub check {
216 my ($self) = @_;
217
218 $self->{output}->output_add(long_msg => "Checking temperatures");
219 $self->{components}->{temperature} = {name => 'temperatures', total => 0, skip => 0};
220 return if ($self->check_filter(section => 'temperature'));
221
222 check_inSeptPro($self) if ($self->{inSeptPro} == 1);
223 check_inSept($self) if ($self->{inSept} == 1);
224 }
225
226 1;