| 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::socomec::netvision::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 |
sub custom_status_output { |
| 30 |
my ($self, %options) = @_; |
| 31 |
|
| 32 |
return sprintf('battery status is %s', $self->{result_values}->{status}); |
| 33 |
} |
| 34 |
|
| 35 |
sub custom_load_output { |
| 36 |
my ($self, %options) = @_; |
| 37 |
|
| 38 |
return sprintf( |
| 39 |
'charge remaining: %s%% (%s minutes remaining)', |
| 40 |
$self->{result_values}->{charge_remain}, |
| 41 |
$self->{result_values}->{minute_remain} |
| 42 |
); |
| 43 |
} |
| 44 |
|
| 45 |
sub set_counters { |
| 46 |
my ($self, %options) = @_; |
| 47 |
|
| 48 |
$self->{maps_counters_type} = [ |
| 49 |
{ name => 'global', type => 0, message_separator => ' - ', skipped_code => { -10 => 1 } } |
| 50 |
]; |
| 51 |
|
| 52 |
$self->{maps_counters}->{global} = [ |
| 53 |
{ |
| 54 |
label => 'status', |
| 55 |
type => 2, |
| 56 |
unknown_default => '%{status} =~ /unknown/i', |
| 57 |
warning_default => '%{status} =~ /low/i', |
| 58 |
critical_default => '%{status} =~ /depleted|failure/i', |
| 59 |
set => { |
| 60 |
key_values => [ { name => 'status' } ], |
| 61 |
closure_custom_output => $self->can('custom_status_output'), |
| 62 |
closure_custom_perfdata => sub { return 0; }, |
| 63 |
closure_custom_threshold_check => \&catalog_status_threshold_ng |
| 64 |
} |
| 65 |
}, |
| 66 |
{ label => 'charge-remaining', nlabel => 'battery.charge.remaining.percent', set => { |
| 67 |
key_values => [ { name => 'charge_remain' }, { name => 'minute_remain' } ], |
| 68 |
closure_custom_output => $self->can('custom_load_output'), |
| 69 |
perfdatas => [ |
| 70 |
{ template => '%s', min => 0, max => 100, unit => '%' } |
| 71 |
] |
| 72 |
} |
| 73 |
}, |
| 74 |
{ label => 'charge-remaining-minutes', nlabel => 'battery.charge.remaining.minutes', display_ok => 0, set => { |
| 75 |
key_values => [ { name => 'minute_remain', no_value => 'unknown' } ], |
| 76 |
output_template => 'minutes remaining: %s', |
| 77 |
perfdatas => [ |
| 78 |
{ template => '%s', min => 0 } |
| 79 |
] |
| 80 |
} |
| 81 |
}, |
| 82 |
{ label => 'current', nlabel => 'battery.current.ampere', display_ok => 0, set => { |
| 83 |
key_values => [ { name => 'current', no_value => 0 } ], |
| 84 |
output_template => 'current: %s A', |
| 85 |
perfdatas => [ |
| 86 |
{ template => '%s', min => 0, unit => 'A' } |
| 87 |
] |
| 88 |
} |
| 89 |
}, |
| 90 |
{ label => 'voltage', nlabel => 'battery.voltage.volt', display_ok => 0, set => { |
| 91 |
key_values => [ { name => 'voltage', no_value => 0 } ], |
| 92 |
output_template => 'voltage: %s V', |
| 93 |
perfdatas => [ |
| 94 |
{ template => '%s', unit => 'V' } |
| 95 |
] |
| 96 |
} |
| 97 |
}, |
| 98 |
{ label => 'temperature', nlabel => 'battery.temperature.celsius', display_ok => 0, set => { |
| 99 |
key_values => [ { name => 'temperature', no_value => 0 } ], |
| 100 |
output_template => 'temperature: %s C', |
| 101 |
perfdatas => [ |
| 102 |
{ template => '%s', unit => 'C' } |
| 103 |
] |
| 104 |
} |
| 105 |
} |
| 106 |
]; |
| 107 |
} |
| 108 |
|
| 109 |
sub new { |
| 110 |
my ($class, %options) = @_; |
| 111 |
my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1); |
| 112 |
bless $self, $class; |
| 113 |
|
| 114 |
$options{options}->add_options(arguments => { |
| 115 |
}); |
| 116 |
|
| 117 |
return $self; |
| 118 |
} |
| 119 |
|
| 120 |
my $map_status_v6 = { |
| 121 |
1 => 'unknown', 2 => 'normal', 3 => 'charging', 4 => 'test', |
| 122 |
5 => 'discharging', 6 => 'low', 7 => 'depleted', 8 => 'failure', |
| 123 |
9 => 'disconnected' |
| 124 |
}; |
| 125 |
my $map_status_v5 = { |
| 126 |
1 => 'unknown', 2 => 'normal', 3 => 'low', |
| 127 |
4 => 'depleted', 5 => 'discharging', |
| 128 |
6 => 'failure', 7 => 'upsOff' |
| 129 |
}; |
| 130 |
|
| 131 |
my $mapping = { |
| 132 |
netvision5 => { |
| 133 |
status => { oid => '.1.3.6.1.4.1.4555.1.1.1.1.2.1', map => $map_status_v5 }, # upsBatteryStatus |
| 134 |
minute_remain => { oid => '.1.3.6.1.4.1.4555.1.1.1.1.2.3' }, # upsEstimatedMinutesRemaining |
| 135 |
charge_remain => { oid => '.1.3.6.1.4.1.4555.1.1.1.1.2.4' }, # upsEstimatedChargeRemaining |
| 136 |
voltage => { oid => '.1.3.6.1.4.1.4555.1.1.1.1.2.5' }, # upsBatteryVoltage (dV) |
| 137 |
temperature => { oid => '.1.3.6.1.4.1.4555.1.1.1.1.2.6' } # upsBatteryTemperature (degrees Centigrade) |
| 138 |
}, |
| 139 |
netvision6 => { |
| 140 |
status => { oid => '.1.3.6.1.4.1.4555.1.1.7.1.2.1', map => $map_status_v6 }, # upsBatteryStatus |
| 141 |
minute_remain => { oid => '.1.3.6.1.4.1.4555.1.1.7.1.2.3' }, # upsEstimatedMinutesRemaining |
| 142 |
charge_remain => { oid => '.1.3.6.1.4.1.4555.1.1.7.1.2.4' }, # upsEstimatedChargeRemaining |
| 143 |
voltage => { oid => '.1.3.6.1.4.1.4555.1.1.7.1.2.5' }, # upsBatteryVoltage (dV) |
| 144 |
temperature => { oid => '.1.3.6.1.4.1.4555.1.1.7.1.2.6' }, # upsBatteryTemperature (degrees Centigrade) |
| 145 |
current => { oid => '.1.3.6.1.4.1.4555.1.1.7.1.2.8' } # upsBatteryCurrent (dA) |
| 146 |
} |
| 147 |
}; |
| 148 |
|
| 149 |
sub manage_selection { |
| 150 |
my ($self, %options) = @_; |
| 151 |
|
| 152 |
my $label = 'netvision6'; |
| 153 |
my $snmp_result = $options{snmp}->get_leef( |
| 154 |
oids => [ map($_->{oid} . '.0', values(%{$mapping->{$label}})) ] |
| 155 |
); |
| 156 |
if (!defined($snmp_result->{ $mapping->{netvision6}->{status}->{oid} . '.0' })) { |
| 157 |
$label = 'netvision5'; |
| 158 |
$snmp_result = $options{snmp}->get_leef( |
| 159 |
oids => [ map($_->{oid} . '.0', values(%{$mapping->{$label}})) ], |
| 160 |
nothing_quit => 1 |
| 161 |
); |
| 162 |
} |
| 163 |
|
| 164 |
$self->{global} = $options{snmp}->map_instance(mapping => $mapping->{$label}, results => $snmp_result, instance => 0); |
| 165 |
$self->{global}->{current} = (defined($self->{global}->{current}) && $self->{global}->{current} =~ /\d/ && $self->{global}->{current} != -1 && $self->{global}->{current} != 65535) ? |
| 166 |
$self->{global}->{current} * 0.1 : 0; |
| 167 |
$self->{global}->{voltage} = (defined($self->{global}->{voltage}) && $self->{global}->{voltage} =~ /\d/ && $self->{global}->{voltage} != -1 && $self->{global}->{voltage} != 65535) ? |
| 168 |
$self->{global}->{voltage} * 0.1 : 0; |
| 169 |
$self->{global}->{temperature} = (defined($self->{global}->{temperature}) && $self->{global}->{temperature} =~ /\d/) ? $self->{global}->{temperature} * 0.1 : 0; |
| 170 |
$self->{global}->{minute_remain} = (defined($self->{global}->{minute_remain}) && $self->{global}->{minute_remain} =~ /\d/ && $self->{global}->{minute_remain} != -1) ? $self->{global}->{minute_remain} : 'unknown'; |
| 171 |
$self->{global}->{charge_remain} = (defined($self->{global}->{charge_remain}) && $self->{global}->{charge_remain} =~ /\d/) ? $self->{global}->{charge_remain} : undef; |
| 172 |
} |
| 173 |
|
| 174 |
1; |
| 175 |
|
| 176 |
__END__ |
| 177 |
|
| 178 |
=head1 MODE |
| 179 |
|
| 180 |
Check battery status and charge remaining. |
| 181 |
|
| 182 |
=over 8 |
| 183 |
|
| 184 |
=item B<--unknown-status> |
| 185 |
|
| 186 |
Define the conditions to match for the status to be UNKNOWN (default: '%{status} =~ /unknown/i'). |
| 187 |
You can use the following variables: %{status} |
| 188 |
|
| 189 |
=item B<--warning-status> |
| 190 |
|
| 191 |
Define the conditions to match for the status to be WARNING (default: '%{status} =~ /low/i'). |
| 192 |
You can use the following variables: %{status} |
| 193 |
|
| 194 |
=item B<--critical-status> |
| 195 |
|
| 196 |
Define the conditions to match for the status to be CRITICAL (default: '%{status} =~ /depleted|failure/i'). |
| 197 |
You can use the following variables: %{status} |
| 198 |
|
| 199 |
=item B<--warning-*> B<--critical-*> |
| 200 |
|
| 201 |
Thresholds. |
| 202 |
Can be: 'charge-remaining' (%), 'charge-remaining-minutes', |
| 203 |
'current' (A), 'voltage' (V), 'temperature' (C). |
| 204 |
|
| 205 |
=back |
| 206 |
|
| 207 |
=cut |