| 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::smallbusiness::snmp::mode::components::fan; |
| 22 |
|
| 23 |
use strict; |
| 24 |
use warnings; |
| 25 |
use centreon::common::cisco::smallbusiness::snmp::mode::components::resources qw( |
| 26 |
$rl_envmon_state |
| 27 |
$oid_rlPhdUnitEnvParamMonitorAutoRecoveryEnable |
| 28 |
$oid_rlPhdUnitEnvParamEntry |
| 29 |
); |
| 30 |
|
| 31 |
my $mapping_stack = { |
| 32 |
new => { |
| 33 |
rlPhdUnitEnvParamFan1Status => { oid => '.1.3.6.1.4.1.9.6.1.101.53.15.1.4', map => $rl_envmon_state }, |
| 34 |
rlPhdUnitEnvParamFan2Status => { oid => '.1.3.6.1.4.1.9.6.1.101.53.15.1.5', map => $rl_envmon_state }, |
| 35 |
rlPhdUnitEnvParamFan3Status => { oid => '.1.3.6.1.4.1.9.6.1.101.53.15.1.6', map => $rl_envmon_state }, |
| 36 |
rlPhdUnitEnvParamFan4Status => { oid => '.1.3.6.1.4.1.9.6.1.101.53.15.1.7', map => $rl_envmon_state }, |
| 37 |
rlPhdUnitEnvParamFan5Status => { oid => '.1.3.6.1.4.1.9.6.1.101.53.15.1.8', map => $rl_envmon_state }, |
| 38 |
rlPhdUnitEnvParamFan6Status => { oid => '.1.3.6.1.4.1.9.6.1.101.53.15.1.9', map => $rl_envmon_state } |
| 39 |
}, |
| 40 |
old => { |
| 41 |
rlPhdUnitEnvParamFan1Status => { oid => '.1.3.6.1.4.1.9.6.1.101.53.15.1.4', map => $rl_envmon_state }, |
| 42 |
rlPhdUnitEnvParamFan2Status => { oid => '.1.3.6.1.4.1.9.6.1.101.53.15.1.5', map => $rl_envmon_state }, |
| 43 |
rlPhdUnitEnvParamFan3Status => { oid => '.1.3.6.1.4.1.9.6.1.101.53.15.1.6', map => $rl_envmon_state }, |
| 44 |
rlPhdUnitEnvParamFan4Status => { oid => '.1.3.6.1.4.1.9.6.1.101.53.15.1.7', map => $rl_envmon_state }, |
| 45 |
rlPhdUnitEnvParamFan5Status => { oid => '.1.3.6.1.4.1.9.6.1.101.53.15.1.8', map => $rl_envmon_state } |
| 46 |
} |
| 47 |
}; |
| 48 |
|
| 49 |
my $mapping = { |
| 50 |
rlEnvMonFanStatusDescr => { oid => '.1.3.6.1.4.1.9.6.1.101.83.1.1.1.2' }, |
| 51 |
rlEnvMonFanState => { oid => '.1.3.6.1.4.1.9.6.1.101.83.1.1.1.3', map => $rl_envmon_state } |
| 52 |
}; |
| 53 |
my $oid_rlEnvMonFanStatusEntry = '.1.3.6.1.4.1.9.6.1.101.83.1.1.1'; |
| 54 |
|
| 55 |
sub load { |
| 56 |
my ($self) = @_; |
| 57 |
|
| 58 |
push @{$self->{request}}, { |
| 59 |
oid => $oid_rlEnvMonFanStatusEntry, |
| 60 |
start => $mapping->{rlEnvMonFanStatusDescr}->{oid}, |
| 61 |
end => $mapping->{rlEnvMonFanState}->{oid} |
| 62 |
}; |
| 63 |
} |
| 64 |
|
| 65 |
sub check_fan_stack { |
| 66 |
my ($self) = @_; |
| 67 |
|
| 68 |
my $num_fans = 5; |
| 69 |
$num_fans = 6 if ($self->{sb_new} == 1); |
| 70 |
|
| 71 |
foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$self->{results}->{$oid_rlPhdUnitEnvParamEntry}})) { |
| 72 |
next if ($oid !~ /^$mapping_stack->{new}->{rlPhdUnitEnvParamFan1Status}->{oid}\.(.*)$/); |
| 73 |
my $instance = $1; |
| 74 |
my $result = $self->{snmp}->map_instance( |
| 75 |
mapping => $self->{sb_new} == 1 ? $mapping_stack->{new} : $mapping_stack->{old}, |
| 76 |
results => $self->{results}->{$oid_rlPhdUnitEnvParamEntry}, |
| 77 |
instance => $instance |
| 78 |
); |
| 79 |
|
| 80 |
for (my $i = 1; $i <= $num_fans; $i++) { |
| 81 |
my $instance2 = 'stack.' . $instance . '.fan.' . $i; |
| 82 |
my $name = 'rlPhdUnitEnvParamFan' . $i . 'Status'; |
| 83 |
|
| 84 |
next if ($self->check_filter(section => 'fan', instance => $instance2)); |
| 85 |
next if ($result->{$name} =~ /notPresent/i && |
| 86 |
$self->absent_problem(section => 'fan', instance => $instance2)); |
| 87 |
|
| 88 |
$self->{components}->{fan}->{total}++; |
| 89 |
$self->{output}->output_add( |
| 90 |
long_msg => sprintf( |
| 91 |
"fan '%s' status is '%s' [instance: %s]", |
| 92 |
$instance2, |
| 93 |
$result->{$name}, |
| 94 |
$instance2 |
| 95 |
) |
| 96 |
); |
| 97 |
|
| 98 |
my $exit = $self->get_severity(label => 'default', section => 'fan', value => $result->{$name}); |
| 99 |
if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { |
| 100 |
$self->{output}->output_add( |
| 101 |
severity => $exit, |
| 102 |
short_msg => sprintf( |
| 103 |
"Fan '%s' status is '%s'", |
| 104 |
$instance2, |
| 105 |
$result->{$name} |
| 106 |
) |
| 107 |
); |
| 108 |
} |
| 109 |
} |
| 110 |
} |
| 111 |
} |
| 112 |
|
| 113 |
sub check_fan { |
| 114 |
my ($self) = @_; |
| 115 |
|
| 116 |
foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$self->{results}->{$oid_rlEnvMonFanStatusEntry}})) { |
| 117 |
next if ($oid !~ /^$mapping->{rlEnvMonFanState}->{oid}\.(.*)$/); |
| 118 |
my $instance = $1; |
| 119 |
my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}->{$oid_rlEnvMonFanStatusEntry}, instance => $instance); |
| 120 |
|
| 121 |
next if ($self->check_filter(section => 'fan', instance => $instance)); |
| 122 |
if ($result->{rlEnvMonFanState} =~ /notPresent/i) { |
| 123 |
$self->absent_problem(section => 'fan', instance => $instance); |
| 124 |
next; |
| 125 |
} |
| 126 |
|
| 127 |
$self->{components}->{fan}->{total}++; |
| 128 |
$self->{output}->output_add( |
| 129 |
long_msg => sprintf( |
| 130 |
"fan '%s' status is '%s' [instance: %s]", |
| 131 |
$result->{rlEnvMonFanStatusDescr}, |
| 132 |
$result->{rlEnvMonFanState}, |
| 133 |
$instance |
| 134 |
) |
| 135 |
); |
| 136 |
|
| 137 |
my $exit = $self->get_severity(label => 'default', section => 'fan', value => $result->{rlEnvMonFanState}); |
| 138 |
if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { |
| 139 |
$self->{output}->output_add( |
| 140 |
severity => $exit, |
| 141 |
short_msg => sprintf( |
| 142 |
"Fan '%s' status is '%s'", |
| 143 |
$result->{rlEnvMonFanStatusDescr}, |
| 144 |
$result->{rlEnvMonFanState} |
| 145 |
) |
| 146 |
); |
| 147 |
} |
| 148 |
} |
| 149 |
} |
| 150 |
|
| 151 |
sub check { |
| 152 |
my ($self) = @_; |
| 153 |
|
| 154 |
$self->{output}->output_add(long_msg => "Checking fans"); |
| 155 |
$self->{components}->{fan} = { name => 'fan', total => 0, skip => 0 }; |
| 156 |
return if ($self->check_filter(section => 'fan')); |
| 157 |
|
| 158 |
check_fan($self); |
| 159 |
check_fan_stack($self); |
| 160 |
} |
| 161 |
|
| 162 |
1; |