Debian Codegraph @

src/hardware/server/xfusion/ibmc/snmp/mode/components/component.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::xfusion::ibmc::snmp::mode::components::component;
22
23 use strict;
24 use warnings;
25
26 my %map_status = (
27 1 => 'ok',
28 2 => 'minor',
29 3 => 'major',
30 4 => 'critical',
31 5 => 'absence',
32 6 => 'unknown'
33 );
34
35 my %map_type = (
36 1 => 'baseBoard',
37 2 => 'mezzCard',
38 3 => 'amcController',
39 4 => 'mmcController',
40 5 => 'hddBackPlane',
41 6 => 'raidCard'
42 );
43
44 my $mapping = {
45 componentName => { oid => '.1.3.6.1.4.1.58132.2.235.1.1.10.50.1.1' },
46 componentType => { oid => '.1.3.6.1.4.1.58132.2.235.1.1.10.50.1.2', map => \%map_type },
47 componentStatus => { oid => '.1.3.6.1.4.1.58132.2.235.1.1.10.50.1.5', map => \%map_status }
48 };
49 my $oid_componentDescriptionEntry = '.1.3.6.1.4.1.58132.2.235.1.1.10.50.1';
50
51 sub load {
52 my ($self) = @_;
53
54 push @{$self->{request}}, { oid => $oid_componentDescriptionEntry };
55 }
56
57 sub check {
58 my ($self) = @_;
59
60 $self->{output}->output_add(long_msg => "Checking component");
61 $self->{components}->{component} = {name => 'components', total => 0, skip => 0};
62 return if ($self->check_filter(section => 'component'));
63
64 foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$self->{results}->{$oid_componentDescriptionEntry}})) {
65 next if ($oid !~ /^$mapping->{componentStatus}->{oid}\.(.*)$/);
66 my $instance = $1;
67 my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}->{$oid_componentDescriptionEntry}, instance => $instance);
68
69 next if ($self->check_filter(section => 'component', instance => $instance));
70 next if ($result->{componentStatus} =~ /absence/);
71 $self->{components}->{component}->{total}++;
72
73 $self->{output}->output_add(
74 long_msg => sprintf(
75 "component '%s' of type '%s' status is '%s' [instance: %s]",
76 $result->{componentName}, $result->{componentType}, $result->{componentStatus}, $instance,
77 )
78 );
79
80 my $exit = $self->get_severity(label => 'default', section => 'component', value => $result->{componentStatus});
81 if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) {
82 $self->{output}->output_add(
83 severity => $exit,
84 short_msg => sprintf(
85 "Component '%s' of type '%s' status is '%s'",
86 $result->{componentName}, $result->{componentType}, $result->{componentStatus}
87 )
88 );
89 }
90 }
91 }
92
93 1;