Debian Codegraph @

src/storage/qsan/nas/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::qsan::nas::snmp::mode::components::disk;
22
23 use strict;
24 use warnings;
25
26 my $mapping = {
27 pd_location => { oid => '.1.3.6.1.4.1.22274.2.2.1.1.1' },
28 pd_status_health => { oid => '.1.3.6.1.4.1.22274.2.2.1.1.3' },
29 hdd_temperature => { oid => '.1.3.6.1.4.1.22274.2.3.4.1.4' },
30 };
31
32 sub load {
33 my ($self) = @_;
34
35 push @{$self->{request}}, { oid => $mapping->{pd_location}->{oid} },
36 { oid => $mapping->{pd_status_health}->{oid} }, { oid => $mapping->{hdd_temperature}->{oid} };
37 }
38
39 sub check {
40 my ($self) = @_;
41
42 $self->{output}->output_add(long_msg => "Checking disks");
43 $self->{components}->{disk} = {name => 'disks', total => 0, skip => 0};
44 return if ($self->check_filter(section => 'disk'));
45
46 my $results = { %{$self->{results}->{$mapping->{pd_location}->{oid}}}, %{$self->{results}->{$mapping->{pd_status_health}->{oid}}},
47 %{$self->{results}->{$mapping->{hdd_temperature}->{oid}}}};
48 my ($exit, $warn, $crit, $checked);
49 foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$self->{results}->{$mapping->{pd_status_health}->{oid}}})) {
50 $oid =~ /^$mapping->{pd_status_health}->{oid}\.(.*)$/;
51 my $instance = $1;
52 my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $results, instance => $instance);
53
54 next if ($self->check_filter(section => 'disk', instance => $instance));
55
56 $self->{components}->{disk}->{total}++;
57 $self->{output}->output_add(long_msg => sprintf("disk '%s' status is '%s' [instance = %s, temperature = %s]",
58 $result->{pd_location}, $result->{pd_status_health}, $instance, $result->{hdd_temperature}));
59 $exit = $self->get_severity(section => 'disk', value => $result->{pd_status_health});
60 if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) {
61 $self->{output}->output_add(severity => $exit,
62 short_msg => sprintf("Disk '%s' status is '%s'", $result->{pd_location}, $result->{pd_status_health}));
63 }
64
65 next if (!defined($result->{hdd_temperature}) || $result->{hdd_temperature} !~ /[0-9]/);
66
67 ($exit, $warn, $crit, $checked) = $self->get_severity_numeric(section => 'disk.temperature', instance => $instance, value => $result->{hdd_temperature});
68 if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) {
69 $self->{output}->output_add(severity => $exit,
70 short_msg => sprintf("Disk '%s' is '%s' C", $result->{pd_location}, $result->{hdd_temperature}));
71 }
72 $self->{output}->perfdata_add(
73 label => 'disk_temperature', unit => 'C',
74 nlabel => 'hardware.disk.temperature.celsius',
75 instances => $result->{pd_location},
76 value => $result->{hdd_temperature},
77 warning => $warn,
78 critical => $crit
79 );
80 }
81 }
82
83 1;