Debian Codegraph @

src/os/solaris/local/mode/hwraidctl.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 os::solaris::local::mode::hwraidctl;
22
23 use base qw(centreon::plugins::mode);
24
25 use strict;
26 use warnings;
27
28 sub new {
29 my ($class, %options) = @_;
30 my $self = $class->SUPER::new(package => __PACKAGE__, %options);
31 bless $self, $class;
32
33 $options{options}->add_options(arguments => {
34 'warning:s' => { name => 'warning' },
35 'critical:s' => { name => 'critical' }
36 });
37
38 return $self;
39 }
40
41 sub check_options {
42 my ($self, %options) = @_;
43 $self->SUPER::init(%options);
44
45 if (($self->{perfdata}->threshold_validate(label => 'warning', value => $self->{option_results}->{warning})) == 0) {
46 $self->{output}->add_option_msg(short_msg => "Wrong warning threshold '" . $self->{option_results}->{warning} . "'.");
47 $self->{output}->option_exit();
48 }
49 if (($self->{perfdata}->threshold_validate(label => 'critical', value => $self->{option_results}->{critical})) == 0) {
50 $self->{output}->add_option_msg(short_msg => "Wrong critical threshold '" . $self->{option_results}->{critical} . "'.");
51 $self->{output}->option_exit();
52 }
53 }
54
55 sub run {
56 my ($self, %options) = @_;
57
58 my ($stdout) = $options{custom}->execute_command(
59 command => 'raidctl',
60 command_options => '-S 2>&1',
61 command_path => '/usr/sbin'
62 );
63
64 my $long_msg = $stdout;
65 $long_msg =~ s/\|/~/mg;
66 $self->{output}->output_add(long_msg => $long_msg);
67
68 my $volumes_errors = 0;
69 my $disks_errors = 0;
70 my $volumes = '';
71 my $disks = '';
72 foreach (split(/\n/, $stdout)) {
73 #1 "LSI_1030"
74 #c1t2d0 2 0.2.0 0.3.0 1 OPTIMAL
75 #0.0.0 GOOD
76 #0.1.0 GOOD
77 #0.2.0 GOOD
78 #0.3.0 GOOD
79 #4 "LSI_1030"
80
81 # For Disk
82 if (/^\s*(\S+)\s+(FAILED)$/i ) {
83 my $disk = $1;
84
85 $disks_errors++;
86 $disks .= ' [' . $disk . '/FAILED' . ']';
87 } elsif (/^\s*(\S+).*?(DEGRADED|FAILED)$/i) {
88 $volumes_errors++;
89 $volumes .= ' [' . $1 . '/' . $2 . ']';
90 }
91 }
92
93 my ($exit_code) = $self->{perfdata}->threshold_check(
94 value => $volumes_errors,
95 threshold => [ { label => 'critical', 'exit_litteral' => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]
96 );
97 if ($volumes_errors > 0) {
98 $self->{output}->output_add(
99 severity => $exit_code,
100 short_msg => sprintf("Some volumes problems:" . $volumes)
101 );
102 } else {
103 $self->{output}->output_add(
104 severity => 'OK',
105 short_msg => "No problems on volumes"
106 );
107 }
108
109 ($exit_code) = $self->{perfdata}->threshold_check(
110 value => $disks_errors,
111 threshold => [ { label => 'critical', 'exit_litteral' => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]
112 );
113 if ($disks_errors > 0) {
114 $self->{output}->output_add(
115 severity => $exit_code,
116 short_msg => sprintf("Some disks problems:" . $disks)
117 );
118 } else {
119 $self->{output}->output_add(
120 severity => 'OK',
121 short_msg => "No problems on disks"
122 );
123 }
124
125 $self->{output}->display();
126 $self->{output}->exit();
127 }
128
129 1;
130
131 __END__
132
133 =head1 MODE
134
135 Check hardware raid status
136
137 Command used: '/usr/sbin/raidctl -S 2>&1'
138
139 =over 8
140
141 =item B<--warning>
142
143 Warning threshold.
144
145 =item B<--critical>
146
147 Critical threshold.
148
149 =back
150
151 =cut