Debian Codegraph @

src/hardware/server/hp/bladechassis/snmp/mode/components/fan.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::server::hp::bladechassis::snmp::mode::components::fan;
22
23 use strict;
24 use warnings;
25
26 my %map_conditions = (
27 1 => 'other',
28 2 => 'ok',
29 3 => 'degraded',
30 4 => 'failed',
31 );
32
33 my %present_map = (
34 1 => 'other',
35 2 => 'absent',
36 3 => 'present',
37 4 => 'Weird!!!', # for blades it can return 4, which is NOT spesified in MIB
38 );
39
40 my $mapping = {
41 fan_part => { oid => '.1.3.6.1.4.1.232.22.2.3.1.3.1.6' }, # cpqRackCommonEnclosureFanPartNumber
42 fan_spare => { oid => '.1.3.6.1.4.1.232.22.2.3.1.3.1.7' }, # cpqRackCommonEnclosureFanSparePartNumber
43 fan_condition => { oid => '.1.3.6.1.4.1.232.22.2.3.1.3.1.11', map => \%map_conditions }, # cpqRackCommonEnclosureFanCondition
44 };
45
46 sub check {
47 my ($self) = @_;
48
49 $self->{components}->{fan} = {name => 'fans', total => 0, skip => 0};
50 $self->{output}->output_add(long_msg => "checking fans");
51 return if ($self->check_filter(section => 'fan'));
52
53 my $oid_cpqRackCommonEnclosureFanPresent = '.1.3.6.1.4.1.232.22.2.3.1.3.1.8';
54
55 my $snmp_result = $self->{snmp}->get_table(oid => $oid_cpqRackCommonEnclosureFanPresent);
56 return if (scalar(keys %$snmp_result) <= 0);
57 my @get_oids = ();
58 my @oids_end = ();
59 foreach my $key ($self->{snmp}->oid_lex_sort(keys %$snmp_result)) {
60 $key =~ /\.([0-9]+)$/;
61 my $oid_end = $1;
62
63 next if ($present_map{$snmp_result->{$key}} ne 'present' &&
64 $self->absent_problem(section => 'fan', instance => $oid_end));
65
66 push @oids_end, $oid_end;
67 push @get_oids, map($_->{oid} . '.' . $oid_end, values(%$mapping));
68 }
69
70 $snmp_result = $self->{snmp}->get_leef(oids => \@get_oids);
71 foreach (@oids_end) {
72 my $fan_index = $_;
73
74 my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $snmp_result, instance => $fan_index);
75 next if ($self->check_filter(section => 'fan', instance => $fan_index));
76
77 $self->{components}->{fan}->{total}++;
78 $self->{output}->output_add(long_msg => sprintf("fan '%s' condition is %s [part: %s, spare: %s].",
79 $fan_index, $result->{fan_condition},
80 $result->{fan_part}, $result->{fan_spare}));
81 my $exit = $self->get_severity(label => 'default', section => 'fan', instance => $fan_index, value => $result->{fan_condition});
82 if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) {
83 $self->{output}->output_add(severity => $exit,
84 short_msg => sprintf("Fan '%s' condition is %s", $fan_index, $result->{fan_condition}));
85 }
86 }
87 }
88
89 1;