Debian Codegraph @

src/hardware/server/hp/bladechassis/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::server::hp::bladechassis::snmp::mode::components::temperature;
22
23 use strict;
24 use warnings;
25
26 my $map_conditions = {
27 1 => 'other',
28 2 => 'ok',
29 3 => 'degraded',
30 4 => 'failed',
31 };
32
33 my $map_temp_type = {
34 1 => 'other',
35 5 => 'blowout',
36 9 => 'caution',
37 15 => 'critical',
38 };
39
40 my $mapping = {
41 temp_name => { oid => '.1.3.6.1.4.1.232.22.2.3.1.2.1.4' }, # cpqRackCommonEnclosureTempSensorEnclosureName
42 temp_location => { oid => '.1.3.6.1.4.1.232.22.2.3.1.2.1.5' }, # cpqRackCommonEnclosureTempLocation
43 temp_current => { oid => '.1.3.6.1.4.1.232.22.2.3.1.2.1.6' }, # cpqRackCommonEnclosureTempCurrent
44 temp_threshold => { oid => '.1.3.6.1.4.1.232.22.2.3.1.2.1.7' }, # cpqRackCommonEnclosureTempThreshold
45 temp_condition => { oid => '.1.3.6.1.4.1.232.22.2.3.1.2.1.8', map => $map_conditions }, # cpqRackCommonEnclosureTempCondition
46 temp_type => { oid => '.1.3.6.1.4.1.232.22.2.3.1.2.1.9', map => $map_temp_type }, # cpqRackCommonEnclosureTempType
47 };
48
49 sub check {
50 my ($self) = @_;
51
52 $self->{components}->{temperature} = { name => 'temperatures', total => 0, skip => 0 };
53 $self->{output}->output_add(long_msg => "checking temperatures");
54 return if ($self->check_filter(section => 'temperature'));
55
56 my $oid_cpqRackCommonEnclosureTempSensorIndex = '.1.3.6.1.4.1.232.22.2.3.1.2.1.3';
57
58 my $snmp_result = $self->{snmp}->get_table(oid => $oid_cpqRackCommonEnclosureTempSensorIndex);
59 return if (scalar(keys %$snmp_result) <= 0);
60
61 my @get_oids = ();
62 my @oids_end = ();
63 foreach my $key ($self->{snmp}->oid_lex_sort(keys %$snmp_result)) {
64 $key =~ /^$oid_cpqRackCommonEnclosureTempSensorIndex\.(.*)$/;
65 my $oid_end = $1;
66 push @oids_end, $oid_end;
67 push @get_oids, map($_->{oid} . '.' . $oid_end, values(%$mapping));
68 }
69
70 $snmp_result = $self->{snmp}->get_leef(oids => \@get_oids);
71 foreach (@oids_end) {
72 my $temp_index = $_;
73 my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $snmp_result, instance => $temp_index);
74
75 if ($result->{temp_current} == -1) {
76 $self->{output}->output_add(long_msg => sprintf("skipping instance $temp_index: current -1"), debug => 1);
77 next;
78 }
79
80 next if ($self->check_filter(section => 'temperature', instance => $temp_index));
81
82 $self->{components}->{temperature}->{total}++;
83 $self->{output}->output_add(long_msg => sprintf("temperature '%s' status is %s [name: %s, location: %s] (value = %s, threshold = %s%s).",
84 $temp_index, $result->{temp_condition},
85 $result->{temp_name}, $result->{temp_location},
86 $result->{temp_current}, $result->{temp_threshold},
87 defined($result->{temp_type}) ? ", status type = " . $result->{temp_type} : ''));
88 my $exit = $self->get_severity(label => 'default', section => 'temperature', instance => $temp_index, value => $result->{temp_condition});
89 if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) {
90 $self->{output}->output_add(severity => $exit,
91 short_msg => sprintf("Temperature '%s' status is %s",
92 $temp_index, $result->{temp_condition}));
93 }
94
95 $self->{output}->perfdata_add(
96 label => "temp", unit => 'C',
97 nlabel => 'hardware.temperature.celsius',
98 instances => $temp_index,
99 value => $result->{temp_current},
100 warning => $result->{temp_threshold}
101 );
102 }
103 }
104
105 1;