Debian Codegraph @

src/storage/ibm/fs900/snmp/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::ibm::fs900::snmp::mode::components::battery;
22
23 use strict;
24 use warnings;
25
26 # In MIB 'IBM-FLASHSYSTEM.MIB'
27 my $mapping = {
28 batteryObject => { oid => '.1.3.6.1.4.1.2.6.255.1.1.4.10.1.2' },
29 batteryCell1 => { oid => '.1.3.6.1.4.1.2.6.255.1.1.4.10.1.4' }, #mV
30 batteryCell2 => { oid => '.1.3.6.1.4.1.2.6.255.1.1.4.10.1.5' }, #mV
31 batteryCell3 => { oid => '.1.3.6.1.4.1.2.6.255.1.1.4.10.1.6' }, #mV
32 batteryTotal => { oid => '.1.3.6.1.4.1.2.6.255.1.1.4.10.1.7' }, #mV
33 batteryChgCurr => { oid => '.1.3.6.1.4.1.2.6.255.1.1.4.10.1.8' },
34 batteryRmngCap => { oid => '.1.3.6.1.4.1.2.6.255.1.1.4.10.1.9' },
35 batteryFullCap => { oid => '.1.3.6.1.4.1.2.6.255.1.1.4.10.1.10' },
36 };
37 my $oid_batteryTableEntry = '.1.3.6.1.4.1.2.6.255.1.1.4.10.1';
38
39 sub load {
40 my ($self) = @_;
41
42 push @{$self->{request}}, { oid => $oid_batteryTableEntry };
43 }
44
45 sub check {
46 my ($self) = @_;
47
48 $self->{output}->output_add(long_msg => "Checking batteries");
49 $self->{components}->{battery} = {name => 'batteries', total => 0, skip => 0};
50 return if ($self->check_filter(section => 'battery'));
51
52 foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$self->{results}->{$oid_batteryTableEntry}})) {
53 next if ($oid !~ /^$mapping->{batteryObject}->{oid}\.(.*)$/);
54 my $instance = $1;
55 my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}->{$oid_batteryTableEntry}, instance => $instance);
56
57 next if ($self->check_filter(section => 'battery', instance => $instance));
58
59 $self->{components}->{battery}->{total}++;
60 $self->{output}->output_add(long_msg => sprintf("Battery '%s' [instance = %s, cell1 = %s mV, cell2 = %s mV, cell3 = %s mV, total = %s mV, current = %s, capacity remaining = %s, capacity full = %s]",
61 $result->{batteryObject}, $instance, $result->{batteryCell1}, $result->{batteryCell2}, $result->{batteryCell3},
62 $result->{batteryTotal}, $result->{batteryChgCurr}, $result->{batteryRmngCap}, $result->{batteryFullCap}));
63
64 foreach my $cell ('batteryCell1', 'batteryCell2', 'batteryCell3', 'batteryTotal') {
65 if (defined($result->{$cell}) && $result->{$cell} =~ /[0-9]/) {
66 my $pretty_cell = $cell;
67 $pretty_cell =~ s/battery//;
68 my ($exit, $warn, $crit) = $self->get_severity_numeric(section => 'battery.cell', instance => $instance, value => $result->{$cell});
69 if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) {
70 $self->{output}->output_add(severity => $exit,
71 short_msg => sprintf("Battery '%s' cell '%s' voltage is %s mV", $instance, lc($pretty_cell), $result->{$cell}));
72 }
73 $self->{output}->perfdata_add(
74 label => 'battery_voltage', unit => 'mV',
75 nlabel => 'hardware.battery.voltage.millivolt',
76 instances => [$instance, lc($pretty_cell)],
77 value => $result->{$cell},
78 warning => $warn,
79 critical => $crit,
80 min => 0,
81 );
82 }
83 }
84
85 if (defined($result->{batteryChgCurr}) && $result->{batteryChgCurr} =~ /[0-9]/) {
86 my ($exit, $warn, $crit) = $self->get_severity_numeric(section => 'battery.current', instance => $instance, value => $result->{batteryChgCurr});
87 if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) {
88 $self->{output}->output_add(severity => $exit,
89 short_msg => sprintf("Battery '%s' current is %s", $instance, $result->{batteryChgCurr}));
90 }
91 $self->{output}->perfdata_add(
92 label => 'battery_current',
93 nlabel => 'hardware.battery.current.count',
94 instances => $instance,
95 value => $result->{batteryChgCurr},
96 warning => $warn,
97 critical => $crit,
98 min => 0,
99 );
100 }
101
102 if (defined($result->{batteryRmngCap}) && $result->{batteryRmngCap} =~ /[0-9]/ && defined($result->{batteryFullCap}) && $result->{batteryFullCap} =~ /[0-9]/) {
103 my ($exit, $warn, $crit) = $self->get_severity_numeric(section => 'battery.capacity', instance => $instance, value => $result->{batteryRmngCap});
104 if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) {
105 $self->{output}->output_add(severity => $exit,
106 short_msg => sprintf("Battery '%s' capacity is %s on %s", $instance, $result->{batteryRmngCap}, $result->{batteryFullCap}));
107 }
108 $self->{output}->perfdata_add(
109 label => 'battery_capacity',
110 nlabel => 'hardware.battery.capacity.count',
111 instances => $instance,
112 value => $result->{batteryRmngCap},
113 warning => $warn,
114 critical => $crit,
115 min => 0, max => $result->{batteryFullCap},
116 );
117 }
118 }
119 }
120
121 1;