Debian Codegraph @

src/hardware/devices/aeg/acm/snmp/mode/batterystatus.pm

raw
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::devices::aeg::acm::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);
28
29 sub custom_status_output {
30 my ($self, %options) = @_;
31
32 my $msg = sprintf("Battery charging mode is '%s'", $self->{result_values}->{status});
33 return $msg;
34 }
35
36 sub custom_status_calc {
37 my ($self, %options) = @_;
38
39 $self->{result_values}->{status} = $options{new_datas}->{$self->{instance} . '_battChargeMode'};
40 return 0;
41 }
42
43 sub set_counters {
44 my ($self, %options) = @_;
45
46 $self->{maps_counters_type} = [
47 { name => 'global', type => 0, skipped_code => { -10 => 1 } },
48 ];
49
50 $self->{maps_counters}->{global} = [
51 { label => 'status', threshold => 0, set => {
52 key_values => [ { name => 'battChargeMode' } ],
53 closure_custom_calc => $self->can('custom_status_calc'),
54 closure_custom_output => $self->can('custom_status_output'),
55 closure_custom_perfdata => sub { return 0; },
56 closure_custom_threshold_check => \&catalog_status_threshold,
57 }
58 },
59 { label => 'voltage', set => {
60 key_values => [ { name => 'battVoltage' } ],
61 output_template => 'Voltage : %s V',
62 perfdatas => [
63 { label => 'voltage', value => 'battVoltage', template => '%s',
64 unit => 'V' },
65 ],
66 }
67 },
68 { label => 'current', set => {
69 key_values => [ { name => 'battCurrent' } ],
70 output_template => 'Current : %s A',
71 perfdatas => [
72 { label => 'current', value => 'battCurrent', template => '%s',
73 min => 0, unit => 'A' },
74 ],
75 }
76 },
77 { label => 'current1', set => {
78 key_values => [ { name => 'battCurrent1' } ],
79 output_template => 'Current 1 : %s A',
80 perfdatas => [
81 { label => 'current1', value => 'battCurrent1', template => '%s',
82 min => 0, unit => 'A' },
83 ],
84 }
85 },
86 { label => 'current2', set => {
87 key_values => [ { name => 'battCurrent2' } ],
88 output_template => 'Current 2 : %s A',
89 perfdatas => [
90 { label => 'current2', value => 'battCurrent2', template => '%s',
91 min => 0, unit => 'A' },
92 ],
93 }
94 },
95 { label => 'temperature', set => {
96 key_values => [ { name => 'battTemp' } ],
97 output_template => 'Temperature : %s C',
98 perfdatas => [
99 { label => 'temperature', value => 'battTemp', template => '%s',
100 unit => 'C'},
101 ],
102 }
103 },
104 { label => 'temperature1', set => {
105 key_values => [ { name => 'battTemp1' } ],
106 output_template => 'Temperature 1 : %s C',
107 perfdatas => [
108 { label => 'temperature1', value => 'battTemp1', template => '%s',
109 unit => 'C'},
110 ],
111 }
112 },
113 { label => 'temperature2', set => {
114 key_values => [ { name => 'battTemp2' } ],
115 output_template => 'Temperature 2 : %s C',
116 perfdatas => [
117 { label => 'temperature2', value => 'battTemp2', template => '%s',
118 unit => 'C'},
119 ],
120 }
121 },
122 { label => 'amphourmeter', set => {
123 key_values => [ { name => 'battAmpHMeter' } ],
124 output_template => 'Amp Hour Meter : %s %%',
125 perfdatas => [
126 { label => 'amphourmeter', value => 'battAmpHMeter', template => '%s',
127 unit => '%'},
128 ],
129 }
130 },
131 ];
132 }
133
134 sub new {
135 my ($class, %options) = @_;
136 my $self = $class->SUPER::new(package => __PACKAGE__, %options);
137 bless $self, $class;
138
139 $options{options}->add_options(arguments => {
140 "warning-status:s" => { name => 'warning_status', default => '%{status} =~ /onBattery/i' },
141 "critical-status:s" => { name => 'critical_status', default => '%{status} =~ /disconnected/i || %{status} =~ /shutdown/i' },
142 });
143
144 return $self;
145 }
146
147 sub check_options {
148 my ($self, %options) = @_;
149 $self->SUPER::check_options(%options);
150
151 $self->change_macros(macros => ['warning_status', 'critical_status']);
152 }
153
154 my %map_battery_mode = (
155 0 => 'initial',
156 1 => 'float',
157 2 => 'highRate',
158 3 => 'dischargeTest',
159 4 => 'presenceTest',
160 5 => 'disconnected',
161 6 => 'onBattery',
162 7 => 'shutdown',
163 8 => 'fallback',
164 9 => 'inhibited',
165 );
166
167 my $mapping_acm1000 = {
168 battChargeMode => { oid => '.1.3.6.1.4.1.15416.37.1.1', map => \%map_battery_mode },
169 battVoltage => { oid => '.1.3.6.1.4.1.15416.37.1.2', divider => '100' },
170 battCurrent => { oid => '.1.3.6.1.4.1.15416.37.1.3', divider => '100' },
171 battTemp => { oid => '.1.3.6.1.4.1.15416.37.1.4', divider => '100' },
172 battAmpHMeter => { oid => '.1.3.6.1.4.1.15416.37.1.5' },
173 };
174 my $mapping_acmi1000 = {
175 battChargeMode => { oid => '.1.3.6.1.4.1.15416.38.1.1', map => \%map_battery_mode },
176 battVoltage => { oid => '.1.3.6.1.4.1.15416.38.1.2', divider => '100' },
177 battCurrent1 => { oid => '.1.3.6.1.4.1.15416.38.1.4', divider => '100' },
178 battCurrent2 => { oid => '.1.3.6.1.4.1.15416.38.1.5', divider => '100' },
179 battTemp1 => { oid => '.1.3.6.1.4.1.15416.38.1.7', divider => '100' },
180 battTemp2 => { oid => '.1.3.6.1.4.1.15416.38.1.8', divider => '100' },
181 battAmpHMeter => { oid => '.1.3.6.1.4.1.15416.38.1.9' },
182 };
183 my $mapping_acm1d = {
184 battVoltage => { oid => '.1.3.6.1.4.1.15416.29.1.1' },
185 battCurrent => { oid => '.1.3.6.1.4.1.15416.29.1.2' },
186 battTemp => { oid => '.1.3.6.1.4.1.15416.29.1.3' },
187 };
188 my $oid_acm1000Battery = '.1.3.6.1.4.1.15416.37.1';
189 my $oid_acmi1000Battery = '.1.3.6.1.4.1.15416.38.1';
190 my $oid_acm1dBattery = '.1.3.6.1.4.1.15416.29.1';
191
192 sub manage_selection {
193 my ($self, %options) = @_;
194
195 $self->{global} = {};
196 $self->{results} = $options{snmp}->get_multiple_table(oids => [ { oid => $oid_acm1000Battery },
197 { oid => $oid_acmi1000Battery },
198 { oid => $oid_acm1dBattery },
199 ],
200 nothing_quit => 1);
201
202 my $result_acm1000 = $options{snmp}->map_instance(mapping => $mapping_acm1000, results => $self->{results}->{$oid_acm1000Battery}, instance => '0');
203 my $result_acmi1000 = $options{snmp}->map_instance(mapping => $mapping_acmi1000, results => $self->{results}->{$oid_acmi1000Battery}, instance => '0');
204 my $result_acm1d = $options{snmp}->map_instance(mapping => $mapping_acm1d, results => $self->{results}->{$oid_acm1dBattery}, instance => '0');
205
206 foreach my $name (keys %{$mapping_acm1000}) {
207 if (defined($result_acm1000->{$name})) {
208 $self->{global}->{$name} = $result_acm1000->{$name};
209 $self->{global}->{$name} = $result_acm1000->{$name} / $mapping_acm1000->{$name}->{divider} if defined($mapping_acm1000->{$name}->{divider});
210 }
211 }
212 foreach my $name (keys %{$mapping_acmi1000}) {
213 if (defined($result_acmi1000->{$name})) {
214 $self->{global}->{$name} = $result_acmi1000->{$name};
215 $self->{global}->{$name} = $result_acmi1000->{$name} / $mapping_acmi1000->{$name}->{divider} if defined($mapping_acmi1000->{$name}->{divider});
216 }
217 }
218 foreach my $name (keys %{$mapping_acm1d}) {
219 $self->{global}->{$name} = $result_acm1d->{$name} unless (!defined($result_acm1d->{$name}));
220 }
221 }
222
223 1;
224
225 __END__
226
227 =head1 MODE
228
229 Check battery charging mode and power statistics.
230
231 =over 8
232
233 =item B<--filter-counters>
234
235 Only display some counters (regexp can be used).
236 Example: --filter-counters='^status|current$'
237
238 =item B<--warning-status>
239
240 Define the conditions to match for the status to be WARNING (default: '%{status} =~ /onBattery/i').
241 You can use the following variables: %{status}
242
243 =item B<--critical-status>
244
245 Define the conditions to match for the status to be CRITICAL (default: '%{status} =~ /disconnected/i || %{status} =~ /shutdown/i').
246 You can use the following variables: %{status}
247
248 =item B<--warning-*>
249
250 Warning threshold.
251 Can be: 'voltage', 'current', 'current1', 'current2', 'temperature',
252 'temperature2', 'temperature2', 'amphourmeter'.
253
254 =item B<--critical-*>
255
256 Critical threshold.
257 Can be: 'voltage', 'current', 'current1', 'current2', 'temperature',
258 'temperature2', 'temperature2', 'amphourmeter'.
259
260 =back
261
262 =cut