Debian Codegraph @

src/storage/synology/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::synology::snmp::mode::components::disk;
22
23 use strict;
24 use warnings;
25
26 my $map_disk_status = {
27 1 => 'Normal',
28 2 => 'Initialized',
29 3 => 'NotInitialized',
30 4 => 'SystemPartitionFailed',
31 5 => 'Crashed'
32 };
33 my $map_disk_health = {
34 1 => 'normal',
35 2 => 'warning',
36 3 => 'critical',
37 4 => 'failing'
38 };
39
40 my $mapping = {
41 status => { oid => '.1.3.6.1.4.1.6574.2.1.1.5', map => $map_disk_status }, # synoDiskdiskStatus
42 badSectors => { oid => '.1.3.6.1.4.1.6574.2.1.1.9' }, # diskBadSector
43 healthStatus => { oid => '.1.3.6.1.4.1.6574.2.1.1.13', map => $map_disk_health } # diskHealthStatus
44 };
45 my $oid_diskName = '.1.3.6.1.4.1.6574.2.1.1.2'; # synoDiskdiskName
46
47 sub load {
48 my ($self) = @_;
49
50 push @{$self->{request}}, { oid => $oid_diskName };
51 }
52
53 sub check {
54 my ($self) = @_;
55
56 $self->{output}->output_add(long_msg => "Checking disk");
57 $self->{components}->{disk} = { name => 'disk', total => 0, skip => 0 };
58 return if ($self->check_filter(section => 'disk'));
59
60 my $instances = [];
61 foreach (keys %{$self->{results}->{$oid_diskName}}) {
62 push @$instances, $1 if (/^$oid_diskName\.(.*)$/);
63 }
64
65 return if (scalar(@$instances) <= 0);
66
67 $self->{snmp}->load(
68 oids => [map($_->{oid}, values(%$mapping))],
69 instances => $instances
70 );
71 my $results = $self->{snmp}->get_leef();
72
73 foreach my $oid ($self->{snmp}->oid_lex_sort(keys %$results)) {
74 next if ($oid !~ /^$mapping->{status}->{oid}\.(\d+)/);
75 my $instance = $1;
76 my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $results, instance => $instance);
77
78 my $name = $self->{results}->{$oid_diskName}->{$oid_diskName . '.' . $instance};
79 next if ($self->check_filter(section => 'disk', instance => $instance));
80 $self->{components}->{disk}->{total}++;
81
82 $self->{output}->output_add(
83 long_msg => sprintf(
84 "disk '%s' status is %s [instance: %s%s%s]",
85 $name, $result->{status}, $instance,
86 defined($result->{badSectors}) ? ', bad sectors: ' . $result->{badSectors} : '',
87 defined($result->{healthStatus}) ? ', health: ' . $result->{healthStatus} : ''
88 )
89 );
90 my $exit = $self->get_severity(section => 'disk', value => $result->{status});
91 if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) {
92 $self->{output}->output_add(
93 severity => $exit,
94 short_msg => sprintf("Disk '%s' status is %s", $name, $result->{status})
95 );
96 }
97
98 if (defined($result->{healthStatus})) {
99 $exit = $self->get_severity(section => 'disk', value => $result->{healthStatus});
100 if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) {
101 $self->{output}->output_add(
102 severity => $exit,
103 short_msg => sprintf("Disk '%s' health is %s", $name, $result->{healthStatus})
104 );
105 }
106 }
107
108 next if (!defined($result->{badSectors}));
109
110 my ($exit2, $warn, $crit, $checked) = $self->get_severity_numeric(section => 'disk.badsectors', instance => $instance, value => $result->{badSectors});
111 if (!$self->{output}->is_status(value => $exit2, compare => 'ok', litteral => 1)) {
112 $self->{output}->output_add(
113 severity => $exit2,
114 short_msg => sprintf("Disk '%s' has %s bad sector(s)", $name, $result->{badSectors})
115 );
116 }
117
118 $self->{output}->perfdata_add(
119 nlabel => 'hardware.disk.bad_sectors.count',
120 instances => $name,
121 value => $result->{badSectors},
122 warning => $warn,
123 critical => $crit,
124 min => 0
125 );
126 }
127 }
128
129 1;