Debian Codegraph @

src/hardware/server/fujitsu/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::fujitsu::snmp::mode::components::memory;
22
23 use strict;
24 use warnings;
25
26 my $map_sc_memory_status = {
27 1 => 'unknown', 2 => 'error', 3 => 'ok', 4 => 'not-available', 5 => 'fail',
28 6 => 'prefailure-warning', 7 => 'hot-spare', 8 => 'mirror',
29 9 => 'disabled', 10 => 'raid'
30 };
31 my $map_sc2_memory_status = {
32 1 => 'unknown', 2 => 'not-present', 3 => 'ok', 4 => 'disabled', 5 => 'error', 6 => 'failed',
33 7 => 'prefailure-predicted', 8 => 'hot-spare', 9 => 'mirror', 10 => 'raid', 11 => 'hidden'
34 };
35
36 my $mapping = {
37 sc => {
38 memModuleStatus => { oid => '.1.3.6.1.4.1.231.2.10.2.2.5.4.10.1.3', map => $map_sc_memory_status }
39 },
40 sc2 => {
41 sc2memModuleDesignation => { oid => '.1.3.6.1.4.1.231.2.10.2.2.10.6.5.1.3' },
42 sc2memModuleStatus => { oid => '.1.3.6.1.4.1.231.2.10.2.2.10.6.5.1.4', map => $map_sc2_memory_status }
43 }
44 };
45 my $oid_sc2MemoryModules = '.1.3.6.1.4.1.231.2.10.2.2.10.6.5.1';
46
47 sub load {
48 my ($self) = @_;
49
50 push @{$self->{request}}, { oid => $oid_sc2MemoryModules, end => $mapping->{sc2}->{sc2memModuleStatus} }, { oid => $mapping->{sc}->{memModuleStatus}->{oid} };
51 }
52
53 sub check_memory {
54 my ($self, %options) = @_;
55
56 my ($exit, $warn, $crit, $checked);
57 foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$self->{results}->{$options{entry}}})) {
58 next if ($oid !~ /^$options{mapping}->{$options{status}}->{oid}\.(.*)$/);
59 my $instance = $1;
60 my $result = $self->{snmp}->map_instance(mapping => $options{mapping}, results => $self->{results}->{$options{entry}}, instance => $instance);
61 $result->{instance} = $instance;
62
63 next if ($self->check_filter(section => 'memory', instance => $instance));
64 next if ($result->{$options{status}} =~ /not-present|not-available/i &&
65 $self->absent_problem(section => 'memory', instance => $instance));
66 $self->{components}->{memory}->{total}++;
67
68 $self->{output}->output_add(
69 long_msg => sprintf(
70 "memory '%s' status is '%s' [instance: %s]",
71 $result->{$options{name}}, $result->{$options{status}}, $instance
72 )
73 );
74
75 $exit = $self->get_severity(section => 'memory', value => $result->{$options{status}});
76 if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) {
77 $self->{output}->output_add(
78 severity => $exit,
79 short_msg => sprintf("Memory '%s' status is '%s'", $result->{$options{name}}, $result->{$options{status}})
80 );
81 }
82 }
83 }
84
85 sub check {
86 my ($self) = @_;
87
88 $self->{output}->output_add(long_msg => 'Checking memories');
89 $self->{components}->{memory} = { name => 'memories', total => 0, skip => 0 };
90 return if ($self->check_filter(section => 'memory'));
91
92 if (defined($self->{results}->{$oid_sc2MemoryModules}) && scalar(keys %{$self->{results}->{$oid_sc2MemoryModules}}) > 0) {
93 check_memory(
94 $self, entry => $oid_sc2MemoryModules, mapping => $mapping->{sc2}, name => 'sc2memModuleDesignation',
95 status => 'sc2memModuleStatus'
96 );
97 } else {
98 check_memory(
99 $self, entry => $mapping->{sc}->{memModuleStatus}, mapping => $mapping->{sc}, name => 'instance',
100 status => 'memModuleStatus'
101 );
102 }
103 }
104
105 1;