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