Debian Codegraph @

src/network/fiberstore/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 network::fiberstore::snmp::mode::components::fan;
22
23 use strict;
24 use warnings;
25 use centreon::plugins::misc;
26
27 my $map_status = {
28 1 => 'active', 2 => 'deactive', 3 => 'notInstall', 4 => 'unsupport'
29 };
30 my $map_position = {
31 1 => 'default', 2 => 'left', 3 => 'right'
32 };
33
34 sub load {
35 my ($self) = @_;
36
37 $self->{mapping_fan} = {
38 status => { oid => $self->{branch} . '.37.1.1.1.1.4', map => $map_status }, # devMFanStatus
39 speed => { oid => $self->{branch} . '.37.1.1.1.1.5' } # devMFanSpeed
40 };
41 $self->{table_fan} = $self->{branch} . '.37.1.1.1';
42
43 push @{$self->{request}}, {
44 oid => $self->{table_fan},
45 start => $self->{mapping_fan}->{status}->{oid},
46 end => $self->{mapping_fan}->{speed}->{oid}
47 };
48 }
49
50 sub check {
51 my ($self) = @_;
52
53 $self->{output}->output_add(long_msg => 'Checking fans');
54 $self->{components}->{fan} = {name => 'fans', total => 0, skip => 0};
55 return if ($self->check_filter(section => 'fan'));
56
57 foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$self->{results}->{ $self->{table_fan} }})) {
58 next if ($oid !~ /^$self->{mapping_fan}->{status}->{oid}\.(\d+)\.(\d+)\.(\d+)$/);
59 my ($position, $instance) = ($1, $1 . '.' . $2 . '.' . $3);
60 my $description = $map_position->{$position} . ':' . $2 . ':' . $3;
61 my $result = $self->{snmp}->map_instance(mapping => $self->{mapping_fan}, results => $self->{results}->{ $self->{table_fan} }, instance => $instance);
62
63 next if ($self->check_filter(section => 'fan', instance => $instance));
64
65 $self->{components}->{fan}->{total}++;
66 $self->{output}->output_add(
67 long_msg => sprintf(
68 "fan '%s' status is '%s' [instance: %s, speed: %s]",
69 $description, $result->{status}, $instance, centreon::plugins::misc::trim($result->{speed})
70 )
71 );
72
73 my $exit = $self->get_severity(section => 'fan', instance => $instance, value => $result->{status});
74 if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) {
75 $self->{output}->output_add(
76 severity => $exit,
77 short_msg => sprintf(
78 "Fan '%s' status is %s", $description, $result->{status}
79 )
80 );
81 }
82
83 next if ($result->{speed} !~ /([0-9]+)\s*%/i);
84
85 my $fan_speed_value = $1;
86 my ($exit2, $warn, $crit) = $self->get_severity_numeric(section => 'fan.speed', instance => $instance, value => $fan_speed_value);
87 if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) {
88 $self->{output}->output_add(
89 severity => $exit2,
90 short_msg => sprintf(
91 "Fan '%s' speed is %s %%", $description, $fan_speed_value
92 )
93 );
94 }
95 $self->{output}->perfdata_add(
96 nlabel => 'hardware.fan.speed.percentage',
97 unit => '%',
98 instances => $description,
99 value => $fan_speed_value,
100 min => 0,
101 max => 100
102 );
103 }
104 }
105
106 1;