Debian Codegraph @

src/storage/hp/3par/ssh/mode/components/battery.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 storage::hp::3par::ssh::mode::components::battery;
22
23 use strict;
24 use warnings;
25
26 sub load {
27 my ($self) = @_;
28
29 # Node PS Bat Assem_Serial -State- ChrgLvl(%) -ExpDate- Expired Testing
30 # 0,1 0 0 6CQUBA1HN5065R OK 100 n/a No No
31 # 0,1 1 0 6CQUBA1HN5063G OK 100 n/a No No
32 # 2,3 0 0 6CQUBA1HN484RB OK 100 n/a No No
33 # 2,3 1 0 6CQUBA1HN484R9 OK 100 n/a No No
34 push @{$self->{commands}}, 'echo "===showbattery==="', 'showbattery';
35 }
36
37 sub check {
38 my ($self) = @_;
39
40 $self->{output}->output_add(long_msg => "Checking batteries");
41 $self->{components}->{battery} = { name => 'batteries', total => 0, skip => 0 };
42 return if ($self->check_filter(section => 'battery'));
43
44 return if ($self->{results} !~ /===showbattery===.*?\n(.*?)(===|\Z)/msi);
45 my @results = split /\n/, $1;
46
47 foreach (@results) {
48 next if (!/^\s*\S+\s+(\d+)\s+(\d+)\s+\S+\s+(\S+)\s+(\d+)/);
49 my ($psu_id, $battery_id, $battery_state, $battery_chrg_lvl) = ($1, $2, $3, $4);
50 my $instance = $psu_id . '.' . $battery_id;
51
52 next if ($self->check_filter(section => 'battery', instance => $instance));
53 $self->{components}->{battery}->{total}++;
54
55 $self->{output}->output_add(
56 long_msg => sprintf(
57 "battery '%s' on power supply '%s' status is '%s' [instance: %s, charge level: %d%%]",
58 $psu_id, $battery_id, $battery_state, $instance, $battery_chrg_lvl
59 )
60 );
61 my $exit = $self->get_severity(label => 'default', section => 'battery', value => $battery_state);
62 if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) {
63 $self->{output}->output_add(
64 severity => $exit,
65 short_msg => sprintf(
66 "Battery '%s' on power supply '%s' status is '%s'",
67 $psu_id, $battery_id, $battery_state, $instance
68 )
69 );
70 }
71
72 my ($exit2, $warn, $crit, $checked) = $self->get_severity_numeric(section => 'battery.charge', instance => $instance, value => $battery_chrg_lvl);
73
74 if (!$self->{output}->is_status(value => $exit2, compare => 'ok', litteral => 1)) {
75 $self->{output}->output_add(
76 severity => $exit2,
77 short_msg => sprintf("Battery '%s' on power supply '%s' charge level is %s %%", $psu_id, $battery_id, $battery_chrg_lvl)
78 );
79 }
80
81 $self->{output}->perfdata_add(
82 nlabel => 'hardware.battery.charge.percentage',
83 unit => '%',
84 instances => ['psu' . $psu_id, 'battery' . $battery_id],
85 value => $battery_chrg_lvl,
86 warning => $warn,
87 critical => $crit,
88 min => 0, max => 100
89 );
90 }
91 }
92
93 1;