Debian Codegraph @

src/centreon/common/radlan/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 centreon::common::radlan::snmp::mode::components::temperature;
22
23 use strict;
24 use warnings;
25 use centreon::common::radlan::snmp::mode::components::resources qw($oid_rlPhdUnitEnvParamEntry);
26
27 my $map_entity_sensor = { 1 => 'ok', 2 => 'unavailable', 3 => 'nonoperational' };
28
29 my $mapping = {
30 new => {
31 rlPhdUnitEnvParamTempSensorValue => { oid => '.1.3.6.1.4.1.89.53.15.1.10' },
32 rlPhdUnitEnvParamTempSensorStatus => { oid => '.1.3.6.1.4.1.89.53.15.1.11', map => $map_entity_sensor },
33 rlPhdUnitEnvParamTempSensorWarningThresholdValue => { oid => '.1.3.6.1.4.1.89.53.15.1.12' },
34 rlPhdUnitEnvParamTempSensorCriticalThresholdValue => { oid => '.1.3.6.1.4.1.89.53.15.1.13' }
35 },
36 old => {
37 rlPhdUnitEnvParamTempSensorValue => { oid => '.1.3.6.1.4.1.89.53.15.1.9' },
38 rlPhdUnitEnvParamTempSensorStatus => { oid => '.1.3.6.1.4.1.89.53.15.1.10', map => $map_entity_sensor },
39 }
40 };
41
42 sub load {}
43
44 sub check {
45 my ($self) = @_;
46
47 $self->{output}->output_add(long_msg => "Checking temperatures");
48 $self->{components}->{temperature} = { name => 'temperatures', total => 0, skip => 0 };
49 return if ($self->check_filter(section => 'temperature'));
50
51 foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$self->{results}->{$oid_rlPhdUnitEnvParamEntry}})) {
52 next if ($oid !~ /^$mapping->{new}->{rlPhdUnitEnvParamTempSensorValue}->{oid}\.(.*)$/);
53 my $instance = $1;
54 my $result = $self->{snmp}->map_instance(
55 mapping => $self->{radlan_new} == 1 ? $mapping->{new} : $mapping->{old},
56 results => $self->{results}->{$oid_rlPhdUnitEnvParamEntry},
57 instance => $instance
58 );
59
60 next if ($self->check_filter(section => 'temperature', instance => $instance));
61 $self->{components}->{temperature}->{total}++;
62
63 $self->{output}->output_add(
64 long_msg => sprintf(
65 "temperature '%s' status is '%s' [instance = %s, value: %s degree centigrade]",
66 $instance,
67 $result->{rlPhdUnitEnvParamTempSensorStatus},
68 $instance,
69 $result->{rlPhdUnitEnvParamTempSensorValue}
70 )
71 );
72
73 my $exit = $self->get_severity(section => 'temperature', value => $result->{rlPhdUnitEnvParamTempSensorStatus});
74 if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) {
75 $self->{output}->output_add(
76 severity => $exit,
77 short_msg => sprintf(
78 "Temperature '%s' status is '%s'",
79 $instance,
80 $result->{rlPhdUnitEnvParamTempSensorStatus}
81 )
82 );
83 }
84
85 my ($exit2, $warn, $crit, $checked) = $self->get_severity_numeric(section => 'temperature', instance => $instance, value => $result->{rlPhdUnitEnvParamTempSensorValue});
86 if ($checked == 0 && defined($result->{rlPhdUnitEnvParamTempSensorWarningThresholdValue})) {
87 my $warn_th = ':' . $result->{rlPhdUnitEnvParamTempSensorWarningThresholdValue};
88 my $crit_th = ':' . $result->{rlPhdUnitEnvParamTempSensorCriticalThresholdValue};
89 $self->{perfdata}->threshold_validate(label => 'warning-temperature-instance-' . $instance, value => $warn_th);
90 $self->{perfdata}->threshold_validate(label => 'critical-temperature-instance-' . $instance, value => $crit_th);
91
92 $exit2 = $self->{perfdata}->threshold_check(
93 value => $result->{rlPhdUnitEnvParamTempSensorValue},
94 threshold => [
95 { label => 'critical-temperature-instance-' . $instance, exit_litteral => 'critical' },
96 { label => 'warning-temperature-instance-' . $instance, exit_litteral => 'warning' }
97 ]
98 );
99 $warn = $self->{perfdata}->get_perfdata_for_output(label => 'warning-temperature-instance-' . $instance);
100 $crit = $self->{perfdata}->get_perfdata_for_output(label => 'critical-temperature-instance-' . $instance);
101 }
102
103 if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) {
104 $self->{output}->output_add(
105 severity => $exit2,
106 short_msg => sprintf(
107 "Temperature '%s' is %s degree centigrade",
108 $instance,
109 $result->{rlPhdUnitEnvParamTempSensorValue}
110 )
111 );
112 }
113 $self->{output}->perfdata_add(
114 label => 'temp', unit => 'C',
115 nlabel => 'hardware.temperature.celsius',
116 instances => $instance,
117 value => $result->{rlPhdUnitEnvParamTempSensorValue},
118 warning => $warn,
119 critical => $crit
120 );
121 }
122 }
123
124 1;