Debian Codegraph @

src/centreon/common/dell/fastpath/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::dell::fastpath::snmp::mode::components::temperature;
22
23 use strict;
24 use warnings;
25
26 my %map_temp_status = (
27 0 => 'low',
28 1 => 'normal',
29 2 => 'warning',
30 3 => 'critical',
31 4 => 'shutdown',
32 5 => 'notpresent',
33 6 => 'notoperational'
34 );
35
36 my $mapping1 = {
37 boxServicesTempSensorState => { oid => '.1.3.6.1.4.1.674.10895.5000.2.6132.1.1.43.1.8.1.3', map => \%map_temp_status },
38 boxServicesTempSensorTemperature => { oid => '.1.3.6.1.4.1.674.10895.5000.2.6132.1.1.43.1.8.1.4' }
39 };
40 my $mapping2 = {
41 boxServicesTempSensorState => { oid => '.1.3.6.1.4.1.674.10895.5000.2.6132.1.1.43.1.8.1.4', map => \%map_temp_status },
42 boxServicesTempSensorTemperature => { oid => '.1.3.6.1.4.1.674.10895.5000.2.6132.1.1.43.1.8.1.5' }
43 };
44 my $oid_boxServicesTempSensorsEntry = '.1.3.6.1.4.1.674.10895.5000.2.6132.1.1.43.1.8.1';
45
46 sub load {
47 my ($self) = @_;
48
49 push @{$self->{request}}, { oid => $oid_boxServicesTempSensorsEntry };
50 }
51
52 sub check {
53 my ($self) = @_;
54
55 $self->{output}->output_add(long_msg => "Checking temperatures");
56 $self->{components}->{temperature} = {name => 'temperatures', total => 0, skip => 0};
57 return if ($self->check_filter(section => 'temperature'));
58
59 my ($result, $exit, $warn, $crit, $checked);
60 foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$self->{results}->{$oid_boxServicesTempSensorsEntry}})) {
61 next if ($oid !~ /^$mapping2->{boxServicesTempSensorState}->{oid}\.(.*)$/);
62 my $instance = $1;
63
64 if (defined($self->{results}->{$oid_boxServicesTempSensorsEntry}->{$mapping2->{boxServicesTempSensorTemperature}->{oid} . '.' . $instance})) {
65 $result = $self->{snmp}->map_instance(mapping => $mapping2, results => $self->{results}->{$oid_boxServicesTempSensorsEntry}, instance => $instance);
66 } else {
67 $result = $self->{snmp}->map_instance(mapping => $mapping1, results => $self->{results}->{$oid_boxServicesTempSensorsEntry}, instance => $instance);
68 }
69
70 next if ($self->check_filter(section => 'temperature', instance => $instance));
71 if ($result->{boxServicesTempSensorState} =~ /notPresent/i) {
72 $self->absent_problem(section => 'temperature', instance => $instance);
73 next;
74 }
75
76 $self->{components}->{temperature}->{total}++;
77 $self->{output}->output_add(
78 long_msg => sprintf(
79 "temperature '%s' status is '%s' [instance = %s, temperature = %s]",
80 $instance, $result->{boxServicesTempSensorState}, $instance, defined($result->{boxServicesTempSensorTemperature}) ? $result->{boxServicesTempSensorTemperature} : 'unknown'
81 )
82 );
83 $exit = $self->get_severity(section => 'temperature', value => $result->{boxServicesTempSensorState});
84 if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) {
85 $self->{output}->output_add(
86 severity => $exit,
87 short_msg => sprintf("Temperature '%s' status is '%s'", $instance, $result->{boxServicesTempSensorState})
88 );
89 }
90
91 ($exit, $warn, $crit, $checked) = $self->get_severity_numeric(section => 'temperature', instance => $instance, value => $result->{boxServicesTempSensorTemperature});
92 if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) {
93 $self->{output}->output_add(
94 severity => $exit,
95 short_msg => sprintf("Temperature '%s' is '%s' C", $instance, $result->{boxServicesTempSensorTemperature})
96 );
97 }
98
99 $self->{output}->perfdata_add(
100 nlabel => 'hardware.temperature.celsius',
101 unit => 'C',
102 instances => $instance,
103 value => $result->{boxServicesTempSensorTemperature},
104 warning => $warn,
105 critical => $crit, min => 0
106 );
107 }
108 }
109
110 1;