Debian Codegraph @

src/storage/huawei/oceanstor/snmp/mode/components/disk.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::disk;
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.1.1.1' }, # hwInfoDiskID
29 health_status => { oid => '.1.3.6.1.4.1.34774.4.1.23.5.1.1.2', map => $health_status }, # hwInfoDiskHealthStatus
30 running_status => { oid => '.1.3.6.1.4.1.34774.4.1.23.5.1.1.3', map => $running_status }, # hwInfoDiskRunningStatus
31 location => { oid => '.1.3.6.1.4.1.34774.4.1.23.5.1.1.4' }, # hwInfoDiskLocation
32 temperature => { oid => '.1.3.6.1.4.1.34774.4.1.23.5.1.1.11' } # hwInfoDiskTemperature
33 };
34 my $oid_disk_entry = '.1.3.6.1.4.1.34774.4.1.23.5.1.1';
35
36 sub load {
37 my ($self) = @_;
38
39 push @{$self->{request}}, {
40 oid => $oid_disk_entry,
41 end => $mapping->{temperature}->{oid}
42 };
43 }
44
45 sub check {
46 my ($self) = @_;
47
48 $self->{output}->output_add(long_msg => 'checking disks');
49 $self->{components}->{disk} = { name => 'disks', total => 0, skip => 0 };
50 return if ($self->check_filter(section => 'disk'));
51
52 my ($exit, $warn, $crit, $checked);
53 foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$self->{results}->{$oid_disk_entry}})) {
54 next if ($oid !~ /^$mapping->{id}->{oid}\.(.*)$/);
55 my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}->{$oid_disk_entry}, instance => $1);
56 my $instance = $result->{id};
57 my $name = $result->{location} . ':' . $result->{id};
58
59 next if ($self->check_filter(section => 'disk', instance => $instance, name => $name));
60
61 $self->{components}->{disk}->{total}++;
62 $self->{output}->output_add(
63 long_msg => sprintf(
64 "disk '%s' status is '%s' [instance: %s, location: %s, running status: %s, temperature: %s]",
65 $instance,
66 $result->{health_status},
67 $instance,
68 $result->{location},
69 $result->{running_status},
70 $result->{temperature}
71 )
72 );
73 $exit = $self->get_severity(label => 'default', section => 'disk', 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 "Disk '%s' status is '%s'",
79 $instance,
80 $result->{health_status}
81 )
82 );
83 }
84
85 ($exit, $warn, $crit, $checked) = $self->get_severity_numeric(section => 'disk.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("Disk temperature '%s' is '%s' C", $instance, $result->{temperature})
90 );
91 }
92 $self->{output}->perfdata_add(
93 nlabel => 'hardware.disk.temperature.celsius',
94 unit => 'C',
95 instances => $instance,
96 value => $result->{temperature},
97 warning => $warn,
98 critical => $crit
99 );
100 }
101 }
102
103 1;