Debian Codegraph @

src/hardware/server/dell/openmanage/snmp/mode/components/cachebattery.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::server::dell::openmanage::snmp::mode::components::cachebattery;
22
23 use strict;
24 use warnings;
25
26 my %map_state = (
27 0 => 'unknown',
28 1 => 'ready',
29 2 => 'failed',
30 6 => 'degraded',
31 7 => 'reconditioning',
32 9 => 'high',
33 10 => 'powerLow',
34 12 => 'charging',
35 21 => 'missing',
36 36 => 'learning',
37 );
38 my %map_status = (
39 1 => 'other',
40 2 => 'unknown',
41 3 => 'ok',
42 4 => 'nonCritical',
43 5 => 'critical',
44 6 => 'nonRecoverable',
45 );
46 my %map_learnState = (
47 1 => 'failed',
48 2 => 'active',
49 4 => 'timedOut',
50 8 => 'requested',
51 16 => 'idle',
52 32 => 'due',
53 );
54 my %map_predictedCapacity = (
55 1 => 'failed',
56 2 => 'ready',
57 4 => 'unknown',
58 );
59
60 # In MIB 'dcstorag.mib'
61 my $mapping = {
62 batteryState => { oid => '.1.3.6.1.4.1.674.10893.1.20.130.15.1.4', map => \%map_state },
63 };
64 my $mapping2 = {
65 batteryComponentStatus => { oid => '.1.3.6.1.4.1.674.10893.1.20.130.15.1.6', map => \%map_status },
66 };
67 my $mapping3 = {
68 batteryPredictedCapicity => { oid => '.1.3.6.1.4.1.674.10893.1.20.130.15.1.10', map => \%map_predictedCapacity },
69 };
70 my $mapping4 = {
71 batteryLearnState => { oid => '.1.3.6.1.4.1.674.10893.1.20.130.15.1.12', map => \%map_learnState },
72 };
73
74 sub load {
75 my ($self) = @_;
76
77 push @{$self->{request}}, { oid => $mapping->{batteryState}->{oid} }, { oid => $mapping2->{batteryComponentStatus}->{oid} },
78 { oid => $mapping3->{batteryPredictedCapicity}->{oid} }, { oid => $mapping4->{batteryLearnState}->{oid} };
79 }
80
81 sub check {
82 my ($self) = @_;
83
84 $self->{output}->output_add(long_msg => "Checking cache batteries");
85 $self->{components}->{cachebattery} = {name => 'cache batteries', total => 0, skip => 0};
86 return if ($self->check_filter(section => 'cachebattery'));
87
88 foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$self->{results}->{$mapping2->{batteryComponentStatus}->{oid}}})) {
89 next if ($oid !~ /^$mapping2->{batteryComponentStatus}->{oid}\.(.*)$/);
90 my $instance = $1;
91 my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}->{$mapping->{batteryState}->{oid}}, instance => $instance);
92 my $result2 = $self->{snmp}->map_instance(mapping => $mapping2, results => $self->{results}->{$mapping2->{batteryComponentStatus}->{oid}}, instance => $instance);
93 my $result3 = $self->{snmp}->map_instance(mapping => $mapping3, results => $self->{results}->{$mapping3->{batteryPredictedCapicity}->{oid}}, instance => $instance);
94 my $result4 = $self->{snmp}->map_instance(mapping => $mapping4, results => $self->{results}->{$mapping4->{batteryLearnState}->{oid}}, instance => $instance);
95 $result4->{batteryLearnState} = defined($result4->{batteryLearnState}) ? $result4->{batteryLearnState} : '-';
96 $result3->{batteryPredictedCapicity} = defined($result3->{batteryPredictedCapicity}) ? $result3->{batteryPredictedCapicity} : '-';
97
98 next if ($self->check_filter(section => 'cachebattery', instance => $instance));
99
100 $self->{components}->{cachebattery}->{total}++;
101
102 $self->{output}->output_add(long_msg => sprintf("Cache battery '%s' status is '%s' [instance: %s, state: %s, learn state: %s, predicted capacity: %s]",
103 $instance, $result2->{batteryComponentStatus}, $instance,
104 $result->{batteryState}, $result4->{batteryLearnState}, $result3->{batteryPredictedCapicity}
105 ));
106 my $exit = $self->get_severity(label => 'default', section => 'cachebattery', value => $result2->{batteryComponentStatus});
107 if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) {
108 $self->{output}->output_add(severity => $exit,
109 short_msg => sprintf("Cache battery '%s' status is '%s'",
110 $instance, $result2->{batteryComponentStatus}));
111 }
112 }
113 }
114
115 1;