Debian Codegraph @

src/centreon/common/broadcom/megaraid/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::broadcom::megaraid::snmp::mode::components::temperature;
22
23 use strict;
24 use warnings;
25
26 my %map_temp_status = (
27 1 => 'status-invalid', 2 => 'status-ok', 3 => 'status-critical', 4 => 'status-nonCritical',
28 5 => 'status-unrecoverable', 6 => 'status-not-installed', 7 => 'status-unknown', 8 => 'status-not-available'
29 );
30
31 my $mapping = {
32 enclosureId_ETST => { oid => '.1.3.6.1.4.1.3582.4.1.5.6.1.2' },
33 tempSensorStatus => { oid => '.1.3.6.1.4.1.3582.4.1.5.6.1.3', map => \%map_temp_status },
34 enclosureTemperature => { oid => '.1.3.6.1.4.1.3582.4.1.5.6.1.4' },
35 };
36 my $oid_enclosureTempSensorEntry = '.1.3.6.1.4.1.3582.4.1.5.6.1';
37
38 sub load {
39 my ($self) = @_;
40
41 push @{$self->{request}}, { oid => $oid_enclosureTempSensorEntry, start => $mapping->{enclosureId_ETST}->{oid},
42 end => $mapping->{enclosureTemperature}->{oid} };
43 }
44
45 sub check {
46 my ($self) = @_;
47
48 $self->{output}->output_add(long_msg => "Checking temperatures");
49 $self->{components}->{temperature} = {name => 'temperatures', total => 0, skip => 0};
50 return if ($self->check_filter(section => 'temperature'));
51
52 my ($exit, $warn, $crit, $checked);
53 foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$self->{results}->{$oid_enclosureTempSensorEntry}})) {
54 next if ($oid !~ /^$mapping->{tempSensorStatus}->{oid}\.(.*)$/);
55 my $instance = $1;
56 my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}->{$oid_enclosureTempSensorEntry}, instance => $instance);
57
58 next if ($self->check_filter(section => 'temperature', instance => $instance));
59 if ($result->{tempSensorStatus} =~ /status-not-installed/i) {
60 $self->absent_problem(section => 'temperature', instance => $instance);
61 next;
62 }
63
64 $self->{components}->{temperature}->{total}++;
65 $self->{output}->output_add(long_msg => sprintf("Temperature '%s' status is '%s' [instance = %s, enclosure = %s, temperature = %s C]",
66 $instance, $result->{tempSensorStatus}, $instance, $result->{enclosureId_ETST},
67 defined($result->{enclosureTemperature}) ? $result->{enclosureTemperature} : 'unknown'));
68 $exit = $self->get_severity(section => 'default', value => $result->{tempSensorStatus});
69 if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) {
70 $self->{output}->output_add(severity => $exit,
71 short_msg => sprintf("Temperature '%s' status is '%s'", $instance, $result->{tempSensorStatus}));
72 }
73
74 next if (!defined($result->{enclosureTemperature}) || $result->{enclosureTemperature} !~ /[0-9]+/);
75
76 ($exit, $warn, $crit, $checked) = $self->get_severity_numeric(section => 'temperature', instance => $instance, value => $result->{enclosureTemperature});
77 if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) {
78 $self->{output}->output_add(severity => $exit,
79 short_msg => sprintf("Temperature '%s' is '%s' C", $instance, $result->{enclosureTemperature}));
80 }
81 $self->{output}->perfdata_add(
82 label => 'temp', unit => 'C',
83 nlabel => 'hardware.temperature.celsius',
84 instances => $instance,
85 value => $result->{enclosureTemperature},
86 warning => $warn,
87 critical => $crit,
88 );
89 }
90 }
91
92 1;