Debian Codegraph @

src/hardware/sensors/akcp/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::sensors::akcp::snmp::mode::components::temperature;
22
23 use strict;
24 use warnings;
25 use hardware::sensors::akcp::snmp::mode::components::resources qw(%map_default1_status %map_online %map_degree_type);
26
27 my $mapping = {
28 TempDescription => { oid => '.1.3.6.1.4.1.3854.1.2.2.1.16.1.1' }, # hhmsSensorArrayTempDescription
29 TempDegree => { oid => '.1.3.6.1.4.1.3854.1.2.2.1.16.1.3' }, # hhmsSensorArrayTempDegree
30 TempStatus => { oid => '.1.3.6.1.4.1.3854.1.2.2.1.16.1.4', map => \%map_default1_status }, # hhmsSensorArrayTempStatus
31 TempOnline => { oid => '.1.3.6.1.4.1.3854.1.2.2.1.16.1.5', map => \%map_online }, # hhmsSensorArrayTempOnline
32 TempHighWarning => { oid => '.1.3.6.1.4.1.3854.1.2.2.1.16.1.7' }, # hhmsSensorArrayTempHighWarning
33 TempHighCritical => { oid => '.1.3.6.1.4.1.3854.1.2.2.1.16.1.8' }, # hhmsSensorArrayTempHighCritical
34 TempLowWarning => { oid => '.1.3.6.1.4.1.3854.1.2.2.1.16.1.9' }, # hhmsSensorArrayTempLowWarning
35 TempLowCritical => { oid => '.1.3.6.1.4.1.3854.1.2.2.1.16.1.10' }, # hhmsSensorArrayTempLowCritical
36 TempDegreeType => { oid => '.1.3.6.1.4.1.3854.1.2.2.1.16.1.12', map => \%map_degree_type }, # hhmsSensorArrayTempDegreeType
37 };
38 my $mapping2 = {
39 TempDescription => { oid => '.1.3.6.1.4.1.3854.3.5.2.1.2' }, # temperatureDescription
40 TempDegree => { oid => '.1.3.6.1.4.1.3854.3.5.2.1.4' }, # temperatureDegree
41 TempStatus => { oid => '.1.3.6.1.4.1.3854.3.5.2.1.6', map => \%map_default1_status }, # temperatureStatus
42 TempOnline => { oid => '.1.3.6.1.4.1.3854.3.5.2.1.8', map => \%map_online }, # temperatureGoOffline
43 TempHighWarning => { oid => '.1.3.6.1.4.1.3854.3.5.2.1.11' }, # temperatureHighWarning
44 TempHighCritical => { oid => '.1.3.6.1.4.1.3854.3.5.2.1.12' }, # temperatureHighCritical
45 TempLowWarning => { oid => '.1.3.6.1.4.1.3854.3.5.2.1.10' }, # temperatureLowWarning
46 TempLowCritical => { oid => '.1.3.6.1.4.1.3854.3.5.2.1.9' }, # temperatureLowCritical
47 TempDegreeType => { oid => '.1.3.6.1.4.1.3854.3.5.2.1.5', map => \%map_degree_type }, # temperatureUnit
48 };
49
50 my $oid_hhmsSensorArrayTempEntry = '.1.3.6.1.4.1.3854.1.2.2.1.16.1';
51 my $oid_temperatureEntry = '.1.3.6.1.4.1.3854.3.5.2.1';
52
53 sub load {
54 my ($self) = @_;
55
56 push @{$self->{request}}, { oid => $oid_hhmsSensorArrayTempEntry },
57 { oid => $oid_temperatureEntry, end => $mapping2->{TempHighCritical}->{oid} };
58 }
59
60 sub check_temperature {
61 my ($self, %options) = @_;
62
63 foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$self->{results}->{$options{entry}}})) {
64 next if ($oid !~ /^$options{mapping}->{TempOnline}->{oid}\.(.*)$/);
65 my $instance = $1;
66 my $result = $self->{snmp}->map_instance(mapping => $options{mapping}, results => $self->{results}->{$options{entry}}, instance => $instance);
67
68 next if ($self->check_filter(section => 'temperature', instance => $instance));
69 if ($result->{TempOnline} eq 'offline') {
70 $self->{output}->output_add(long_msg => sprintf("skipping '%s': is offline", $result->{TempDescription}));
71 next;
72 }
73 $self->{components}->{temperature}->{total}++;
74
75 $self->{output}->output_add(long_msg => sprintf("temperature '%s' status is '%s' [instance = %s] [value = %s]",
76 $result->{TempDescription}, $result->{TempStatus}, $instance,
77 $result->{TempDegree}));
78
79 my $exit = $self->get_severity(label => 'default1', section => 'temperature', value => $result->{TempStatus});
80 if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) {
81 $self->{output}->output_add(severity => $exit,
82 short_msg => sprintf("Temperature '%s' status is '%s'", $result->{TempDescription}, $result->{TempStatus}));
83 }
84
85 my ($exit2, $warn, $crit, $checked) = $self->get_severity_numeric(section => 'temperature', instance => $instance, value => $result->{TempDegree});
86 if ($checked == 0) {
87 $result->{TempLowWarning} = (defined($result->{TempLowWarning}) && $result->{TempLowWarning} =~ /[0-9]/) ?
88 $result->{TempLowWarning} * $options{threshold_mult} : '';
89 $result->{TempLowCritical} = (defined($result->{TempLowCritical}) && $result->{TempLowCritical} =~ /[0-9]/) ?
90 $result->{TempLowCritical} * $options{threshold_mult} : '';
91 $result->{TempHighWarning} = (defined($result->{TempHighWarning}) && $result->{TempHighWarning} =~ /[0-9]/) ?
92 $result->{TempHighWarning} * $options{threshold_mult} : '';
93 $result->{TempHighCritical} = (defined($result->{TempHighCritical}) && $result->{TempHighCritical} =~ /[0-9]/) ?
94 $result->{TempHighCritical} * $options{threshold_mult} : '';
95 my $warn_th = $result->{TempLowWarning} . ':' . $result->{TempHighWarning};
96 my $crit_th = $result->{TempLowCritical} . ':' . $result->{TempHighCritical};
97 $self->{perfdata}->threshold_validate(label => 'warning-temperature-instance-' . $instance, value => $warn_th);
98 $self->{perfdata}->threshold_validate(label => 'critical-temperature-instance-' . $instance, value => $crit_th);
99
100 $warn = $self->{perfdata}->get_perfdata_for_output(label => 'warning-temperature-instance-' . $instance);
101 $crit = $self->{perfdata}->get_perfdata_for_output(label => 'critical-temperature-instance-' . $instance);
102 }
103
104 if (!$self->{output}->is_status(value => $exit2, compare => 'ok', litteral => 1)) {
105 $self->{output}->output_add(severity => $exit2,
106 short_msg => sprintf("Temperature '%s' is %s %s", $result->{TempDescription}, $result->{TempDegree}, $result->{TempDegreeType}->{unit}));
107 }
108 $self->{output}->perfdata_add(
109 label => 'temperature', unit => $result->{TempDegreeType}->{unit},
110 nlabel => 'hardware.sensor.temperature.' . $result->{TempDegreeType}->{unit_long},
111 instances => $result->{TempDescription},
112 value => $result->{TempDegree},
113 warning => $warn,
114 critical => $crit,
115 );
116 }
117 }
118
119 sub check {
120 my ($self) = @_;
121
122 $self->{output}->output_add(long_msg => "Checking temperatures");
123 $self->{components}->{temperature} = {name => 'temperatures', total => 0, skip => 0};
124 return if ($self->check_filter(section => 'temperature'));
125
126 check_temperature($self, entry => $oid_hhmsSensorArrayTempEntry, mapping => $mapping, threshold_mult => 1);
127 check_temperature($self, entry => $oid_temperatureEntry, mapping => $mapping2, threshold_mult => 0.1);
128 }
129
130 1;