| 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 storage::qnap::snmp::mode::components::fan; |
| 22 |
|
| 23 |
use strict; |
| 24 |
use warnings; |
| 25 |
|
| 26 |
my $map_status = { |
| 27 |
0 => 'ok', -1 => 'fail' |
| 28 |
}; |
| 29 |
|
| 30 |
my $mapping = { |
| 31 |
legacy => { |
| 32 |
description => { oid => '.1.3.6.1.4.1.24681.1.2.15.1.2' }, # sysFanDescr |
| 33 |
speed => { oid => '.1.3.6.1.4.1.24681.1.2.15.1.3' } # sysFanSpeed |
| 34 |
}, |
| 35 |
qts => { |
| 36 |
description => { oid => '.1.3.6.1.4.1.55062.1.12.9.1.2' }, # sysFanDescr |
| 37 |
speed => { oid => '.1.3.6.1.4.1.55062.1.12.9.1.3' } # sysFanSpeed |
| 38 |
}, |
| 39 |
ex => { |
| 40 |
description => { oid => '.1.3.6.1.4.1.24681.1.4.1.1.1.1.2.2.1.2' }, # systemFanID |
| 41 |
status => { oid => '.1.3.6.1.4.1.24681.1.4.1.1.1.1.2.2.1.4', map => $map_status }, # systemFanStatus |
| 42 |
speed => { oid => '.1.3.6.1.4.1.24681.1.4.1.1.1.1.2.2.1.5' }, # systemFanSpeed |
| 43 |
}, |
| 44 |
es => { |
| 45 |
description => { oid => '.1.3.6.1.4.1.24681.2.2.15.1.2' }, # es-SysFanDescr |
| 46 |
speed => { oid => '.1.3.6.1.4.1.24681.2.2.15.1.3' } # es-SysFanSpeed |
| 47 |
} |
| 48 |
}; |
| 49 |
|
| 50 |
sub load {} |
| 51 |
|
| 52 |
sub check_fan_result { |
| 53 |
my ($self, %options) = @_; |
| 54 |
|
| 55 |
foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$options{snmp_result}})) { |
| 56 |
next if ($oid !~ /^$mapping->{ $options{type} }->{description}->{oid}\.(.*)$/); |
| 57 |
my $instance = $1; |
| 58 |
$self->{fan_checked} = 1; |
| 59 |
|
| 60 |
my $result = $self->{snmp}->map_instance(mapping => $mapping->{ $options{type} }, results => $options{snmp_result}, instance => $instance); |
| 61 |
|
| 62 |
next if ($self->check_filter(section => 'fan', instance => $instance)); |
| 63 |
$self->{components}->{fan}->{total}++; |
| 64 |
|
| 65 |
$result->{speed} = defined($result->{speed}) ? $result->{speed} : 'unknown'; |
| 66 |
$result->{status} = defined($result->{status}) ? $result->{status} : 'n/a'; |
| 67 |
$self->{output}->output_add( |
| 68 |
long_msg => sprintf( |
| 69 |
"fan '%s' speed is %s [instance: %s, status: %s]", |
| 70 |
$result->{description}, $result->{speed}, $instance, |
| 71 |
$result->{status} |
| 72 |
) |
| 73 |
); |
| 74 |
|
| 75 |
if ($result->{speed} =~ /([0-9]+)/i) { |
| 76 |
my $fan_speed_value = $1; |
| 77 |
my ($exit, $warn, $crit) = $self->get_severity_numeric(section => 'fan', instance => $instance, value => $fan_speed_value); |
| 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' speed is %s rpm", $result->{description}, $fan_speed_value |
| 83 |
) |
| 84 |
); |
| 85 |
} |
| 86 |
$self->{output}->perfdata_add( |
| 87 |
nlabel => 'hardware.fan.speed.rpm', |
| 88 |
unit => 'rpm', |
| 89 |
instances => $instance, |
| 90 |
value => $fan_speed_value, |
| 91 |
min => 0 |
| 92 |
); |
| 93 |
} |
| 94 |
} |
| 95 |
} |
| 96 |
|
| 97 |
sub check_fan_es { |
| 98 |
my ($self, %options) = @_; |
| 99 |
|
| 100 |
my $snmp_result = $self->{snmp}->get_table( |
| 101 |
oid => '.1.3.6.1.4.1.24681.2.2.15', # es-SystemFanTable |
| 102 |
start => $mapping->{es}->{description}->{oid} |
| 103 |
); |
| 104 |
check_fan_result($self, type => 'es', snmp_result => $snmp_result); |
| 105 |
} |
| 106 |
|
| 107 |
sub check_fan_qts { |
| 108 |
my ($self, %options) = @_; |
| 109 |
|
| 110 |
return if (defined($self->{fan_checked})); |
| 111 |
|
| 112 |
my $snmp_result = $self->{snmp}->get_table( |
| 113 |
oid => '.1.3.6.1.4.1.55062.1.12.9', # systemFanTable |
| 114 |
start => $mapping->{qts}->{description}->{oid} |
| 115 |
); |
| 116 |
check_fan_result($self, type => 'qts', snmp_result => $snmp_result); |
| 117 |
} |
| 118 |
|
| 119 |
sub check_fan_legacy { |
| 120 |
my ($self, %options) = @_; |
| 121 |
|
| 122 |
return if (defined($self->{fan_checked})); |
| 123 |
|
| 124 |
my $snmp_result = $self->{snmp}->get_table( |
| 125 |
oid => '.1.3.6.1.4.1.24681.1.2.15', # systemFanTable |
| 126 |
start => $mapping->{legacy}->{description}->{oid} |
| 127 |
); |
| 128 |
check_fan_result($self, type => 'legacy', snmp_result => $snmp_result); |
| 129 |
} |
| 130 |
|
| 131 |
sub check_fan_ex { |
| 132 |
my ($self, %options) = @_; |
| 133 |
|
| 134 |
my $snmp_result = $self->{snmp}->get_table( |
| 135 |
oid => '.1.3.6.1.4.1.24681.1.4.1.1.1.1.2.2', # systemFan2Table |
| 136 |
start => $mapping->{ex}->{description}->{oid} |
| 137 |
); |
| 138 |
check_fan_result($self, type => 'ex', snmp_result => $snmp_result); |
| 139 |
} |
| 140 |
|
| 141 |
sub check { |
| 142 |
my ($self) = @_; |
| 143 |
|
| 144 |
$self->{output}->output_add(long_msg => "Checking fans"); |
| 145 |
$self->{components}->{fan} = {name => 'fans', total => 0, skip => 0}; |
| 146 |
return if ($self->check_filter(section => 'fan')); |
| 147 |
|
| 148 |
if ($self->{is_qts} == 1) { |
| 149 |
check_fan_qts($self); |
| 150 |
} elsif ($self->{is_es} == 1) { |
| 151 |
check_fan_es($self); |
| 152 |
} else { |
| 153 |
check_fan_ex($self); |
| 154 |
check_fan_legacy($self); |
| 155 |
} |
| 156 |
} |
| 157 |
|
| 158 |
1; |