Debian Codegraph @

src/hardware/server/fujitsu/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::fujitsu::snmp::mode::components::fan;
22
23 use strict;
24 use warnings;
25
26 my $map_sc_fan_status = {
27 1 => 'unknown', 2 => 'disabled', 3 => 'ok', 4 => 'fail',
28 5 => 'prefailure-predicted', 6 => 'redundant-fan-failed',
29 7 => 'not-manageable', 8 => 'not-present'
30 };
31 my $map_sc2_fan_status = {
32 1 => 'unknown', 2 => 'disabled', 3 => 'ok', 4 => 'failed',
33 5 => 'prefailure-predicted', 6 => 'redundant-fan-failed',
34 7 => 'not-manageable', 8 => 'not-present'
35 };
36
37 my $mapping = {
38 sc => {
39 fanStatus => { oid => '.1.3.6.1.4.1.231.2.10.2.2.5.2.2.1.3', map => $map_sc_fan_status },
40 fanCurrentSpeed => { oid => '.1.3.6.1.4.1.231.2.10.2.2.5.2.2.1.8' },
41 fanDesignation => { oid => '.1.3.6.1.4.1.231.2.10.2.2.5.2.2.1.16' }
42 },
43 sc2 => {
44 sc2fanDesignation => { oid => '.1.3.6.1.4.1.231.2.10.2.2.10.5.2.1.3' },
45 sc2fanStatus => { oid => '.1.3.6.1.4.1.231.2.10.2.2.10.5.2.1.5', map => $map_sc2_fan_status },
46 sc2fanCurrentSpeed => { oid => '.1.3.6.1.4.1.231.2.10.2.2.10.5.2.1.6' }
47 }
48 };
49 my $oid_sc2Fans = '.1.3.6.1.4.1.231.2.10.2.2.10.5.2.1';
50 my $oid_fans = '.1.3.6.1.4.1.231.2.10.2.2.5.2.2.1';
51
52 sub load {
53 my ($self) = @_;
54
55 push @{$self->{request}}, { oid => $oid_sc2Fans, end => $mapping->{sc2}->{sc2fanCurrentSpeed} }, { oid => $oid_fans };
56 }
57
58 sub check_fan {
59 my ($self, %options) = @_;
60
61 my ($exit, $warn, $crit, $checked);
62 foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$self->{results}->{$options{entry}}})) {
63 next if ($oid !~ /^$options{mapping}->{$options{status}}->{oid}\.(.*)$/);
64 my $instance = $1;
65 my $result = $self->{snmp}->map_instance(mapping => $options{mapping}, results => $self->{results}->{$options{entry}}, instance => $instance);
66
67 next if ($self->check_filter(section => 'fan', instance => $instance));
68 next if ($result->{$options{status}} =~ /not-present|not-available/i &&
69 $self->absent_problem(section => 'fan', instance => $instance));
70
71 $self->{components}->{fan}->{total}++;
72
73 $self->{output}->output_add(
74 long_msg => sprintf(
75 "fan '%s' status is '%s' [instance: %s] [speed: %s]",
76 $result->{$options{name}}, $result->{$options{status}}, $instance, $result->{$options{speed}}
77 )
78 );
79
80 $exit = $self->get_severity(section => 'fan', value => $result->{$options{status}});
81 if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) {
82 $self->{output}->output_add(
83 severity => $exit,
84 short_msg => sprintf("Fan '%s' status is '%s'", $result->{$options{name}}, $result->{$options{status}})
85 );
86 }
87
88 next if (!defined($result->{$options{speed}}) || $result->{$options{speed}} == -1);
89
90 ($exit, $warn, $crit, $checked) = $self->get_severity_numeric(section => 'fan', instance => $instance, value => $result->{$options{speed}});
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("Fan '%s' speed is %s rpm", $result->{$options{name}}, $result->{$options{speed}})
96 );
97 }
98 $self->{output}->perfdata_add(
99 nlabel => 'hardware.fan.speed.rpm',
100 unit => 'rpm',
101 instances => $result->{$options{name}},
102 value => $result->{$options{speed}},
103 warning => $warn,
104 critical => $crit,
105 min => 0
106 );
107 }
108 }
109
110 sub check {
111 my ($self) = @_;
112
113 $self->{output}->output_add(long_msg => 'Checking fans');
114 $self->{components}->{fan} = { name => 'fans', total => 0, skip => 0 };
115 return if ($self->check_filter(section => 'fan'));
116
117 if (defined($self->{results}->{$oid_sc2Fans}) && scalar(keys %{$self->{results}->{$oid_sc2Fans}}) > 0) {
118 check_fan(
119 $self, entry => $oid_sc2Fans, mapping => $mapping->{sc2}, name => 'sc2fanDesignation',
120 speed => 'sc2fanCurrentSpeed', status => 'sc2fanStatus'
121 );
122 } else {
123 check_fan(
124 $self, entry => $oid_fans, mapping => $mapping->{sc}, name => 'fanDesignation',
125 speed => 'fanCurrentSpeed', status => 'fanStatus'
126 );
127 }
128 }
129
130 1;