Debian Codegraph @

src/hardware/server/cisco/ucs/snmp/mode/components/memory.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::cisco::ucs::snmp::mode::components::memory;
22
23 use strict;
24 use warnings;
25 use hardware::server::cisco::ucs::snmp::mode::components::resources qw(%mapping_presence %mapping_operability);
26
27 # In MIB 'CISCO-UNIFIED-COMPUTING-MEMORY-MIB'
28 my $mapping1 = {
29 cucsMemoryUnitPresence => { oid => '.1.3.6.1.4.1.9.9.719.1.30.11.1.17', map => \%mapping_presence },
30 };
31 my $mapping2 = {
32 cucsMemoryUnitOperState => { oid => '.1.3.6.1.4.1.9.9.719.1.30.11.1.13', map => \%mapping_operability },
33 };
34 my $oid_cucsMemoryUnitDn = '.1.3.6.1.4.1.9.9.719.1.30.11.1.2';
35
36 sub load {
37 my ($self) = @_;
38
39 push @{$self->{request}}, { oid => $mapping1->{cucsMemoryUnitPresence}->{oid} },
40 { oid => $mapping2->{cucsMemoryUnitOperState}->{oid} }, { oid => $oid_cucsMemoryUnitDn };
41 }
42
43 sub check {
44 my ($self) = @_;
45
46 $self->{output}->output_add(long_msg => "Checking memories");
47 $self->{components}->{memory} = {name => 'memories', total => 0, skip => 0};
48 return if ($self->check_filter(section => 'memory'));
49
50 foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$self->{results}->{$oid_cucsMemoryUnitDn}})) {
51 $oid =~ /\.(\d+)$/;
52 my $instance = $1;
53 my $memory_dn = $self->{results}->{$oid_cucsMemoryUnitDn}->{$oid};
54 $memory_dn =~ s/\n$//ms;
55 my $result = $self->{snmp}->map_instance(mapping => $mapping1, results => $self->{results}->{$mapping1->{cucsMemoryUnitPresence}->{oid}}, instance => $instance);
56 my $result2 = $self->{snmp}->map_instance(mapping => $mapping2, results => $self->{results}->{$mapping2->{cucsMemoryUnitOperState}->{oid}}, instance => $instance);
57
58 next if ($self->absent_problem(section => 'memory', instance => $memory_dn));
59 next if ($self->check_filter(section => 'memory', instance => $memory_dn));
60
61 $self->{output}->output_add(
62 long_msg => sprintf(
63 "memory '%s' state is '%s' [presence: %s].",
64 $memory_dn, $result2->{cucsMemoryUnitOperState},
65 $result->{cucsMemoryUnitPresence}
66 )
67 );
68
69 my $exit = $self->get_severity(section => 'memory.presence', label => 'default.presence', value => $result->{cucsMemoryUnitPresence});
70 if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) {
71 $self->{output}->output_add(
72 severity => $exit,
73 short_msg => sprintf(
74 "memory '%s' presence is: '%s'",
75 $memory_dn, $result->{cucsMemoryUnitPresence}
76 )
77 );
78 next;
79 }
80
81 if($result->{cucsMemoryUnitPresence} eq "equipped") {
82 $self->{components}->{memory}->{total}++;
83 }
84
85 $exit = $self->get_severity(section => 'memory.operability', label => 'default.operability', value => $result2->{cucsMemoryUnitOperState});
86 if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) {
87 $self->{output}->output_add(
88 severity => $exit,
89 short_msg => sprintf(
90 "memory '%s' state is '%s'",
91 $memory_dn, $result2->{cucsMemoryUnitOperState}
92 )
93 );
94 }
95 }
96 }
97
98 1;