| 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::dlink::standard::snmp::mode::components::fan; |
| 22 |
|
| 23 |
use strict; |
| 24 |
use warnings; |
| 25 |
|
| 26 |
my $map_status_equipment = { |
| 27 |
0 => 'other', 1 => 'working', |
| 28 |
2 => 'fail', 3 => 'speed-0', |
| 29 |
4 => 'speed-low', 5 => 'speed-middle', |
| 30 |
6 => 'speed-high' |
| 31 |
}; |
| 32 |
my $map_status = { |
| 33 |
1 => 'ok', 2 => 'fault' |
| 34 |
}; |
| 35 |
|
| 36 |
my $mapping_equipment = { |
| 37 |
swFanStatus => { oid => '.1.3.6.1.4.1.171.12.11.1.7.1.3', map => $map_status_equipment }, |
| 38 |
swFanSpeed => { oid => '.1.3.6.1.4.1.171.12.11.1.7.1.6' } |
| 39 |
}; |
| 40 |
my $oid_swFanEntry = '.1.3.6.1.4.1.171.12.11.1.7.1'; |
| 41 |
|
| 42 |
my $mapping_industrial = { |
| 43 |
description => { oid => '.1.3.6.1.4.1.171.14.5.1.1.2.1.3' }, # dEntityExtEnvFanDescr |
| 44 |
status => { oid => '.1.3.6.1.4.1.171.14.5.1.1.2.1.4', map => $map_status } # dEntityExtEnvFanStatus |
| 45 |
}; |
| 46 |
my $oid_dEntityExtEnvFanEntry = '.1.3.6.1.4.1.171.14.5.1.1.2.1'; |
| 47 |
|
| 48 |
my $mapping_common = { |
| 49 |
description => { oid => '.1.3.6.1.4.1.171.17.5.1.1.2.1.3' }, # esEntityExtEnvFanDescr |
| 50 |
status => { oid => '.1.3.6.1.4.1.171.17.5.1.1.2.1.4', map => $map_status } # esEntityExtEnvFanStatus |
| 51 |
}; |
| 52 |
my $oid_esEntityExtEnvFanEntry = '.1.3.6.1.4.1.171.17.5.1.1.2.1'; |
| 53 |
|
| 54 |
sub load { |
| 55 |
my ($self) = @_; |
| 56 |
|
| 57 |
push @{$self->{request}}, |
| 58 |
{ oid => $oid_swFanEntry, start => $mapping_equipment->{swFanStatus}->{oid} }, |
| 59 |
{ oid => $oid_dEntityExtEnvFanEntry, start => $mapping_industrial->{description}->{oid} }, |
| 60 |
{ oid => $oid_esEntityExtEnvFanEntry, start => $mapping_common->{description}->{oid} } |
| 61 |
; |
| 62 |
} |
| 63 |
|
| 64 |
sub check_fan_equipment { |
| 65 |
my ($self, %options) = @_; |
| 66 |
|
| 67 |
foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$self->{results}->{$oid_swFanEntry}})) { |
| 68 |
next if ($oid !~ /^$mapping_equipment->{swFanStatus}->{oid}\.(\d+)\.(\d+)$/); |
| 69 |
my ($unit_id, $fan_id) = ($1, $2); |
| 70 |
my $instance = $1 . '.' . $2; |
| 71 |
my $result = $self->{snmp}->map_instance(mapping => $mapping_equipment, results => $self->{results}->{$oid_swFanEntry}, instance => $instance); |
| 72 |
|
| 73 |
my $description = 'unit' . $unit_id . ':fan' . $fan_id; |
| 74 |
next if ($self->check_filter(section => 'fan', instance => $instance)); |
| 75 |
$self->{components}->{fan}->{total}++; |
| 76 |
|
| 77 |
$self->{output}->output_add( |
| 78 |
long_msg => sprintf( |
| 79 |
"fan '%s' status is %s [instance: %s, speed: %s]", |
| 80 |
$description, |
| 81 |
$result->{swFanStatus}, |
| 82 |
$instance, |
| 83 |
defined($result->{swFanSpeed}) ? $result->{swFanSpeed} : '-' |
| 84 |
) |
| 85 |
); |
| 86 |
my $exit = $self->get_severity(section => 'fan', value => $result->{swFanStatus}); |
| 87 |
if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { |
| 88 |
$self->{output}->output_add( |
| 89 |
severity => $exit, |
| 90 |
short_msg => sprintf( |
| 91 |
"fan '%s' status is %s", |
| 92 |
$description, $result->{swFanStatus} |
| 93 |
) |
| 94 |
); |
| 95 |
} |
| 96 |
|
| 97 |
next if (!defined($result->{swFanSpeed})); |
| 98 |
|
| 99 |
my ($exit2, $warn, $crit, $checked) = $self->get_severity_numeric(section => 'fan', instance => $instance, value => $result->{swFanSpeed}); |
| 100 |
if (!$self->{output}->is_status(value => $exit2, compare => 'ok', litteral => 1)) { |
| 101 |
$self->{output}->output_add( |
| 102 |
severity => $exit2, |
| 103 |
short_msg => sprintf( |
| 104 |
"fan '%s' speed is %s rpm", |
| 105 |
$description, |
| 106 |
$result->{swFanSpeed} |
| 107 |
) |
| 108 |
); |
| 109 |
} |
| 110 |
$self->{output}->perfdata_add( |
| 111 |
unit => 'rpm', |
| 112 |
nlabel => 'hardware.fan.speed.rpm', |
| 113 |
instances => ['unit' . $unit_id, 'fan' . $fan_id], |
| 114 |
value => $result->{swFanSpeed}, |
| 115 |
warning => $warn, |
| 116 |
critical => $crit, |
| 117 |
min => 0 |
| 118 |
); |
| 119 |
} |
| 120 |
} |
| 121 |
|
| 122 |
sub check_fan { |
| 123 |
my ($self, %options) = @_; |
| 124 |
|
| 125 |
foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$self->{results}->{ $options{entry} }})) { |
| 126 |
next if ($oid !~ /^$options{mapping}->{status}->{oid}\.(\d+)\.(\d+)$/); |
| 127 |
my ($unit_id, $fan_id) = ($1, $2); |
| 128 |
my $instance = $1 . '.' . $2; |
| 129 |
my $result = $self->{snmp}->map_instance(mapping => $options{mapping}, results => $self->{results}->{ $options{entry} }, instance => $instance); |
| 130 |
|
| 131 |
my $description = 'unit' . $unit_id . ':fan' . $fan_id; |
| 132 |
next if ($self->check_filter(section => 'fan', instance => $instance)); |
| 133 |
$self->{components}->{fan}->{total}++; |
| 134 |
|
| 135 |
$self->{output}->output_add( |
| 136 |
long_msg => sprintf( |
| 137 |
"fan '%s' status is '%s' [instance: %s, description: %s]", |
| 138 |
$description, |
| 139 |
$result->{status}, |
| 140 |
$instance, |
| 141 |
$result->{description} |
| 142 |
) |
| 143 |
); |
| 144 |
my $exit = $self->get_severity(section => 'fan', value => $result->{status}); |
| 145 |
if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { |
| 146 |
$self->{output}->output_add( |
| 147 |
severity => $exit, |
| 148 |
short_msg => sprintf( |
| 149 |
"fan '%s' status is '%s'", |
| 150 |
$description, $result->{status} |
| 151 |
) |
| 152 |
); |
| 153 |
} |
| 154 |
} |
| 155 |
} |
| 156 |
|
| 157 |
sub check { |
| 158 |
my ($self) = @_; |
| 159 |
|
| 160 |
$self->{output}->output_add(long_msg => 'checking fans'); |
| 161 |
$self->{components}->{fan} = { name => 'fans', total => 0, skip => 0 }; |
| 162 |
return if ($self->check_filter(section => 'fan')); |
| 163 |
|
| 164 |
check_fan_equipment($self); |
| 165 |
check_fan($self, entry => $oid_dEntityExtEnvFanEntry, mapping => $mapping_industrial); |
| 166 |
check_fan($self, entry => $oid_esEntityExtEnvFanEntry, mapping => $mapping_common); |
| 167 |
} |
| 168 |
|
| 169 |
1; |