Debian Codegraph @

src/storage/qnap/snmp/mode/components/raid.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::qnap::snmp::mode::components::raid;
22
23 use strict;
24 use warnings;
25
26 sub load {}
27
28 sub check_raid_qts {
29 my ($self) = @_;
30
31 my $mapping = {
32 name => { oid => '.1.3.6.1.4.1.55062.1.10.5.1.3' }, # raidName
33 status => { oid => '.1.3.6.1.4.1.55062.1.10.5.1.4' } # raidStatus
34 };
35 my $snmp_result = $self->{snmp}->get_table(
36 oid => '.1.3.6.1.4.1.55062.1.10.5', # raidTable
37 start => $mapping->{name}->{oid},
38 end => $mapping->{status}->{oid}
39 );
40 foreach my $oid ($self->{snmp}->oid_lex_sort(keys %$snmp_result)) {
41 next if ($oid !~ /^$mapping->{status}->{oid}\.(\d+)$/);
42 my $instance = $1;
43 my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $snmp_result, instance => $instance);
44
45 next if ($self->check_filter(section => 'raid', instance => $instance));
46
47 $self->{components}->{raid}->{total}++;
48 $self->{output}->output_add(
49 long_msg => sprintf(
50 "raid '%s' status is %s [instance: %s]",
51 $result->{name}, $result->{status}, $instance
52 )
53 );
54 my $exit = $self->get_severity(section => 'raid', value => $result->{status});
55 if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) {
56 $self->{output}->output_add(
57 severity => $exit,
58 short_msg => sprintf(
59 "Raid '%s' status is %s.", $result->{name}, $result->{status}
60 )
61 );
62 }
63 }
64 }
65
66 sub check_raid_ex {
67 my ($self) = @_;
68
69 my $snmp_result = $self->{snmp}->get_table(
70 oid => '.1.3.6.1.4.1.24681.1.4.1.1.1.2.1.2.1.5' # raidStatus
71 );
72 foreach my $oid ($self->{snmp}->oid_lex_sort(keys %$snmp_result)) {
73 $oid =~ /\.(\d+)$/;
74 my $instance = $1;
75
76 next if ($self->check_filter(section => 'raid', instance => $instance));
77
78 my $status = $snmp_result->{$oid};
79 $self->{components}->{raid}->{total}++;
80 $self->{output}->output_add(
81 long_msg => sprintf(
82 "raid '%s' status is %s [instance: %s]",
83 $instance, $status, $instance
84 )
85 );
86 my $exit = $self->get_severity(section => 'raid', value => $status);
87 if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) {
88 $self->{output}->output_add(
89 severity => $exit,
90 short_msg => sprintf(
91 "Raid '%s' status is %s.", $instance, $status
92 )
93 );
94 }
95 }
96 }
97
98 sub check {
99 my ($self) = @_;
100
101 $self->{output}->output_add(long_msg => "Checking raids");
102 $self->{components}->{raid} = {name => 'raids', total => 0, skip => 0};
103 return if ($self->check_filter(section => 'raid'));
104
105 if ($self->{is_qts} == 1) {
106 check_raid_qts($self);
107 } elsif ($self->{is_es} == 0) {
108 check_raid_ex($self);
109 }
110 }
111
112 1;