Debian Codegraph @

src/hardware/pdu/schleifenbauer/gateway/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::pdu::schleifenbauer::gateway::snmp::mode::components::temperature;
22
23 use strict;
24 use warnings;
25 use hardware::pdu::schleifenbauer::gateway::snmp::mode::components::resources qw($oid_pdumeasuresEntry $oid_deviceName $mapping);
26
27 sub load {}
28
29 sub check_temperature {
30 my ($self, %options) = @_;
31
32 my $description = $options{device_name};
33 $description .= '.' . ((defined($options{sensor_name}) && $options{sensor_name} ne '') ? $options{sensor_name} : $options{num});
34
35 next if ($self->check_filter(section => 'temperature', instance => $options{instance}, name => $description));
36 $self->{components}->{temperature}->{total}++;
37 $self->{output}->output_add(long_msg => sprintf("temperature '%s' is %s C [instance = %s]",
38 $description, $options{value}, $options{instance}));
39
40 my ($exit, $warn, $crit, $checked) = $self->get_severity_numeric(section => 'temperature', instance => $options{instance}, name => $description, value => $options{value});
41
42 if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) {
43 $self->{output}->output_add(severity => $exit,
44 short_msg => sprintf("Temperature '%s' is %s C", $description, $options{value}));
45 }
46 $self->{output}->perfdata_add(
47 label => 'temperature', unit => 'C',
48 nlabel => 'hardware.sensor.temperature.celsius',
49 instances => [$options{device_name}, (defined($options{sensor_name}) && $options{sensor_name} ne '') ? $options{sensor_name} : $options{num}],
50 value => $options{value},
51 warning => $warn,
52 critical => $crit,
53 );
54 }
55
56 sub check {
57 my ($self) = @_;
58
59 $self->{output}->output_add(long_msg => "Checking temperature");
60 $self->{components}->{temperature} = { name => 'temperature', total => 0, skip => 0 };
61 return if ($self->check_filter(section => 'temperature'));
62
63 foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$self->{results}->{$oid_deviceName}})) {
64 $oid =~ /^$oid_deviceName.(.*)$/;
65 my $instance = $1;
66 my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}->{$oid_pdumeasuresEntry}, instance => $instance);
67
68 for (my $i = 1; $i <= 16; $i++) {
69 next if (!defined($result->{'sensor' . $i . 'Type'}) || $result->{'sensor' . $i . 'Type'} !~ /T/);
70 check_temperature($self,
71 instance => $instance,
72 device_name => $self->{results}->{$oid_deviceName}->{$oid},
73 num => $i,
74 value => $result->{'sensor' . $i . 'Value'},
75 sensor_name => $result->{'sensor' . $i . 'Name'},
76 );
77 }
78
79 check_temperature($self,
80 instance => $instance,
81 device_name => $self->{results}->{$oid_deviceName}->{$oid},
82 num => 0,
83 value => $result->{pduIntTemperature},
84 sensor_name => 'Internal',
85 ) if ($result->{pduIntTemperature} != 0);
86 check_temperature($self,
87 instance => $instance,
88 device_name => $self->{results}->{$oid_deviceName}->{$oid},
89 num => 0,
90 value => $result->{pduExtTemperature},
91 sensor_name => 'External',
92 ) if ($result->{pduExtTemperature} != 0);
93 }
94 }
95
96 1;