| 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 hardware::server::fujitsu::snmp::mode::components::psu; |
| 22 |
|
| 23 |
use strict; |
| 24 |
use warnings; |
| 25 |
|
| 26 |
my $map_psu_status = { |
| 27 |
1 => 'unknown', 2 => 'not-present', 3 => 'ok', 4 => 'failed', 5 => 'ac-fail', 6 => 'dc-fail', |
| 28 |
7 => 'critical-temperature', 8 => 'not-manageable', 9 => 'fan-failure-predicted', 10 => 'fan-failure', |
| 29 |
11 => 'power-safe-mode', 12 => 'non-redundant-dc-fail', 13 => 'non-redundant-ac-fail' |
| 30 |
}; |
| 31 |
|
| 32 |
my $mapping = { |
| 33 |
sc => { |
| 34 |
powerSupplyUnitStatus => { oid => '.1.3.6.1.4.1.231.2.10.2.2.5.11.2.1.3', map => $map_psu_status }, |
| 35 |
powerSupplyUnitDesignation => { oid => '.1.3.6.1.4.1.231.2.10.2.2.5.11.2.1.4' } |
| 36 |
}, |
| 37 |
sc2 => { |
| 38 |
sc2PowerSupplyDesignation => { oid => '.1.3.6.1.4.1.231.2.10.2.2.10.6.2.1.3' }, |
| 39 |
sc2PowerSupplyStatus => { oid => '.1.3.6.1.4.1.231.2.10.2.2.10.6.2.1.5', map => $map_psu_status }, |
| 40 |
sc2psPowerSupplyLoad => { oid => '.1.3.6.1.4.1.231.2.10.2.2.10.6.2.1.6' } |
| 41 |
} |
| 42 |
}; |
| 43 |
my $oid_sc2PowerSupply = '.1.3.6.1.4.1.231.2.10.2.2.10.6.2.1'; |
| 44 |
my $oid_powerSupplyUnits = '.1.3.6.1.4.1.231.2.10.2.2.5.11.2.1'; |
| 45 |
|
| 46 |
sub load { |
| 47 |
my ($self) = @_; |
| 48 |
|
| 49 |
push @{$self->{request}}, { oid => $oid_sc2PowerSupply }, { oid => $oid_powerSupplyUnits }; |
| 50 |
} |
| 51 |
|
| 52 |
sub check_psu { |
| 53 |
my ($self, %options) = @_; |
| 54 |
|
| 55 |
my ($exit, $warn, $crit, $checked); |
| 56 |
foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$self->{results}->{$options{entry}}})) { |
| 57 |
next if ($oid !~ /^$options{mapping}->{$options{status}}->{oid}\.(.*)$/); |
| 58 |
my $instance = $1; |
| 59 |
my $result = $self->{snmp}->map_instance(mapping => $options{mapping}, results => $self->{results}->{$options{entry}}, instance => $instance); |
| 60 |
|
| 61 |
next if ($self->check_filter(section => 'psu', instance => $instance)); |
| 62 |
next if ($result->{$options{status}} =~ /not-present|not-available/i && |
| 63 |
$self->absent_problem(section => 'psu', instance => $instance)); |
| 64 |
$self->{components}->{psu}->{total}++; |
| 65 |
|
| 66 |
$self->{output}->output_add( |
| 67 |
long_msg => sprintf( |
| 68 |
"power supply '%s' status is '%s' [instance: %s] [value: %s]", |
| 69 |
$result->{$options{name}}, $result->{$options{status}}, $instance, $result->{$options{current}} |
| 70 |
) |
| 71 |
); |
| 72 |
|
| 73 |
$exit = $self->get_severity(section => 'psu', value => $result->{$options{status}}); |
| 74 |
if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { |
| 75 |
$self->{output}->output_add( |
| 76 |
severity => $exit, |
| 77 |
short_msg => sprintf("Power supply '%s' status is '%s'", $result->{$options{name}}, $result->{$options{status}}) |
| 78 |
); |
| 79 |
} |
| 80 |
|
| 81 |
next if (!defined($result->{$options{current}}) || $result->{$options{current}} == 0); |
| 82 |
|
| 83 |
($exit, $warn, $crit, $checked) = $self->get_severity_numeric(section => 'power', instance => $instance, value => $result->{$options{current}}); |
| 84 |
if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { |
| 85 |
$self->{output}->output_add( |
| 86 |
severity => $exit, |
| 87 |
short_msg => sprintf("Power supply '%s' is %s W", $result->{$options{name}}, $result->{$options{current}}) |
| 88 |
); |
| 89 |
} |
| 90 |
$self->{output}->perfdata_add( |
| 91 |
nlabel => 'hardware.powersupply.power.watt', |
| 92 |
unit => 'W', |
| 93 |
instances => $result->{$options{name}}, |
| 94 |
value => $result->{$options{current}}, |
| 95 |
warning => $warn, |
| 96 |
critical => $crit, |
| 97 |
min => 0 |
| 98 |
); |
| 99 |
} |
| 100 |
} |
| 101 |
|
| 102 |
sub check { |
| 103 |
my ($self) = @_; |
| 104 |
|
| 105 |
$self->{output}->output_add(long_msg => 'Checking poer supplies'); |
| 106 |
$self->{components}->{psu} = { name => 'psus', total => 0, skip => 0 }; |
| 107 |
return if ($self->check_filter(section => 'psu')); |
| 108 |
|
| 109 |
if (defined($self->{results}->{$oid_sc2PowerSupply}) && scalar(keys %{$self->{results}->{$oid_sc2PowerSupply}}) > 0) { |
| 110 |
check_psu( |
| 111 |
$self, entry => $oid_sc2PowerSupply, mapping => $mapping->{sc2}, name => 'sc2PowerSupplyDesignation', |
| 112 |
current => 'sc2psPowerSupplyLoad', status => 'sc2PowerSupplyStatus' |
| 113 |
); |
| 114 |
} else { |
| 115 |
check_psu( |
| 116 |
$self, entry => $oid_powerSupplyUnits, mapping => $mapping->{sc}, name => 'powerSupplyUnitDesignation', |
| 117 |
status => 'powerSupplyUnitStatus' |
| 118 |
); |
| 119 |
} |
| 120 |
} |
| 121 |
|
| 122 |
1; |