| 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::adic::tape::snmp::mode::components::fan; |
| 22 |
|
| 23 |
use strict; |
| 24 |
use warnings; |
| 25 |
|
| 26 |
my %map_status = ( |
| 27 |
1 => 'nominal', |
| 28 |
2 => 'warningLow', 3 => 'warningHigh', |
| 29 |
4 => 'alarmLow', 5 => 'alarmHigh', |
| 30 |
6 => 'notInstalled', 7 => 'noData', |
| 31 |
); |
| 32 |
|
| 33 |
my $mapping = { |
| 34 |
coolingFanName => { oid => '.1.3.6.1.4.1.3764.1.1.200.200.40.1.2' }, |
| 35 |
coolingFanStatus => { oid => '.1.3.6.1.4.1.3764.1.1.200.200.40.1.3', map => \%map_status }, |
| 36 |
coolingFanRPM => { oid => '.1.3.6.1.4.1.3764.1.1.200.200.40.1.4' }, |
| 37 |
coolingFanWarningHi => { oid => '.1.3.6.1.4.1.3764.1.1.200.200.40.1.8' }, |
| 38 |
coolingFanNominalHi => { oid => '.1.3.6.1.4.1.3764.1.1.200.200.40.1.6' }, |
| 39 |
coolingFanNominalLo => { oid => '.1.3.6.1.4.1.3764.1.1.200.200.40.1.5' }, |
| 40 |
coolingFanWarningLo => { oid => '.1.3.6.1.4.1.3764.1.1.200.200.40.1.7' }, |
| 41 |
coolingFanLocation => { oid => '.1.3.6.1.4.1.3764.1.1.200.200.40.1.9' }, |
| 42 |
}; |
| 43 |
my $oid_coolingFanEntry = '.1.3.6.1.4.1.3764.1.1.200.200.40.1'; |
| 44 |
|
| 45 |
sub load { |
| 46 |
my ($self) = @_; |
| 47 |
|
| 48 |
push @{$self->{request}}, { oid => $oid_coolingFanEntry }; |
| 49 |
} |
| 50 |
|
| 51 |
sub check { |
| 52 |
my ($self) = @_; |
| 53 |
|
| 54 |
$self->{output}->output_add(long_msg => "Checking fans"); |
| 55 |
$self->{components}->{fan} = {name => 'fans', total => 0, skip => 0}; |
| 56 |
return if ($self->check_filter(section => 'fan')); |
| 57 |
|
| 58 |
foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$self->{results}->{$oid_coolingFanEntry}})) { |
| 59 |
next if ($oid !~ /^$mapping->{coolingFanStatus}->{oid}\.(.*)$/); |
| 60 |
my $instance = $1; |
| 61 |
my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}->{$oid_coolingFanEntry}, instance => $instance); |
| 62 |
|
| 63 |
$result->{coolingFanName} =~ s/\s+/ /g; |
| 64 |
$result->{coolingFanName} = centreon::plugins::misc::trim($result->{coolingFanName}); |
| 65 |
$result->{coolingFanLocation} =~ s/,/_/g; |
| 66 |
my $id = $result->{coolingFanName} . '_' . $result->{coolingFanLocation}; |
| 67 |
|
| 68 |
next if ($self->check_filter(section => 'fan', instance => $id)); |
| 69 |
$self->{components}->{fan}->{total}++; |
| 70 |
|
| 71 |
$self->{output}->output_add(long_msg => sprintf("fan '%s' status is '%s' [instance = %s] [value = %s]", |
| 72 |
$id, $result->{coolingFanStatus}, $id, |
| 73 |
$result->{coolingFanRPM})); |
| 74 |
|
| 75 |
my $exit = $self->get_severity(label => 'sensor', section => 'fan', value => $result->{coolingFanStatus}); |
| 76 |
if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { |
| 77 |
$self->{output}->output_add(severity => $exit, |
| 78 |
short_msg => sprintf("fan '%s' status is '%s'", $id, $result->{coolingFanStatus})); |
| 79 |
next; |
| 80 |
} |
| 81 |
|
| 82 |
if (defined($result->{coolingFanRPM}) && $result->{coolingFanRPM} =~ /[0-9]/) { |
| 83 |
my ($exit, $warn, $crit, $checked) = $self->get_severity_numeric(section => 'fan', instance => $instance, value => $result->{coolingFanRPM}); |
| 84 |
if ($checked == 0) { |
| 85 |
$result->{coolingFanNominalLo} = (defined($result->{coolingFanNominalLo}) && $result->{coolingFanNominalLo} =~ /[0-9]/) ? |
| 86 |
$result->{coolingFanNominalLo} : ''; |
| 87 |
$result->{coolingFanWarningLo} = (defined($result->{coolingFanWarningLo}) && $result->{coolingFanWarningLo} =~ /[0-9]/) ? |
| 88 |
$result->{coolingFanWarningLo} : ''; |
| 89 |
$result->{coolingFanNominalHi} = (defined($result->{coolingFanNominalHi}) && $result->{coolingFanNominalHi} =~ /[0-9]/) ? |
| 90 |
$result->{coolingFanNominalHi} : ''; |
| 91 |
$result->{coolingFanWarningHi} = (defined($result->{coolingFanWarningHi}) && $result->{coolingFanWarningHi} =~ /[0-9]/) ? |
| 92 |
$result->{coolingFanWarningHi} : ''; |
| 93 |
my $warn_th = $result->{coolingFanNominalLo} . ':' . $result->{coolingFanNominalHi}; |
| 94 |
my $crit_th = $result->{coolingFanWarningLo} . ':' . $result->{coolingFanWarningHi}; |
| 95 |
$self->{perfdata}->threshold_validate(label => 'warning-fan-instance-' . $instance, value => $warn_th); |
| 96 |
$self->{perfdata}->threshold_validate(label => 'critical-fan-instance-' . $instance, value => $crit_th); |
| 97 |
|
| 98 |
$exit = $self->{perfdata}->threshold_check(value => $result->{coolingFanRPM}, threshold => [ { label => 'critical-fan-instance-' . $instance, exit_litteral => 'critical' }, |
| 99 |
{ label => 'warning-fan-instance-' . $instance, exit_litteral => 'warning' } ]); |
| 100 |
$warn = $self->{perfdata}->get_perfdata_for_output(label => 'warning-fan-instance-' . $instance); |
| 101 |
$crit = $self->{perfdata}->get_perfdata_for_output(label => 'critical-fan-instance-' . $instance); |
| 102 |
} |
| 103 |
|
| 104 |
if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { |
| 105 |
$self->{output}->output_add(severity => $exit, |
| 106 |
short_msg => sprintf("Fan '%s' is %s rpm", $id, $result->{coolingFanRPM})); |
| 107 |
} |
| 108 |
$self->{output}->perfdata_add( |
| 109 |
label => 'fan', unit => 'rpm', |
| 110 |
nlabel => 'hardware.fan.speed.rpm', |
| 111 |
instances => $id, |
| 112 |
value => $result->{coolingFanRPM}, |
| 113 |
warning => $warn, |
| 114 |
critical => $crit, |
| 115 |
); |
| 116 |
} |
| 117 |
} |
| 118 |
} |
| 119 |
|
| 120 |
1; |