| 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::dell::idrac::snmp::mode::components::amperage; |
| 22 |
|
| 23 |
use strict; |
| 24 |
use warnings; |
| 25 |
use hardware::server::dell::idrac::snmp::mode::components::resources qw(%map_probe_status %map_state %map_amperage_type); |
| 26 |
|
| 27 |
my $mapping = { |
| 28 |
amperageProbeStateSettings => { oid => '.1.3.6.1.4.1.674.10892.5.4.600.30.1.4', map => \%map_state }, |
| 29 |
amperageProbeStatus => { oid => '.1.3.6.1.4.1.674.10892.5.4.600.30.1.5', map => \%map_probe_status }, |
| 30 |
amperageProbeReading => { oid => '.1.3.6.1.4.1.674.10892.5.4.600.30.1.6' }, |
| 31 |
amperageProbeType => { oid => '.1.3.6.1.4.1.674.10892.5.4.600.30.1.7', map => \%map_amperage_type }, |
| 32 |
amperageProbeLocationName => { oid => '.1.3.6.1.4.1.674.10892.5.4.600.30.1.8' }, |
| 33 |
amperageProbeUpperCriticalThreshold => { oid => '.1.3.6.1.4.1.674.10892.5.4.600.30.1.10' }, |
| 34 |
amperageProbeUpperNonCriticalThreshold => { oid => '.1.3.6.1.4.1.674.10892.5.4.600.30.1.11' }, |
| 35 |
amperageProbeLowerNonCriticalThreshold => { oid => '.1.3.6.1.4.1.674.10892.5.4.600.30.1.12' }, |
| 36 |
amperageProbeLowerCriticalThreshold => { oid => '.1.3.6.1.4.1.674.10892.5.4.600.30.1.13' } |
| 37 |
}; |
| 38 |
my $oid_amperageProbeTableEntry = '.1.3.6.1.4.1.674.10892.5.4.600.30.1'; |
| 39 |
|
| 40 |
sub load { |
| 41 |
my ($self) = @_; |
| 42 |
|
| 43 |
push @{$self->{request}}, { |
| 44 |
oid => $oid_amperageProbeTableEntry, |
| 45 |
start => $mapping->{amperageProbeStateSettings}->{oid}, |
| 46 |
end => $mapping->{amperageProbeLowerCriticalThreshold}->{oid} |
| 47 |
}; |
| 48 |
} |
| 49 |
|
| 50 |
sub check { |
| 51 |
my ($self) = @_; |
| 52 |
|
| 53 |
$self->{output}->output_add(long_msg => "Checking amperages"); |
| 54 |
$self->{components}->{amperage} = {name => 'amperages', total => 0, skip => 0}; |
| 55 |
return if ($self->check_filter(section => 'amperage')); |
| 56 |
|
| 57 |
foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$self->{results}->{$oid_amperageProbeTableEntry}})) { |
| 58 |
next if ($oid !~ /^$mapping->{amperageProbeStatus}->{oid}\.(\d+)\.(\d+)$/); |
| 59 |
my $instance = $1 . '.' . $2; |
| 60 |
my $chassis_name = $self->get_chassis_name(id => $1); |
| 61 |
my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}->{$oid_amperageProbeTableEntry}, instance => $instance); |
| 62 |
|
| 63 |
next if ($self->check_filter(section => 'amperage', instance => $instance, name => $result->{amperageProbeLocationName})); |
| 64 |
$self->{components}->{amperage}->{total}++; |
| 65 |
|
| 66 |
my ($divisor, $unit) = (1000, 'A'); |
| 67 |
if ($result->{amperageProbeType} =~ /amperageProbeTypeIsPowerSupplyAmps|amperageProbeTypeIsSystemAmps/) { |
| 68 |
$divisor = 10; |
| 69 |
} elsif ($result->{amperageProbeType} =~ /amperageProbeTypeIsPowerSupplyWatts|amperageProbeTypeIsSystemWatts/) { |
| 70 |
$unit = 'W'; |
| 71 |
$divisor = 1; |
| 72 |
} |
| 73 |
$result->{amperageProbeReading} = (defined($result->{amperageProbeReading})) ? $result->{amperageProbeReading} / $divisor : 'unknown'; |
| 74 |
$self->{output}->output_add( |
| 75 |
long_msg => sprintf( |
| 76 |
"amperage '%s' status is '%s' [instance: %s] [state: %s] [value: %s]", |
| 77 |
$result->{amperageProbeLocationName}, $result->{amperageProbeStatus}, $instance, |
| 78 |
$result->{amperageProbeStateSettings}, $result->{amperageProbeReading} |
| 79 |
) |
| 80 |
); |
| 81 |
|
| 82 |
my $exit = $self->get_severity(label => 'default.state', section => 'amperage.state', value => $result->{amperageProbeStateSettings}); |
| 83 |
if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { |
| 84 |
$self->{output}->output_add( |
| 85 |
severity => $exit, |
| 86 |
short_msg => sprintf("Amperage '%s' state is '%s'", $result->{amperageProbeLocationName}, $result->{amperageProbeStateSettings}) |
| 87 |
); |
| 88 |
next; |
| 89 |
} |
| 90 |
|
| 91 |
$exit = $self->get_severity(label => 'probe.status', section => 'amperage.status', value => $result->{amperageProbeStatus}); |
| 92 |
if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { |
| 93 |
$self->{output}->output_add( |
| 94 |
severity => $exit, |
| 95 |
short_msg => sprintf( |
| 96 |
"Amperage '%s' status is '%s'", $result->{amperageProbeLocationName}, $result->{amperageProbeStatus}) |
| 97 |
); |
| 98 |
} |
| 99 |
|
| 100 |
next if ($result->{amperageProbeType} =~ /amperageProbeTypeIsDiscrete/); |
| 101 |
|
| 102 |
if (defined($result->{amperageProbeReading}) && $result->{amperageProbeReading} =~ /[0-9]/) { |
| 103 |
my ($exit, $warn, $crit, $checked) = $self->get_severity_numeric( |
| 104 |
section => 'amperage', |
| 105 |
instance => $instance, |
| 106 |
name => $result->{amperageProbeLocationName}, |
| 107 |
value => $result->{amperageProbeReading} |
| 108 |
); |
| 109 |
if ($checked == 0) { |
| 110 |
$result->{amperageProbeLowerNonCriticalThreshold} = (defined($result->{amperageProbeLowerNonCriticalThreshold}) && $result->{amperageProbeLowerNonCriticalThreshold} =~ /[0-9]/) ? |
| 111 |
$result->{amperageProbeLowerNonCriticalThreshold} / $divisor : ''; |
| 112 |
$result->{amperageProbeLowerCriticalThreshold} = (defined($result->{amperageProbeLowerCriticalThreshold}) && $result->{amperageProbeLowerCriticalThreshold} =~ /[0-9]/) ? |
| 113 |
$result->{amperageProbeLowerCriticalThreshold} / $divisor : ''; |
| 114 |
$result->{amperageProbeUpperNonCriticalThreshold} = (defined($result->{amperageProbeUpperNonCriticalThreshold}) && $result->{amperageProbeUpperNonCriticalThreshold} =~ /[0-9]/) ? |
| 115 |
$result->{amperageProbeUpperNonCriticalThreshold} / $divisor : ''; |
| 116 |
$result->{amperageProbeUpperCriticalThreshold} = (defined($result->{amperageProbeUpperCriticalThreshold}) && $result->{amperageProbeUpperCriticalThreshold} =~ /[0-9]/) ? |
| 117 |
$result->{amperageProbeUpperCriticalThreshold} / $divisor : ''; |
| 118 |
my $warn_th = $result->{amperageProbeLowerNonCriticalThreshold} . ':' . $result->{amperageProbeUpperNonCriticalThreshold}; |
| 119 |
my $crit_th = $result->{amperageProbeLowerCriticalThreshold} . ':' . $result->{amperageProbeUpperCriticalThreshold}; |
| 120 |
$self->{perfdata}->threshold_validate(label => 'warning-amperage-instance-' . $instance, value => $warn_th); |
| 121 |
$self->{perfdata}->threshold_validate(label => 'critical-amperage-instance-' . $instance, value => $crit_th); |
| 122 |
|
| 123 |
$exit = $self->{perfdata}->threshold_check( |
| 124 |
value => $result->{amperageProbeReading}, |
| 125 |
threshold => [ |
| 126 |
{ label => 'critical-amperage-instance-' . $instance, exit_litteral => 'critical' }, |
| 127 |
{ label => 'warning-amperage-instance-' . $instance, exit_litteral => 'warning' } |
| 128 |
] |
| 129 |
); |
| 130 |
$warn = $self->{perfdata}->get_perfdata_for_output(label => 'warning-amperage-instance-' . $instance); |
| 131 |
$crit = $self->{perfdata}->get_perfdata_for_output(label => 'critical-amperage-instance-' . $instance); |
| 132 |
} |
| 133 |
|
| 134 |
if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { |
| 135 |
$self->{output}->output_add( |
| 136 |
severity => $exit, |
| 137 |
short_msg => sprintf("Amperage '%s' is %s %s", $result->{amperageProbeLocationName}, $result->{amperageProbeReading}, $unit) |
| 138 |
); |
| 139 |
} |
| 140 |
$self->{output}->perfdata_add( |
| 141 |
nlabel => 'hardware.probe.amperage.' . ($unit eq 'A' ? 'ampere' : 'watt'), |
| 142 |
unit => $unit, |
| 143 |
instances => [$chassis_name, $result->{amperageProbeLocationName}], |
| 144 |
value => $result->{amperageProbeReading}, |
| 145 |
warning => $warn, |
| 146 |
critical => $crit |
| 147 |
); |
| 148 |
} |
| 149 |
} |
| 150 |
} |
| 151 |
|
| 152 |
1; |