Debian Codegraph @

src/storage/huawei/oceanstor/snmp/mode/components/enclosure.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::huawei::oceanstor::snmp::mode::components::enclosure;
22
23 use strict;
24 use warnings;
25 use storage::huawei::oceanstor::snmp::mode::resources qw($health_status $running_status);
26
27 my $mapping = {
28 id => { oid => '.1.3.6.1.4.1.34774.4.1.23.5.6.1.1' }, # hwInfoEnclosureID
29 name => { oid => '.1.3.6.1.4.1.34774.4.1.23.5.6.1.2' }, # hwInfoEnclosureName
30 health_status => { oid => '.1.3.6.1.4.1.34774.4.1.23.5.6.1.4', map => $health_status }, # hwInfoEnclosureHealthStatus
31 running_status => { oid => '.1.3.6.1.4.1.34774.4.1.23.5.6.1.5', map => $running_status }, # hwInfoEnclosureRunningStatus
32 temperature => { oid => '.1.3.6.1.4.1.34774.4.1.23.5.6.1.8' } # hwInfoEnclosureTemperature
33 };
34 my $oid_enclosure_entry = '.1.3.6.1.4.1.34774.4.1.23.5.6.1'; # hwInfoEnclosureEntry
35
36 sub load {
37 my ($self) = @_;
38
39 push @{$self->{request}}, {
40 oid => $oid_enclosure_entry,
41 end => $mapping->{temperature}->{oid}
42 };
43 }
44
45 sub check {
46 my ($self) = @_;
47
48 $self->{output}->output_add(long_msg => 'checking enclosures');
49 $self->{components}->{enclosure} = { name => 'enclosures', total => 0, skip => 0 };
50 return if ($self->check_filter(section => 'enclosure'));
51
52 my ($exit, $warn, $crit, $checked);
53 foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$self->{results}->{$oid_enclosure_entry}})) {
54 next if ($oid !~ /^$mapping->{id}->{oid}\.(.*)$/);
55 my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}->{$oid_enclosure_entry}, instance => $1);
56 my $instance = $result->{id};
57 my $name = $result->{name};
58
59 next if ($self->check_filter(section => 'enclosure', instance => $instance, name => $name));
60
61 $self->{components}->{enclosure}->{total}++;
62 $self->{output}->output_add(
63 long_msg => sprintf(
64 "enclosure '%s' status is '%s' [instance: %s, name: %s, running status: %s, temperature: %s]",
65 $instance,
66 $result->{health_status},
67 $instance,
68 $result->{name},
69 $result->{running_status},
70 $result->{temperature}
71 )
72 );
73 $exit = $self->get_severity(label => 'default', section => 'enclosure', name => $name, value => $result->{health_status});
74 if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) {
75 $self->{output}->output_add(
76 severity => $exit,
77 short_msg => sprintf(
78 "Enclosure '%s' status is '%s'",
79 $instance,
80 $result->{health_status}
81 )
82 );
83 }
84
85 ($exit, $warn, $crit, $checked) = $self->get_severity_numeric(section => 'enclosure.temperature', instance => $instance, name => $name, value => $result->{temperature});
86 if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) {
87 $self->{output}->output_add(
88 severity => $exit,
89 short_msg => sprintf("Enclosure temperature '%s' is '%s' C", $instance, $result->{temperature})
90 );
91 }
92 $self->{output}->perfdata_add(
93 nlabel => 'hardware.enclosure.temperature.celsius',
94 unit => 'C',
95 instances => $instance,
96 value => $result->{temperature},
97 warning => $warn,
98 critical => $crit
99 );
100 }
101 }
102
103 1;