Debian Codegraph @

src/storage/hp/lefthand/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 storage::hp::lefthand::snmp::mode::components::temperature;
22
23 use strict;
24 use warnings;
25 use storage::hp::lefthand::snmp::mode::components::resources qw($map_status);
26
27 my $mapping = {
28 infoTemperatureSensorName => { oid => '.1.3.6.1.4.1.9804.3.1.1.2.1.121.1.2' },
29 infoTemperatureSensorValue => { oid => '.1.3.6.1.4.1.9804.3.1.1.2.1.121.1.3' },
30 infoTemperatureSensorCritical => { oid => '.1.3.6.1.4.1.9804.3.1.1.2.1.121.1.4' },
31 infoTemperatureSensorLimit => { oid => '.1.3.6.1.4.1.9804.3.1.1.2.1.121.1.5' },
32 infoTemperatureSensorState => { oid => '.1.3.6.1.4.1.9804.3.1.1.2.1.121.1.90' },
33 infoTemperatureSensorStatus => { oid => '.1.3.6.1.4.1.9804.3.1.1.2.1.121.1.91', map => $map_status },
34 };
35 my $oid_infoTemperatureSensorEntry = '.1.3.6.1.4.1.9804.3.1.1.2.1.121.1';
36
37 sub load {
38 my ($self) = @_;
39
40 push @{$self->{request}}, { oid => $oid_infoTemperatureSensorEntry };
41 }
42
43 sub check {
44 my ($self) = @_;
45
46 $self->{output}->output_add(long_msg => "Checking temperature sensors");
47 $self->{components}->{temperature} = {name => 'temperature sensors', total => 0, skip => 0};
48 return if ($self->check_filter(section => 'temperature'));
49
50 foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$self->{results}->{$oid_infoTemperatureSensorEntry}})) {
51 next if ($oid !~ /^$mapping->{infoTemperatureSensorStatus}->{oid}\.(.*)$/);
52 my $instance = $1;
53 my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}->{$oid_infoTemperatureSensorEntry}, instance => $instance);
54
55 next if ($self->check_filter(section => 'temperature', instance => $instance));
56
57 $self->{components}->{temperature}->{total}++;
58 $self->{output}->output_add(long_msg => sprintf("temperature sensor '%s' status is '%s' [instance = %s, state = %s, temperature = %s]",
59 $result->{infoTemperatureSensorName}, $result->{infoTemperatureSensorStatus}, $instance, $result->{infoTemperatureSensorState},
60 defined($result->{infoTemperatureSensorValue}) ? $result->{infoTemperatureSensorValue} : '-'));
61
62 my $exit = $self->get_severity(label => 'default', section => 'temperature', value => $result->{infoTemperatureSensorStatus});
63 if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) {
64 $self->{output}->output_add(severity => $exit,
65 short_msg => sprintf("temperature sensor '%s' state is '%s'", $result->{infoTemperatureSensorName}, $result->{infoTemperatureSensorState}));
66 }
67
68 next if (!defined($result->{infoTemperatureSensorValue}) || $result->{infoTemperatureSensorValue} !~ /[0-9]/);
69
70 my ($exit2, $warn, $crit, $checked) = $self->get_severity_numeric(section => 'temperature', instance => $instance, value => $result->{infoTemperatureSensorValue});
71 if ($checked == 0) {
72 my $warn_th = '';
73 my $crit_th = defined($result->{infoTemperatureSensorCritical}) ? $result->{infoTemperatureSensorCritical} : '';
74 $self->{perfdata}->threshold_validate(label => 'warning-temperature-instance-' . $instance, value => $warn_th);
75 $self->{perfdata}->threshold_validate(label => 'critical-temperature-instance-' . $instance, value => $crit_th);
76
77 $exit = $self->{perfdata}->threshold_check(
78 value => $result->{infoTemperatureSensorValue},
79 threshold => [ { label => 'critical-temperature-instance-' . $instance, exit_litteral => 'critical' },
80 { label => 'warning-temperature-instance-' . $instance, exit_litteral => 'warning' } ]);
81 $warn = $self->{perfdata}->get_perfdata_for_output(label => 'warning-temperature-instance-' . $instance);
82 $crit = $self->{perfdata}->get_perfdata_for_output(label => 'critical-temperature-instance-' . $instance)
83 }
84
85 if (!$self->{output}->is_status(value => $exit2, compare => 'ok', litteral => 1)) {
86 $self->{output}->output_add(severity => $exit2,
87 short_msg => sprintf("temperature sensor '%s' is %s C", $result->{infoTemperatureSensorName}, $result->{infoTemperatureSensorValue}));
88 }
89 $self->{output}->perfdata_add(
90 label => 'temp', unit => 'C',
91 nlabel => 'hardware.temperature.celsius',
92 instances => $result->{infoTemperatureSensorName},
93 value => $result->{infoTemperatureSensorValue},
94 warning => $warn,
95 critical => $crit,
96 max => $result->{infoTemperatureSensorLimit}
97 );
98 }
99 }
100
101 1;