Debian Codegraph @

src/centreon/common/cisco/standard/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 centreon::common::cisco::standard::snmp::mode::components::fan;
22
23 use strict;
24 use warnings;
25
26 my %map_fan_state1 = (
27 1 => 'normal',
28 2 => 'warning',
29 3 => 'critical',
30 4 => 'shutdown',
31 5 => 'not present',
32 6 => 'not functioning',
33 );
34 my %map_fan_state2 = (
35 1 => 'unknown',
36 2 => 'up',
37 3 => 'down',
38 4 => 'warning',
39 );
40
41 my $oid_ciscoEnvMonFanStatusEntry = '.1.3.6.1.4.1.9.9.13.1.4.1'; # CISCO-ENVMON-MIB
42 my $oid_cefcFanTrayOperStatus = '.1.3.6.1.4.1.9.9.117.1.4.1.1.1'; # CISCO-ENTITY-SENSOR-MIB
43
44 sub load {
45 my ($self) = @_;
46
47 push @{$self->{request}}, { oid => $oid_ciscoEnvMonFanStatusEntry }, { oid => $oid_cefcFanTrayOperStatus };
48 }
49
50 sub check_fan_envmon {
51 my ($self) = @_;
52
53 my $mapping = {
54 ciscoEnvMonFanStatusDescr => { oid => '.1.3.6.1.4.1.9.9.13.1.4.1.2' },
55 ciscoEnvMonFanState => { oid => '.1.3.6.1.4.1.9.9.13.1.4.1.3', map => \%map_fan_state1 },
56 };
57
58 foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$self->{results}->{$oid_ciscoEnvMonFanStatusEntry}})) {
59 next if ($oid !~ /^$mapping->{ciscoEnvMonFanStatusDescr}->{oid}\./);
60 $oid =~ /\.([0-9]+)$/;
61 my $instance = $1;
62
63 my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}->{$oid_ciscoEnvMonFanStatusEntry}, instance => $instance);
64
65 next if ($self->check_filter(section => 'fan', instance => $instance, name => $result->{ciscoEnvMonFanStatusDescr}));
66 next if ($result->{ciscoEnvMonFanState} =~ /not present/i &&
67 $self->absent_problem(section => 'fan', instance => $instance, name => $result->{ciscoEnvMonFanStatusDescr}));
68 $self->{components}->{fan}->{total}++;
69
70 $self->{output}->output_add(
71 long_msg => sprintf(
72 "fan '%s' status is %s [instance: %s].",
73 $result->{ciscoEnvMonFanStatusDescr}, $result->{ciscoEnvMonFanState},
74 $instance
75 )
76 );
77 my $exit = $self->get_severity(section => 'fan', instance => $instance, value => $result->{ciscoEnvMonFanState});
78 if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) {
79 $self->{output}->output_add(
80 severity => $exit,
81 short_msg => sprintf(
82 "fan '%s' status is %s",
83 $result->{ciscoEnvMonFanStatusDescr}, $result->{ciscoEnvMonFanState}
84 )
85 );
86 }
87 }
88 }
89
90 sub check_fan_entity {
91 my ($self) = @_;
92
93 my $mapping = {
94 cefcFanTrayOperStatus => { oid => '.1.3.6.1.4.1.9.9.117.1.4.1.1.1', map => \%map_fan_state2 }
95 };
96 foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$self->{results}->{$oid_cefcFanTrayOperStatus}})) {
97 $oid =~ /\.([0-9]+)$/;
98 my $instance = $1;
99
100 my $fan_descr = $self->{results}->{ $self->{physical_name} }->{ $self->{physical_name} . '.' . $instance };
101 my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}->{$oid_cefcFanTrayOperStatus}, instance => $instance);
102
103 next if ($self->check_filter(section => 'fan', instance => $instance, name => $fan_descr));
104
105 $self->{components}->{fan}->{total}++;
106 $self->{output}->output_add(
107 long_msg => sprintf(
108 "fan '%s' status is %s [instance: %s]",
109 $fan_descr, $result->{cefcFanTrayOperStatus}, $instance
110 )
111 );
112 my $exit = $self->get_severity(section => 'fan', instance => $instance, value => $result->{cefcFanTrayOperStatus});
113 if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) {
114 $self->{output}->output_add(
115 severity => $exit,
116 short_msg => sprintf("Fan '%s/%s' status is %s", $fan_descr, $instance, $result->{cefcFanTrayOperStatus})
117 );
118 }
119 }
120 }
121
122 sub check {
123 my ($self) = @_;
124
125 $self->{output}->output_add(long_msg => "Checking fans");
126 $self->{components}->{fan} = { name => 'fans', total => 0, skip => 0 };
127 return if ($self->check_filter(section => 'fan'));
128
129 check_fan_envmon($self);
130 check_fan_entity($self);
131 }
132
133 1;