| 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::ups::ees::snmp::mode::battery; |
| 22 |
|
| 23 |
use base qw(centreon::plugins::templates::counter); |
| 24 |
|
| 25 |
use strict; |
| 26 |
use warnings; |
| 27 |
use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold_ng); |
| 28 |
|
| 29 |
my $map_battery_mode = { |
| 30 |
1 => 'unknown', |
| 31 |
2 => 'FloatCharging', |
| 32 |
3 => 'ShortTest', |
| 33 |
4 => 'BoostChargingForTest', |
| 34 |
5 => 'ManualTesting', |
| 35 |
6 => 'PlanTesting', |
| 36 |
7 => 'ACFailTesting', |
| 37 |
8 => 'ACFail', |
| 38 |
9 => 'ManualBoostCharging', |
| 39 |
10 => 'AutoBoostCharging', |
| 40 |
11 => 'CyclicBoostCharging', |
| 41 |
12 => 'MasterBoostCharging', |
| 42 |
13 => 'MasterBateryTesting' |
| 43 |
}; |
| 44 |
|
| 45 |
sub battery_mode_custom_output { |
| 46 |
my ($self, %options) = @_; |
| 47 |
|
| 48 |
return sprintf("Battery mode: '%s'", $self->{result_values}->{battery_mode}); |
| 49 |
} |
| 50 |
|
| 51 |
sub set_counters { |
| 52 |
my ($self, %options) = @_; |
| 53 |
|
| 54 |
$self->{maps_counters_type} = [ |
| 55 |
{ name => 'battery', type => 0 } |
| 56 |
]; |
| 57 |
|
| 58 |
$self->{maps_counters}->{battery} = [ |
| 59 |
{ |
| 60 |
label => 'voltage', nlabel => 'battery.voltage.volt', |
| 61 |
set => { |
| 62 |
key_values => [ { name => 'voltage' } ], |
| 63 |
output_template => 'voltage: %.2fV', |
| 64 |
perfdatas => [ { template => '%.2f', unit => 'V' } ], |
| 65 |
} |
| 66 |
}, |
| 67 |
{ |
| 68 |
label => 'current', nlabel => 'battery.current.ampere', |
| 69 |
set => { |
| 70 |
key_values => [ { name => 'current' } ], |
| 71 |
output_template => 'current: %.2fA', |
| 72 |
perfdatas => [ { template => '%.2f', unit => 'A' } ], |
| 73 |
} |
| 74 |
}, |
| 75 |
{ |
| 76 |
label => 'capacity', nlabel => 'battery.capacity.percentage', |
| 77 |
set => { |
| 78 |
key_values => [ { name => 'capacity' } ], |
| 79 |
output_template => 'capacity: %.2f%%', |
| 80 |
perfdatas => [ { template => '%.2f', min => 0, max => 100, unit => '%' } ], |
| 81 |
} |
| 82 |
}, |
| 83 |
{ |
| 84 |
label => 'nominal-capacity', nlabel => 'battery.nominal.capacity.amperehour', |
| 85 |
set => { |
| 86 |
key_values => [ { name => 'nominal_capacity' } ], |
| 87 |
output_template => 'used capacity: %.2fAh', |
| 88 |
perfdatas => [ { template => '%.2f', unit => 'Ah' } ], |
| 89 |
} |
| 90 |
}, |
| 91 |
{ |
| 92 |
label => 'battery-mode', |
| 93 |
unknown_default => '%{battery_mode} =~ /unknown/i', |
| 94 |
warning_default => '%{battery_mode} =~ /ShortTest|BoostChargingForTest|ManualTesting|PlanTesting|ManualBoostCharging|AutoBoostCharging|CyclicBoostCharging|MasterBoostCharging|MasterBateryTesting/i', |
| 95 |
critical_default => '%{battery_mode} =~ /ACFailTesting|ACFail/i', |
| 96 |
type => 2, |
| 97 |
set => { |
| 98 |
key_values => [ { name => 'battery_mode' } ], |
| 99 |
closure_custom_threshold_check => \&catalog_status_threshold_ng, |
| 100 |
closure_custom_perfdata => sub {return 0;}, |
| 101 |
closure_custom_output => $self->can('battery_mode_custom_output') |
| 102 |
} |
| 103 |
} |
| 104 |
]; |
| 105 |
} |
| 106 |
|
| 107 |
sub new { |
| 108 |
my ($class, %options) = @_; |
| 109 |
my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1); |
| 110 |
bless $self, $class; |
| 111 |
|
| 112 |
$options{options}->add_options(arguments => {}); |
| 113 |
|
| 114 |
return $self; |
| 115 |
} |
| 116 |
|
| 117 |
sub manage_selection { |
| 118 |
my ($self, %options) = @_; |
| 119 |
|
| 120 |
my $oid_psStatusBatteryMode = '.1.3.6.1.4.1.6302.2.1.2.9.0'; |
| 121 |
my $oid_psBatteryVoltage = '.1.3.6.1.4.1.6302.2.1.2.5.1.0'; |
| 122 |
my $oid_psTotalBatteryCurrent = '.1.3.6.1.4.1.6302.2.1.2.5.2.0'; |
| 123 |
my $oid_psBatteryCapacity = '.1.3.6.1.4.1.6302.2.1.2.5.3.0'; |
| 124 |
my $oid_psBatteryNominalCapacity = '.1.3.6.1.4.1.6302.2.1.2.5.4.0'; |
| 125 |
|
| 126 |
my $snmp_result = $options{snmp}->get_leef( |
| 127 |
oids => [ |
| 128 |
$oid_psStatusBatteryMode, |
| 129 |
$oid_psBatteryVoltage, |
| 130 |
$oid_psTotalBatteryCurrent, |
| 131 |
$oid_psBatteryCapacity, |
| 132 |
$oid_psBatteryNominalCapacity |
| 133 |
], |
| 134 |
nothing_quit => 1 |
| 135 |
); |
| 136 |
|
| 137 |
$self->{battery} = { |
| 138 |
voltage => $snmp_result->{$oid_psBatteryVoltage} / 1000, |
| 139 |
current => $snmp_result->{$oid_psTotalBatteryCurrent} / 1000, |
| 140 |
capacity => $snmp_result->{$oid_psBatteryCapacity} / 1000, |
| 141 |
nominal_capacity => $snmp_result->{$oid_psBatteryNominalCapacity} / 1000, |
| 142 |
battery_mode => $map_battery_mode->{$snmp_result->{$oid_psStatusBatteryMode}}, |
| 143 |
}; |
| 144 |
} |
| 145 |
|
| 146 |
1; |
| 147 |
|
| 148 |
__END__ |
| 149 |
|
| 150 |
=head1 MODE |
| 151 |
|
| 152 |
Check battery. |
| 153 |
|
| 154 |
=over 8 |
| 155 |
|
| 156 |
=item B<--warning-*> B<--critical-*> |
| 157 |
|
| 158 |
Thresholds: voltage (V), current (A), capacity (%), nominal-capacity (Ah) |
| 159 |
|
| 160 |
=item B<--unknown-battery-mode> |
| 161 |
|
| 162 |
Define the conditions to match for the status to be UNKNOWN (default: '%{battery_mode} =~ /unknown/i'). |
| 163 |
You can use the following variables: %{battery_mode} |
| 164 |
|
| 165 |
=item B<--warning-battery-mode> |
| 166 |
|
| 167 |
Define the conditions to match for the status to be WARNING (default: '%{battery_mode} =~ /ShortTest|BoostChargingForTest|ManualTesting|PlanTesting|ManualBoostCharging|AutoBoostCharging|CyclicBoostCharging|MasterBoostCharging|MasterBateryTesting/i'). |
| 168 |
You can use the following variables: %{battery_mode} |
| 169 |
|
| 170 |
=item B<--critical-battery-mode> |
| 171 |
|
| 172 |
Define the conditions to match for the status to be CRITICAL (default: '%{battery_mode} =~ /ACFailTesting|ACFail/i'). |
| 173 |
You can use the following variables: %{battery_mode} |
| 174 |
|
| 175 |
=back |
| 176 |
|
| 177 |
=cut |