| 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::emc::datadomain::snmp::mode::components::battery; |
| 22 |
|
| 23 |
use strict; |
| 24 |
use warnings; |
| 25 |
use centreon::plugins::misc; |
| 26 |
|
| 27 |
my %map_battery_status = (); |
| 28 |
my ($oid_nvramBatteryStatus, $oid_nvramBatteryCharge); |
| 29 |
my $oid_nvramBatteryEntry = '.1.3.6.1.4.1.19746.1.2.3.1.1'; |
| 30 |
|
| 31 |
sub load { |
| 32 |
my ($self) = @_; |
| 33 |
|
| 34 |
push @{$self->{request}}, { oid => $oid_nvramBatteryEntry }; |
| 35 |
} |
| 36 |
|
| 37 |
sub check { |
| 38 |
my ($self) = @_; |
| 39 |
|
| 40 |
$self->{output}->output_add(long_msg => "Checking nvram batteries"); |
| 41 |
$self->{components}->{battery} = {name => 'nvram batteries', total => 0, skip => 0}; |
| 42 |
return if ($self->check_filter(section => 'battery')); |
| 43 |
|
| 44 |
if (centreon::plugins::misc::minimal_version($self->{os_version}, '5.x')) { |
| 45 |
$oid_nvramBatteryStatus = '.1.3.6.1.4.1.19746.1.2.3.1.1.3'; |
| 46 |
$oid_nvramBatteryCharge = '.1.3.6.1.4.1.19746.1.2.3.1.1.4'; |
| 47 |
%map_battery_status = (0 => 'ok', 1 => 'disabled', 2 => 'discharged', 4 => 'softdisabled'); |
| 48 |
} else { |
| 49 |
$oid_nvramBatteryStatus = '.1.3.6.1.4.1.19746.1.2.3.1.1.2'; |
| 50 |
$oid_nvramBatteryCharge = '.1.3.6.1.4.1.19746.1.2.3.1.1.3'; |
| 51 |
%map_battery_status = ( |
| 52 |
1 => 'ok', 2 => 'disabled', 3 => 'discharged', 4 => 'unknown', |
| 53 |
5 => 'softdisabled' |
| 54 |
); |
| 55 |
} |
| 56 |
|
| 57 |
foreach my $oid (keys %{$self->{results}->{$oid_nvramBatteryEntry}}) { |
| 58 |
next if ($oid !~ /^$oid_nvramBatteryStatus\.(.*)$/); |
| 59 |
my $instance = $1; |
| 60 |
my $batt_status = defined($map_battery_status{$self->{results}->{$oid_nvramBatteryEntry}->{$oid}}) ? |
| 61 |
$map_battery_status{$self->{results}->{$oid_nvramBatteryEntry}->{$oid}} : 'unknown'; |
| 62 |
my $batt_value = $self->{results}->{$oid_nvramBatteryEntry}->{$oid_nvramBatteryCharge . '.' . $instance}; |
| 63 |
|
| 64 |
next if ($self->check_filter(section => 'battery', instance => $instance)); |
| 65 |
next if ($batt_status =~ /disabled/i && |
| 66 |
$self->absent_problem(section => 'battery', instance => $instance)); |
| 67 |
|
| 68 |
$self->{components}->{battery}->{total}++; |
| 69 |
$self->{output}->output_add( |
| 70 |
long_msg => sprintf( |
| 71 |
"nvram battery '%s' status is '%s'", |
| 72 |
$instance, $batt_status |
| 73 |
) |
| 74 |
); |
| 75 |
|
| 76 |
my $exit = $self->get_severity(section => 'battery', value => $batt_status); |
| 77 |
if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { |
| 78 |
$self->{output}->output_add( |
| 79 |
severity => $exit, |
| 80 |
short_msg => sprintf("Nvram battery '%s' status is '%s'", $instance, $batt_status) |
| 81 |
); |
| 82 |
} |
| 83 |
|
| 84 |
if (defined($batt_value) && $batt_value =~ /[0-9]/) { |
| 85 |
my ($exit, $warn, $crit) = $self->get_severity_numeric(section => 'battery', instance => $instance, value => $batt_value); |
| 86 |
$self->{output}->output_add(long_msg => sprintf("Nvram battery '%s' charge is %s %%", $instance, $batt_value)); |
| 87 |
if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { |
| 88 |
$self->{output}->output_add( |
| 89 |
severity => $exit, |
| 90 |
short_msg => sprintf("Nvram battery '%s' charge is %s %%", $instance, $batt_value) |
| 91 |
); |
| 92 |
} |
| 93 |
|
| 94 |
$self->{output}->perfdata_add( |
| 95 |
nlabel => 'hardware.battery.nvram.charge.percentage', |
| 96 |
unit => '%', |
| 97 |
instances => $instance, |
| 98 |
value => $batt_value, |
| 99 |
warning => $warn, |
| 100 |
critical => $crit, |
| 101 |
min => 0, max => 100 |
| 102 |
); |
| 103 |
} |
| 104 |
} |
| 105 |
} |
| 106 |
|
| 107 |
1; |