Debian Codegraph @

src/os/solaris/local/mode/svmdisks.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::svmdisks;
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 => 'metastat',
60 command_options => '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 ($stdout2) = $options{custom}->execute_command(
69 command => 'metadb',
70 command_options => '2>&1',
71 command_path => '/usr/sbin'
72 );
73
74 $long_msg = $stdout2;
75 $long_msg =~ s/\|/~/mg;
76 $self->{output}->output_add(long_msg => $long_msg);
77
78 my $num_metastat_errors = 0;
79 my $metastat_name = '';
80 foreach my $disk_info (split(/(?=d\d+:)/, $stdout)) {
81 #d5: Mirror
82 # Submirror 0: d15
83 # State: Okay
84 # Submirror 1: d25
85 # State: Okay
86 # Pass: 1
87 # Read option: roundrobin (default)
88 # Write option: parallel (default)
89 # Size: 525798 blocks
90 #
91 #d15: Submirror of d5
92 # State: Okay
93 # Size: 525798 blocks
94 # Stripe 0:
95 # Device Start Block Dbase State Reloc Hot Spare
96 # c0t0d0s5 0 No Okay Yes
97 #
98 #
99 #d25: Submirror of d5
100 # State: Okay
101 # Size: 525798 blocks
102 # Stripe 0:
103 # Device Start Block Dbase State Reloc Hot Spare
104 # c0t1d0s5 0 No Okay Yes
105
106 my @lines = split("\n",$disk_info);
107 my @line1 = split(/:/, $lines[0]);
108 my $disk = $line1[0];
109 my $type = $line1[1];
110 $type =~ s/^\s*(.*)\s*$/$1/;
111 #$type =~ s/\s+//g;
112 foreach my $line (@lines) {
113 if ($line =~ /^\s*(\S+)\s+(\S+)\s+(\S+)\s+Maint\S*\s+(.*?)$/i) {
114 $num_metastat_errors++;
115 $metastat_name .= ' [' . $1 . ' (' . $disk . ')][' . $type . ']';
116 }
117 }
118 }
119
120 my $num_metadb_errors = 0;
121 my $metadb_name = '';
122 foreach (split /\n/, $stdout2) {
123 #flags first blk block count
124 # a m pc luo 16 8192 /dev/dsk/c5t600A0B80002929FC0000842E5251EE71d0s7
125 # a pc luo 8208 8192 /dev/dsk/c5t600A0B80002929FC0000842E5251EE71d0s7
126 # a pc luo 16400 8192 /dev/dsk/c5t600A0B80002929FC0000842E5251EE71d0s7
127 # W pc l 16 8192 /dev/dsk/c5t600A0B800011978E000026D95251FEF1d0s7
128 # W pc l 8208 8192 /dev/dsk/c5t600A0B800011978E000026D95251FEF1d0s7
129 # W pc l 16400 8192 /dev/dsk/c5t600A0B800011978E000026D95251FEF1d0s7
130 #
131 # Uppercase letters are problems:
132 # W - replica has device write errors
133 # M - replica had problem with master blocks
134 # D - replica had problem with data blocks
135 # F - replica had format problems
136 # S - replica is too small to hold current data base
137 # R - replica had device read errors
138 if (/^(.*?)[0-9]/i) {
139 my $flags = $1;
140 my $errors_flags = '';
141 while ($flags =~ /([A-Z])/g) {
142 $errors_flags .= $1;
143 }
144
145 next if ($errors_flags eq '');
146 /(\S+)$/;
147 $num_metadb_errors++;
148 $metadb_name .= ' [' . $1 . ' (' . $errors_flags . ')]';
149 }
150 }
151
152 my ($exit_code) = $self->{perfdata}->threshold_check(
153 value => $num_metastat_errors,
154 threshold => [ { label => 'critical', 'exit_litteral' => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]
155 );
156 if ($num_metastat_errors > 0) {
157 $self->{output}->output_add(
158 severity => $exit_code,
159 short_msg => sprintf("Some metadevices need maintenance:" . $metastat_name)
160 );
161 } else {
162 $self->{output}->output_add(
163 severity => 'OK',
164 short_msg => "No problems on metadevices"
165 );
166 }
167
168 ($exit_code) = $self->{perfdata}->threshold_check(
169 value => $num_metadb_errors,
170 threshold => [ { label => 'critical', 'exit_litteral' => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]
171 );
172 if ($num_metadb_errors > 0) {
173 $self->{output}->output_add(
174 severity => $exit_code,
175 short_msg => sprintf("Some replicas have problems:" . $metadb_name)
176 );
177 } else {
178 $self->{output}->output_add(
179 severity => 'OK',
180 short_msg => "No problems on replicas"
181 );
182 }
183
184 $self->{output}->display();
185 $self->{output}->exit();
186 }
187
188 1;
189
190 __END__
191
192 =head1 MODE
193
194 Check SolarisVm disk status
195
196 Command used: '/usr/sbin/metastat 2>&1' and '/usr/sbin/metadb 2>&1'
197
198 =over 8
199
200 =item B<--warning>
201
202 Warning threshold.
203
204 =item B<--critical>
205
206 Critical threshold.
207
208 =back
209
210 =cut