Debian Codegraph @

src/network/lenovo/flexsystem/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 network::lenovo::flexsystem::snmp::mode::components::temperature;
22
23 use strict;
24 use warnings;
25
26 my $mapping = {
27 hwInfoTemperatureWarn => { oid => '.1.3.6.1.4.1.20301.2.5.1.3.1.41.1.1.20' }, # "44 C (Warning at 66 C / Recover at 61 C)"
28 hwInfoTemperatureShut => { oid => '.1.3.6.1.4.1.20301.2.5.1.3.1.41.1.1.21' }, # "44 C (Shutdown at 72 C / Recover at 67 C)"
29 };
30 my $oid_hwInfoTableEntry = '.1.3.6.1.4.1.20301.2.5.1.3.1.41.1.1';
31
32 sub load {
33 my ($self) = @_;
34
35 push @{$self->{request}}, {
36 oid => $oid_hwInfoTableEntry,
37 start => $mapping->{hwInfoTemperatureWarn}->{oid},
38 end => $mapping->{hwInfoTemperatureShut}->{oid}
39 };
40 }
41
42 sub check {
43 my ($self) = @_;
44
45 $self->{output}->output_add(long_msg => "checking temperatures");
46 $self->{components}->{temperature} = { name => 'temperatures', total => 0, skip => 0 };
47 return if ($self->check_filter(section => 'temperature'));
48
49 foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$self->{results}->{$oid_hwInfoTableEntry}})) {
50 next if ($oid !~ /^$mapping->{hwInfoTemperatureShut}->{oid}\.(\d+)$/);
51 my $instance = $1;
52 my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}->{$oid_hwInfoTableEntry}, instance => $instance);
53
54 next if ($self->check_filter(section => 'temperature', instance => $instance));
55 $self->{components}->{temperature}->{total}++;
56
57 $result->{hwInfoTemperatureWarn} =~ /^([.0-9]+)\s*C\s*\(Warn(?:ing)?\s*at\s*([.0-9]+)\s*C/i;
58 my ($temperature, $warning_mib) = ($1, $2);
59 $result->{hwInfoTemperatureShut} =~ /^([.0-9]+)\s*C\s*\(Shutdown\s*at\s*([.0-9]+)\s*C/i;
60 $temperature = $1 if ($1 > $temperature);
61 my $critical_mib = ($warning_mib + $2) / 2;
62
63 if ($warning_mib == $critical_mib) { #seen on some chassis !
64 $warning_mib -= 10;
65 $critical_mib -= 5;
66 }
67
68 $self->{output}->output_add(
69 long_msg => sprintf(
70 "temperature switch '%s' is %s C [instance: %s]",
71 $instance,
72 $temperature,
73 $instance
74 )
75 );
76
77 my ($exit, $warn, $crit, $checked) = $self->get_severity_numeric(section => 'temperature', instance => $instance, value => $temperature);
78 if ($checked == 0) {
79 $self->{perfdata}->threshold_validate(label => 'warning-temperature-instance-' . $instance, value => $warning_mib);
80 $self->{perfdata}->threshold_validate(label => 'critical-temperature-instance-' . $instance, value => $critical_mib);
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 $exit = $self->{perfdata}->threshold_check(
84 value => $temperature,
85 threshold => [
86 { label => 'critical-temperature-instance-' . $instance, exit_litteral => 'critical' },
87 { label => 'warning-temperature-instance-' . $instance, exit_litteral => 'warning' }
88 ]
89 );
90 }
91
92 if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) {
93 $self->{output}->output_add(
94 severity => $exit,
95 short_msg => sprintf(
96 "temperature switch '%s' is %s C",
97 $instance,
98 $temperature
99 )
100 );
101 }
102 $self->{output}->perfdata_add(
103 nlabel => 'hardware.temperature.celsius', unit => 'C',
104 instances => 'switch' . $instance,
105 value => $temperature,
106 warning => $warn,
107 critical => $crit
108 );
109 }
110 }
111
112 1;