| 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::powerware::snmp::mode::batterystatus; |
| 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 catalog_status_calc); |
| 28 |
|
| 29 |
sub custom_status_output { |
| 30 |
my ($self, %options) = @_; |
| 31 |
|
| 32 |
my $msg = sprintf("battery status is '%s'", $self->{result_values}->{status}); |
| 33 |
return $msg; |
| 34 |
} |
| 35 |
|
| 36 |
sub set_counters { |
| 37 |
my ($self, %options) = @_; |
| 38 |
|
| 39 |
$self->{maps_counters_type} = [ |
| 40 |
{ name => 'global', type => 0, skipped_code => { -10 => 1 } }, |
| 41 |
]; |
| 42 |
|
| 43 |
$self->{maps_counters}->{global} = [ |
| 44 |
{ label => 'status', threshold => 0, set => { |
| 45 |
key_values => [ { name => 'status' } ], |
| 46 |
closure_custom_calc => \&catalog_status_calc, |
| 47 |
closure_custom_output => $self->can('custom_status_output'), |
| 48 |
closure_custom_perfdata => sub { return 0; }, |
| 49 |
closure_custom_threshold_check => \&catalog_status_threshold |
| 50 |
} |
| 51 |
}, |
| 52 |
{ label => 'charge-remaining', , nlabel => 'battery.charge.remaining.percent', set => { |
| 53 |
key_values => [ { name => 'xupsBatCapacity' } ], |
| 54 |
output_template => 'remaining capacity: %s %%', |
| 55 |
perfdatas => [ |
| 56 |
{ template => '%s', min => 0, max => 100, unit => '%' } |
| 57 |
] |
| 58 |
} |
| 59 |
}, |
| 60 |
{ label => 'charge-remaining-minutes', nlabel => 'battery.charge.remaining.minutes', display_ok => 0, set => { |
| 61 |
key_values => [ { name => 'xupsBatTimeRemaining' } ], |
| 62 |
output_template => 'remaining time: %s minutes', |
| 63 |
perfdatas => [ |
| 64 |
{ template => '%s', min => 0, unit => 'm' } |
| 65 |
] |
| 66 |
} |
| 67 |
}, |
| 68 |
{ label => 'current', nlabel => 'battery.current.ampere', display_ok => 0, set => { |
| 69 |
key_values => [ { name => 'xupsBatCurrent', no_value => 0 } ], |
| 70 |
output_template => 'current: %s A', |
| 71 |
perfdatas => [ |
| 72 |
{ template => '%s', unit => 'A' } |
| 73 |
] |
| 74 |
} |
| 75 |
}, |
| 76 |
{ label => 'voltage', nlabel => 'battery.voltage.volt', display_ok => 0, set => { |
| 77 |
key_values => [ { name => 'xupsBatVoltage', no_value => 0 } ], |
| 78 |
output_template => 'voltage: %s V', |
| 79 |
perfdatas => [ |
| 80 |
{ template => '%s', unit => 'V' } |
| 81 |
] |
| 82 |
} |
| 83 |
} |
| 84 |
]; |
| 85 |
} |
| 86 |
|
| 87 |
sub new { |
| 88 |
my ($class, %options) = @_; |
| 89 |
my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1); |
| 90 |
bless $self, $class; |
| 91 |
|
| 92 |
$options{options}->add_options(arguments => { |
| 93 |
'unknown-status:s' => { name => 'unknown_status', default => '%{status} =~ /unknown/i' }, |
| 94 |
'warning-status:s' => { name => 'warning_status', default => '%{status} =~ /batteryDischarging/i' }, |
| 95 |
'critical-status:s' => { name => 'critical_status', default => '' } |
| 96 |
}); |
| 97 |
|
| 98 |
return $self; |
| 99 |
} |
| 100 |
|
| 101 |
sub check_options { |
| 102 |
my ($self, %options) = @_; |
| 103 |
$self->SUPER::check_options(%options); |
| 104 |
|
| 105 |
$self->change_macros(macros => ['warning_status', 'critical_status', 'unknown_status']); |
| 106 |
} |
| 107 |
|
| 108 |
my $map_battery_status = { |
| 109 |
1 => 'batteryCharging', 2 => 'batteryDischarging', |
| 110 |
3 => 'batteryFloating', 4 => 'batteryResting', |
| 111 |
5 => 'unknown' |
| 112 |
}; |
| 113 |
|
| 114 |
my $mapping = { |
| 115 |
xupsBatTimeRemaining => { oid => '.1.3.6.1.4.1.534.1.2.1' }, # in seconds |
| 116 |
xupsBatVoltage => { oid => '.1.3.6.1.4.1.534.1.2.2' }, # in V |
| 117 |
xupsBatCurrent => { oid => '.1.3.6.1.4.1.534.1.2.3' }, # in dA |
| 118 |
xupsBatCapacity => { oid => '.1.3.6.1.4.1.534.1.2.4' }, |
| 119 |
xupsBatteryAbmStatus => { oid => '.1.3.6.1.4.1.534.1.2.5', map => $map_battery_status } |
| 120 |
}; |
| 121 |
|
| 122 |
sub manage_selection { |
| 123 |
my ($self, %options) = @_; |
| 124 |
|
| 125 |
my $snmp_result = $options{snmp}->get_leef( |
| 126 |
oids => [ map($_->{oid} . '.0', values(%$mapping)) ], |
| 127 |
nothing_quit => 1 |
| 128 |
); |
| 129 |
|
| 130 |
my $result = $options{snmp}->map_instance(mapping => $mapping, results => $snmp_result, instance => '0'); |
| 131 |
$result->{xupsBatCurrent} = defined($result->{xupsBatCurrent}) ? $result->{xupsBatCurrent} * 0.1 : 0; |
| 132 |
$result->{xupsBatTimeRemaining} = defined($result->{xupsBatTimeRemaining}) ? int($result->{xupsBatTimeRemaining} / 60) : undef; |
| 133 |
$result->{status} = $result->{xupsBatteryAbmStatus}; |
| 134 |
|
| 135 |
$self->{global} = $result; |
| 136 |
} |
| 137 |
|
| 138 |
1; |
| 139 |
|
| 140 |
__END__ |
| 141 |
|
| 142 |
=head1 MODE |
| 143 |
|
| 144 |
Check battery status. |
| 145 |
|
| 146 |
=over 8 |
| 147 |
|
| 148 |
=item B<--filter-counters> |
| 149 |
|
| 150 |
Only display some counters (regexp can be used). |
| 151 |
Example: --filter-counters='status|current' |
| 152 |
|
| 153 |
=item B<--unknown-status> |
| 154 |
|
| 155 |
Define the conditions to match for the status to be UNKNOWN (default: '%{status} =~ /unknown/i'). |
| 156 |
You can use the following variables: %{status}. |
| 157 |
|
| 158 |
=item B<--warning-status> |
| 159 |
|
| 160 |
Define the conditions to match for the status to be WARNING (default: '%{status} =~ /batteryDischarging/i'). |
| 161 |
You can use the following variables: %{status}. |
| 162 |
|
| 163 |
=item B<--critical-status> |
| 164 |
|
| 165 |
Define the conditions to match for the status to be CRITICAL (default: ''). |
| 166 |
You can use the following variables: %{status}. |
| 167 |
|
| 168 |
=item B<--warning-*> B<--critical-*> |
| 169 |
|
| 170 |
Thresholds. |
| 171 |
Can be: Can be: 'charge-remaining' (%), 'charge-remaining-minutes', |
| 172 |
'current' (A), 'voltage' (V). |
| 173 |
|
| 174 |
=back |
| 175 |
|
| 176 |
=cut |