Debian Codegraph @

src/network/hirschmann/standard/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::hirschmann::standard::snmp::mode::components::temperature;
22
23 use strict;
24 use warnings;
25
26 my $mapping_classic_temp = {
27 temp_current => { oid => '.1.3.6.1.4.1.248.14.2.5.1' }, # hmTemperature
28 temp_upper_limit => { oid => '.1.3.6.1.4.1.248.14.2.5.2' }, # hmTempUprLimit
29 temp_lower_limit => { oid => '.1.3.6.1.4.1.248.14.2.5.3' } # hmTempLwrLimit
30 };
31 my $mapping_hios_temp = {
32 temp_current => { oid => '.1.3.6.1.4.1.248.11.10.1.5.1' }, # hm2DevMgmtTemperature
33 temp_upper_limit => { oid => '.1.3.6.1.4.1.248.11.10.1.5.2' }, # hm2DevMgmtTemperatureUpperLimit
34 temp_lower_limit => { oid => '.1.3.6.1.4.1.248.11.10.1.5.3' } # hm2DevMgmtTemperatureLowerLimit
35 };
36 my $oid_classic_temp_table = '.1.3.6.1.4.1.248.14.2.5'; # hmTempTable
37 my $oid_hios_temp_table = '.1.3.6.1.4.1.248.11.10.1.5'; # hm2DeviceMgmtTemperatureGroup
38
39 sub load {
40 my ($self) = @_;
41
42 push @{$self->{myrequest}->{classic}},
43 { oid => $oid_classic_temp_table };
44 push @{$self->{myrequest}->{hios}},
45 { oid => $oid_hios_temp_table, end => $mapping_hios_temp->{temp_lower_limit}->{oid} };
46 }
47
48 sub check_temp {
49 my ($self, %options) = @_;
50
51 my $instance = 0;
52 my $result = $self->{snmp}->map_instance(
53 mapping => $options{mapping},
54 results => $options{results},
55 instance => $instance
56 );
57 return if (!defined($result->{temp_current}));
58
59 next if ($self->check_filter(section => 'temperature', instance => $instance));
60 $self->{components}->{temperature}->{total}++;
61
62 $self->{output}->output_add(
63 long_msg => sprintf(
64 "temperature is %dC [instance: %s].",
65 $result->{temp_current},
66 $instance
67 )
68 );
69 my ($exit, $warn, $crit, $checked) = $self->get_severity_numeric(section => 'temperature', instance => $instance, value => $result->{temp_current});
70 if ($checked == 0) {
71 my $warn_th = '';
72 my $crit_th = $result->{temp_lower_limit} . ':' . $result->{temp_upper_limit};
73 $self->{perfdata}->threshold_validate(label => 'warning-temperature-instance-' . $instance, value => $warn_th);
74 $self->{perfdata}->threshold_validate(label => 'critical-temperature-instance-' . $instance, value => $crit_th);
75 $warn = $self->{perfdata}->get_perfdata_for_output(label => 'warning-temperature-instance-' . $instance);
76 $crit = $self->{perfdata}->get_perfdata_for_output(label => 'critical-temperature-instance-' . $instance);
77 }
78 if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) {
79 $self->{output}->output_add(
80 severity => $exit,
81 short_msg => sprintf("Temperature is %s degree centigrade", $result->{hmTemperature})
82 );
83 }
84 $self->{output}->perfdata_add(
85 nlabel => 'hardware.temperature.celsius',
86 unit => 'C',
87 value => $result->{temp_current},
88 warning => $warn,
89 critical => $crit
90 );
91 }
92
93 sub check {
94 my ($self) = @_;
95
96 $self->{output}->output_add(long_msg => 'Checking temperatures');
97 $self->{components}->{temperature} = {name => 'temperatures', total => 0, skip => 0};
98 return if ($self->check_filter(section => 'temperature'));
99
100 check_temp($self, mapping => $mapping_classic_temp, results => $self->{results}->{$oid_classic_temp_table})
101 if ($self->{os_type} eq 'classic');
102 check_temp($self, mapping => $mapping_hios_temp, results => $self->{results}->{$oid_hios_temp_table})
103 if ($self->{os_type} eq 'hios');
104 }
105
106 1;