| 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::psu; |
| 22 |
|
| 23 |
use strict; |
| 24 |
use warnings; |
| 25 |
|
| 26 |
my $map_status = { |
| 27 |
0 => 'ok', -1 => 'fail' |
| 28 |
}; |
| 29 |
|
| 30 |
my $mapping = { |
| 31 |
ex => { |
| 32 |
status => { oid => '.1.3.6.1.4.1.24681.1.4.1.1.1.1.3.2.1.4', map => $map_status }, # systemPowerStatus |
| 33 |
speed => { oid => '.1.3.6.1.4.1.24681.1.4.1.1.1.1.3.2.1.5' }, # systemPowerFanSpeed |
| 34 |
temperature => { oid => '.1.3.6.1.4.1.24681.1.4.1.1.1.1.3.2.1.6' } # systemPowerTemp |
| 35 |
}, |
| 36 |
es => { |
| 37 |
status => { oid => '.1.3.6.1.4.1.24681.2.2.21.1.4' }, # es-SysPowerStatus |
| 38 |
speed => { oid => '.1.3.6.1.4.1.24681.2.2.21.1.5' }, # es-SysPowerFanSpeed |
| 39 |
temperature => { oid => '.1.3.6.1.4.1.24681.2.2.21.1.6' } # es-SysPowerTemp |
| 40 |
} |
| 41 |
}; |
| 42 |
|
| 43 |
sub load {} |
| 44 |
|
| 45 |
sub check_psu_result { |
| 46 |
my ($self, %options) = @_; |
| 47 |
|
| 48 |
foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$options{snmp_result}})) { |
| 49 |
next if ($oid !~ /^$mapping->{ $options{type} }->{status}->{oid}\.(.*)$/); |
| 50 |
my $instance = $1; |
| 51 |
my $result = $self->{snmp}->map_instance(mapping => $mapping->{ $options{type} }, results => $options{snmp_result}, instance => $instance); |
| 52 |
|
| 53 |
next if ($self->check_filter(section => 'psu', instance => $instance)); |
| 54 |
|
| 55 |
$self->{components}->{psu}->{total}++; |
| 56 |
|
| 57 |
$self->{output}->output_add( |
| 58 |
long_msg => sprintf( |
| 59 |
"power supply '%s' status is '%s' [instance: %s, fan speed: %s, temperature: %s]", |
| 60 |
$instance, $result->{status}, $instance, $result->{speed}, $result->{temperature} |
| 61 |
) |
| 62 |
); |
| 63 |
my $exit = $self->get_severity(section => 'psu', value => $result->{status}); |
| 64 |
if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { |
| 65 |
$self->{output}->output_add( |
| 66 |
severity => $exit, |
| 67 |
short_msg => sprintf( |
| 68 |
"Power supply '%s' status is '%s'", $instance, $result->{status} |
| 69 |
) |
| 70 |
); |
| 71 |
} |
| 72 |
|
| 73 |
if ($result->{speed} =~ /[0-9]/) { |
| 74 |
my ($exit2, $warn, $crit) = $self->get_severity_numeric(section => 'psu.fanspeed', instance => $instance, value => $result->{speed}); |
| 75 |
if (!$self->{output}->is_status(value => $exit2, compare => 'ok', litteral => 1)) { |
| 76 |
$self->{output}->output_add( |
| 77 |
severity => $exit, |
| 78 |
short_msg => sprintf( |
| 79 |
"Power supply '%s' fan speed is %s rpm", $instance, $result->{speed} |
| 80 |
) |
| 81 |
); |
| 82 |
} |
| 83 |
|
| 84 |
$self->{output}->perfdata_add( |
| 85 |
nlabel => 'hardware.powersupply.fan.speed.rpm', |
| 86 |
unit => 'rpm', |
| 87 |
instances => $instance, |
| 88 |
value => $result->{speed}, |
| 89 |
min => 0 |
| 90 |
); |
| 91 |
} |
| 92 |
|
| 93 |
if ($result->{temperature} =~ /[0-9]/) { |
| 94 |
my ($exit2, $warn, $crit) = $self->get_severity_numeric(section => 'psu.temperature', instance => $instance, value => $result->{temperature}); |
| 95 |
if (!$self->{output}->is_status(value => $exit2, compare => 'ok', litteral => 1)) { |
| 96 |
$self->{output}->output_add( |
| 97 |
severity => $exit, |
| 98 |
short_msg => sprintf( |
| 99 |
"Power supply '%s' temperature is %s C", $instance, $result->{temperature} |
| 100 |
) |
| 101 |
); |
| 102 |
} |
| 103 |
|
| 104 |
$self->{output}->perfdata_add( |
| 105 |
nlabel => 'hardware.powersupply.temperature.celsius', |
| 106 |
unit => 'C', |
| 107 |
instances => $instance, |
| 108 |
value => $result->{temperature} |
| 109 |
); |
| 110 |
} |
| 111 |
} |
| 112 |
} |
| 113 |
|
| 114 |
sub check_psu_qts { |
| 115 |
my ($self, %options) = @_; |
| 116 |
|
| 117 |
my $oid_sysPowerStatus = '.1.3.6.1.4.1.55062.1.12.19.0'; |
| 118 |
my $snmp_result = $self->{snmp}->get_leef( |
| 119 |
oids => [$oid_sysPowerStatus] |
| 120 |
); |
| 121 |
|
| 122 |
return if (!defined($snmp_result->{$oid_sysPowerStatus})); |
| 123 |
|
| 124 |
my $instance = 1; |
| 125 |
my $status = $map_status->{ $snmp_result->{$oid_sysPowerStatus} }; |
| 126 |
|
| 127 |
return if ($self->check_filter(section => 'psu', instance => $instance)); |
| 128 |
|
| 129 |
$self->{components}->{psu}->{total}++; |
| 130 |
|
| 131 |
$self->{output}->output_add( |
| 132 |
long_msg => sprintf( |
| 133 |
"system power supply status is '%s' [instance: %s]", |
| 134 |
$status, $instance |
| 135 |
) |
| 136 |
); |
| 137 |
my $exit = $self->get_severity(section => 'psu', value => $status); |
| 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 |
"Sytem power supply status is '%s'", $status |
| 143 |
) |
| 144 |
); |
| 145 |
} |
| 146 |
} |
| 147 |
|
| 148 |
sub check_psu_es { |
| 149 |
my ($self, %options) = @_; |
| 150 |
|
| 151 |
my $snmp_result = $self->{snmp}->get_table( |
| 152 |
oid => '.1.3.6.1.4.1.24681.2.2.21', # es-SystemPowerTable |
| 153 |
start => $mapping->{es}->{status}->{oid} |
| 154 |
); |
| 155 |
check_psu_result($self, type => 'es', snmp_result => $snmp_result); |
| 156 |
} |
| 157 |
|
| 158 |
sub check_psu_ex { |
| 159 |
my ($self, %options) = @_; |
| 160 |
|
| 161 |
my $snmp_result = $self->{snmp}->get_table( |
| 162 |
oid => '.1.3.6.1.4.1.24681.1.4.1.1.1.1.3.2', # systemPowerTable |
| 163 |
start => $mapping->{ex}->{status}->{oid} |
| 164 |
); |
| 165 |
check_psu_result($self, type => 'ex', snmp_result => $snmp_result); |
| 166 |
} |
| 167 |
|
| 168 |
sub check { |
| 169 |
my ($self) = @_; |
| 170 |
|
| 171 |
$self->{output}->output_add(long_msg => "Checking power supplies"); |
| 172 |
$self->{components}->{psu} = { name => 'psu', total => 0, skip => 0 }; |
| 173 |
return if ($self->check_filter(section => 'psu')); |
| 174 |
|
| 175 |
if ($self->{is_qts} == 1) { |
| 176 |
check_psu_qts($self); |
| 177 |
} elsif ($self->{is_es} == 1) { |
| 178 |
check_psu_es($self); |
| 179 |
} else { |
| 180 |
check_psu_ex($self); |
| 181 |
} |
| 182 |
} |
| 183 |
|
| 184 |
1; |