blib/lib/Monitoring/Sneck/Checks/cciss.pm

filter: Statementstmt 93.7% 151 / 161 Branchbran 93.0% 80 / 86 Conditioncond 77.5% 31 / 40 MC/DCmcdc 59.0% 13 / 22 Subroutinesub 100% 12 / 12 Podpod 100% 4 / 4 totaltotal 89.5% 291 / 325 CC 68 SCAR 29.0
CC
68
Cov
91%
controller_status
24.9
_parse
22.9
check
16.0
CRAP 18.1
« blib/lib/Monitoring/Sneck/Checks/jails.pm ↑ Summary blib/lib/Monitoring/Sneck/Checks/dns_sync.pm »
1 package Monitoring::Sneck::Checks::cciss;
2  
3 29 ▶use 5.014;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 29 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 29 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 29 ▶use parent 'Monitoring::Sneck::Checks::base';
Subroutine BEGIN: called CC=1 SCAR=0.0
7 29 ▶use File::Slurp qw(read_file);
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 =head1 NAME
10  
11 Monitoring::Sneck::Checks::cciss - checks HP Smart Array controllers, through cciss_vol_status
12  
13 =head1 VERSION
14  
15 Version 0.1.0
16  
17 =cut
18  
19 29 our $VERSION = '0.1.0';
20  
21 # Where things are. Set by tests. CCISS_VOL_STATUS undef means the first of
22 # CCISS_VOL_STATUS_PATHS that is there.
23 29 our $CCISS_VOL_STATUS;
24 29 our @CCISS_VOL_STATUS_PATHS = (
25 '/usr/bin/cciss_vol_status', '/usr/sbin/cciss_vol_status',
26 '/usr/local/bin/cciss_vol_status', '/usr/local/sbin/cciss_vol_status',
27 );
28 29 our $SYS_VENDOR = '/sys/devices/virtual/dmi/id/sys_vendor';
29 29 our $SCSI_GENERIC = '/sys/class/scsi_generic';
30 29 our $DEV = '/dev';
31  
32 # Volume states, from cciss_vol_status's decode_status, that are passing
33 # rather than broken. Its "expannding" is as it spells it.
34 29 our $PASSING = _any(
35 'Ready for recovery operation',
36 'Currently recovering',
37 'Currently expanding',
38 'Currently expannding',
39 'Not yet available',
40 'Queued for expansion',
41 'Hardware was overheated',
42 );
43  
44 # The cache states cciss_vol_status counts as trouble, some ending in a :.
45 29 our $CACHE_TROUBLE = _any(
46 'Write cache temporarily disabled',
47 'Write Cache permanently disabled',
48 'Possible data loss on last reset',
49 'Cache contains unflushed data',
50 'Cache dirty limit reached',
51 'Excessive ECC errors detected',
52 'Non power related data loss',
53 'HW problem with battery enable',
54 'CPLD battery backed write cache incompatibility',
55 'Permanent disable condition detected',
56 );
57  
58 # A regex matching any of the strings, whole, with a : after allowed.
59 58 ▶sub _any {
Subroutine _any: called CC=1 SCAR=0.0
60 58 my $any = join( '|', map { quotemeta($_) } @_ );
61 58 return qr/\A(?:$any):?\z/;
62 }
63  
64 =head1 SYNOPSIS
65  
66 cciss|perl:cciss
67 cciss_sg0|perl:cciss -d /dev/sg0
68 cciss_bsd|perl:cciss -d /dev/ciss0
69 cciss_no_battery|perl:cciss -C -o
70  
71 =head1 DESCRIPTION
72  
73 Checks the logical volumes, physical drives, enclosures, and cache of
74 HP Smart Array controllers, through cciss_vol_status -u -s -V.
75  
76 - CRITICAL :: A volume FAILED, using interim recovery mode (degraded),
77 with the wrong drive replaced, with a drive not properly connected,
78 overheating, or in a state it does not know. A failed drive, even when
79 a spare has taken over and the volume is OK. A failed spare. A
80 enclosure with a fan, power supply, temperature, or door alert.
81  
82 - WARNING :: A volume ready for recovery, recovering, expanding, queued
83 for expansion, not yet available, or that was overheated in the past.
84 A spare rebuilding. A drive in S.M.A.R.T. predictive failure. Cache
85 trouble, such as the write cache disabled or a battery problem, unless
86 --ignore-cache is given.
87  
88 - UNKNOWN :: cciss_vol_status not being there, or saying nothing about
89 a controller.
90  
91 - OK :: Everything else, including not being a HP, having no
92 controllers, and a controller with no logical drives, such as one used
93 only as a HBA, so the same check can go everywhere.
94  
95 Without --device, the controllers are found...
96  
97 - Linux :: If /sys/devices/virtual/dmi/id/sys_vendor says it is a HP,
98 the sg devices of SCSI type 12, RAID controllers, under
99 /sys/class/scsi_generic, for the hpsa driver, and /dev/cciss/c*d0 for
100 the old cciss driver.
101  
102 - FreeBSD :: /dev/ciss*, as only Smart Arrays have those.
103  
104 This needs root, to open the devices.
105  
106 =head1 OPTIONS
107  
108 - -d, --device :: A controller to check, such as /dev/sg0,
109 /dev/cciss/c0d0, or /dev/ciss0, instead of finding them, and without
110 looking at the vendor. May be given more than once.
111  
112 - -C, --ignore-cache :: Cache trouble is still said, but is OK.
113  
114 - -o, --output :: After the status line, include the output of
115 cciss_vol_status for each controller.
116  
117 - -O, --always-output :: As --output, but for every controller.
118  
119 =cut
120  
121 386 ▶sub option_spec { return ( 'device|d=s@', 'ignore-cache|C', 'output|o', 'always-output|O' ) }
Subroutine option_spec: called CC=1 SCAR=0.0
Pod documented
122  
123 =head1 METHODS
124  
125 =head2 check
126  
127 Does the check.
128  
129 =cut
130  
131 386 ▶sub check {
Subroutine check: called CC=16 SCAR=27.7
Pod documented
132 386 my ($self) = @_;
133  
134 386 ▶ die( 'not supported on ' . $self->os . "\n" ) if $self->os ne 'linux' && $self->os ne 'freebsd';
Branch: 1 branch
BranchTrueFalseTotal
if $self->os ne "linux" and $self->os ne "freebsd" 1 385 386
Condition100%3/3
$self->os ne "linux" and $self->os ne "freebsd"
!ll&&!rl&&r
37691
MC/DC100%2/2
$self->os ne "linux" and $self->os ne "freebsd"
$self->os ne "linux" $self->os ne "freebsd"
Truth table100%3/3
A and B
A= $self->os ne "linux"B= $self->os ne "freebsd"
ABresult
0X0
100
111
135  
136 385 ▶ my @devices = @{ $self->opt('device') // [] };
Condition100%2/2
$self->opt("device") // []
l!l
8377
MC/DC100%1/1
$self->opt("device") // []
$self->opt("device")
Truth table100%2/2
A
A= $self->opt("device")
Aresult
11
00
137 385 ▶ if ( !defined( $devices[0] ) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $devices[0]) 377 8 385
138 377 ▶ if ( $self->os eq 'linux' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->os eq "linux") 368 9 377
139 368 ▶ my $vendor = read_file( $SYS_VENDOR, err_mode => 'quiet' ) // '';
Condition50%1/2
read_file($Monitoring::Sneck::Checks::cciss::SYS_VENDOR, "err_mode", "quiet") // ""
l!l
3680
MC/DC0%0/1
read_file($Monitoring::Sneck::Checks::cciss::SYS_VENDOR, "err_mode", "quiet") // ""
read_file($Monitoring::Sneck::Checks::cciss::SYS_VENDOR, "err_mode", "quiet")
Truth table50%1/2
A
A= read_file($Monitoring::Sneck::Checks::cciss::SYS_VENDOR, "err_mode", "quiet")
Aresult
11
00
140 368 ▶ return $self->finish( $self->OK, 'not a HP' ) if $vendor !~ /\bHPE?\b|Hewlett/i;
Branch: 1 branch
BranchTrueFalseTotal
unless $vendor =~ /\bHPE?\b|Hewlett/iu 5 363 368
141 }
142 372 @devices = $self->controllers;
143 372 ▶ return $self->finish( $self->OK, 'no Smart Array controllers' ) if !defined( $devices[0] );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $devices[0] 6 366 372
144 }
145 374 ▶ my $command = $CCISS_VOL_STATUS // ( grep { -x $_ } @CCISS_VOL_STATUS_PATHS )[0];
Condition66%2/3
$Monitoring::Sneck::Checks::cciss::CCISS_VOL_STATUS // (grep {-x $_;} @Monitoring::Sneck::Checks::cciss::CCISS_VOL_STATUS_PATHS)[0]
l!l&&r!l&&!r
36905
MC/DC50%1/2
$Monitoring::Sneck::Checks::cciss::CCISS_VOL_STATUS // (grep {-x $_;} @Monitoring::Sneck::Checks::cciss::CCISS_VOL_STATUS_PATHS)[0]
$Monitoring::Sneck::Checks::cciss::CCISS_VOL_STATUS (grep {-x $_;} @Monitoring::Sneck::Checks::cciss::CCISS_VOL_STATUS_PATHS)[0]
Truth table66%2/3
A // B
A= $Monitoring::Sneck::Checks::cciss::CCISS_VOL_STATUSB= (grep {-x $_;} @Monitoring::Sneck::Checks::cciss::CCISS_VOL_STATUS_PATHS)[0]
ABresult
1X1
011
000
146 374 ▶ return $self->finish( $self->UNKNOWN, 'cciss_vol_status is not there' ) if !defined($command);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $command 5 369 374
147 369 ▶ return $self->finish( $self->UNKNOWN, $command . ' is not there' ) if !-x $command;
Branch: 1 branch
BranchTrueFalseTotal
unless -x $command 5 364 369
148  
149 364 my @codes;
150 my @parts;
151 364 my @details;
152 364 foreach my $device (@devices) {
153 377 my ( $code, $says, $output ) = $self->controller_status( $command, $device );
154 351 push( @codes, $code );
155 351 push( @parts, $says );
156 351 ▶ if ( $self->opt('always-output') || ( $self->opt('output') && $code != $self->OK ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->opt("always-output") or $self->opt("output") and $code != $self->OK) 29 322 351
Condition100%6/6
$self->opt("always-output") or $self->opt("output") and $code != $self->OK
l!l&&r!l&&!r
1316322
$self->opt("output") and $code != $self->OK
!ll&&!rl&&r
2903216
MC/DC100%3/3
$self->opt("always-output") or $self->opt("output") and $code != $self->OK
$self->opt("always-output") $self->opt("output") $code != $self->OK
Truth table100%4/4
A or B and C
A= $self->opt("always-output")B= $self->opt("output")C= $code != $self->OK
ABCresult
1XX1
0111
00X0
0100
157 29 push( @details, $device . ':', split( /\n/, $output ) );
158 }
159 }
160  
161 338 return $self->finish( $self->worst(@codes), join( ', ', @parts ), @details );
162 } ## end sub check
163  
164 =head2 controllers
165  
166 Returns the controllers found, as in the description, such as /dev/sg0
167 or /dev/ciss0.
168  
169 =cut
170  
171 372 ▶sub controllers {
Subroutine controllers: called CC=8 SCAR=20.8
Pod documented
172 372 my ($self) = @_;
173  
174 372 ▶ my $number = sub { ( $_[0] =~ /([0-9]+)\z/ )[0] // 0 };
Subroutine __ANON__: called CC=2 SCAR=7.2
Condition50%1/2
($_[0] =~ /([0-9]+)\z/u)[0] // 0
l!l
7200
MC/DC0%0/1
($_[0] =~ /([0-9]+)\z/u)[0] // 0
($_[0] =~ /([0-9]+)\z/u)[0]
Truth table50%1/2
A
A= ($_[0] =~ /([0-9]+)\z/u)[0]
Aresult
11
00
175 372 my @controllers;
176 372 ▶ if ( $self->os eq 'freebsd' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->os eq "freebsd") 9 363 372
177 9 ▶ opendir( my $dh, $DEV ) or return ();
Branch: 1 branch
BranchTrueFalseTotal
opendir my $dh, $Monitoring::Sneck::Checks::cciss::DEV or return () 8 1 9
178 16 @controllers = map { $DEV . '/' . $_ }
179 8 sort { $number->($a) <=> $number->($b) } grep { /\Aciss[0-9]+\z/ } readdir($dh);
180 8 return @controllers;
181 }
182  
183 363 ▶ if ( opendir( my $dh, $SCSI_GENERIC ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (opendir my $dh, $Monitoring::Sneck::Checks::cciss::SCSI_GENERIC) 352 11 363
184 352 foreach my $sg ( sort { $number->($a) <=> $number->($b) } grep { /\Asg[0-9]+\z/ } readdir($dh) ) {
185 704 ▶ my $type = read_file( $SCSI_GENERIC . '/' . $sg . '/device/type', err_mode => 'quiet' ) // next;
Condition50%1/2
read_file($Monitoring::Sneck::Checks::cciss::SCSI_GENERIC . '/' . $sg . '/device/type', "err_mode", "quiet") // (next)
l!l
7040
MC/DC0%0/1
read_file($Monitoring::Sneck::Checks::cciss::SCSI_GENERIC . '/' . $sg . '/device/type', "err_mode", "quiet") // (next)
read_file($Monitoring::Sneck::Checks::cciss::SCSI_GENERIC . '/' . $sg . '/device/type', "err_mode", "quiet")
Truth table50%1/2
A
A= read_file($Monitoring::Sneck::Checks::cciss::SCSI_GENERIC . '/' . $sg . '/device/type', "err_mode", "quiet")
Aresult
11
00
186 704 ▶ push( @controllers, $DEV . '/' . $sg ) if $type =~ /\A\s*12\s*\z/;
Branch: 1 branch
BranchTrueFalseTotal
if $type =~ /\A\s*12\s*\z/u 352 352 704
187 }
188 }
189 363 ▶ if ( opendir( my $dh, $DEV . '/cciss' ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (opendir my $dh, $Monitoring::Sneck::Checks::cciss::DEV . '/cciss') 16 347 363
190 push( @controllers,
191 0 map { $DEV . '/cciss/' . $_ } sort { $number->( $a =~ s/d0\z//r ) <=> $number->( $b =~ s/d0\z//r ) }
192 16 grep { /\Ac[0-9]+d0\z/ } readdir($dh) );
193 }
194  
195 363 return @controllers;
196 } ## end sub controllers
197  
198 =head2 controller_status
199  
200 Runs cciss_vol_status -u -s -V on a controller and returns the code,
201 what to say about it, and what cciss_vol_status printed.
202  
203 my ( $code, $says, $output ) = $check->controller_status( '/usr/bin/cciss_vol_status', '/dev/sg0' );
204  
205 =cut
206  
207 377 ▶sub controller_status {
Subroutine controller_status: called CC=24 SCAR=32.1
Pod documented
208 377 my ( $self, $command, $device ) = @_;
209  
210 # it exits 1 when anything is not OK, which the output says more about
211 377 my ( $exit, $output ) = $self->run_command( $command, '-u', '-s', '-V', $device );
212 351 my $found = _parse($output);
213 351 ▶ if ( !defined( $found->{controller} ) && !defined( $found->{volumes}[0] ) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $found->{"controller"} or defined $found->{"volumes"}[0]) 6 345 351
Condition100%3/3
defined $found->{"controller"} or defined $found->{"volumes"}[0]
l!l&&r!l&&!r
34056
MC/DC100%2/2
defined $found->{"controller"} or defined $found->{"volumes"}[0]
defined $found->{"controller"} defined $found->{"volumes"}[0]
Truth table100%3/3
A or B
A= defined $found->{"controller"}B= defined $found->{"volumes"}[0]
ABresult
1X1
011
000
214 0 ▶ my $first = ( grep { /\S/ } split( /\n/, $output ) )[0] // '';
Condition50%1/2
(grep {/\S/u;} split(/\n/u, $output, 0))[0] // ""
l!l
06
MC/DC0%0/1
(grep {/\S/u;} split(/\n/u, $output, 0))[0] // ""
(grep {/\S/u;} split(/\n/u, $output, 0))[0]
Truth table50%1/2
A
A= (grep {/\S/u;} split(/\n/u, $output, 0))[0]
Aresult
11
00
215 6 $first =~ s/\A\s+|\s+\z//g;
216 6 return ( $self->UNKNOWN, $device . ' said nothing, exited ' . $exit . ', "' . $first . '"', $output );
217 }
218  
219 345 my @codes = ( $self->OK );
220 345 my @parts;
221 345 foreach my $volume ( @{ $found->{volumes} } ) {
222 337 my $status = $volume->{status};
223 337 ▶ push(
Branch: 2 branches
BranchTrueFalseTotal
$status eq 'OK' ? : 241 96 337
$status =~ /$Monitoring::Sneck::Checks::cciss::PASSING/u ? : 34 62 96
224 @codes,
225 $status eq 'OK' ? $self->OK
226 : $status =~ $PASSING ? $self->WARNING
227 : $self->CRITICAL
228 );
229 337 my $says = $volume->{device} . ' ' . $volume->{level} . ' ' . lc($status);
230 337 ▶ if ( defined( $volume->{failed}[0] ) ) {
Branch: 2 branches
BranchTrueFalseTotal
if (defined $volume->{'failed'}[0]) { } 65 272 337
elsif ($volume->{'failed_count'}) { } 0 272 272
231 65 push( @codes, $self->CRITICAL );
232 65 $says = $says . ', failed ' . join( ', ', @{ $volume->{failed} } );
233 } elsif ( $volume->{failed_count} ) {
234 0 push( @codes, $self->CRITICAL );
235 0 $says = $says . ', ' . $volume->{failed_count} . ' failed drives';
236 }
237 23 $says = $says . ', replacing ' . join( ', ', @{ $volume->{replacement} } )
238 337 ▶ if defined( $volume->{replacement}[0] );
Branch: 1 branch
BranchTrueFalseTotal
if defined $volume->{"replacement"}[0] 23 314 337
239 337 foreach my $spare ( @{ $volume->{spares} } ) {
240 86 ▶ if ( $spare =~ /has failed/ ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($spare =~ /has failed/u) { } 21 65 86
elsif ($spare =~ /currently rebuilding/u) { } 0 65 65
241 21 push( @codes, $self->CRITICAL );
242 21 $says = $says . ', a spare failed';
243 } elsif ( $spare =~ /currently rebuilding/ ) {
244 0 push( @codes, $self->WARNING );
245 0 $says = $says . ', a spare rebuilding';
246 }
247 }
248 337 push( @parts, $says );
249 } ## end foreach my $volume ( @{ $found->{volumes} } )
250 345 ▶ push( @parts, $device . ' no logical drives' ) if !defined( $found->{volumes}[0] );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $found->{"volumes"}[0] 8 337 345
251  
252 345 my @drives = @{ $found->{drives} };
253 345 my @bad = grep { $_->{status} ne 'OK' } @drives;
254 345 foreach my $drive (@bad) {
255 39 push( @codes, $self->WARNING );
256 39 push( @parts, $drive->{location} . ' ' . $drive->{status} );
257 }
258 # a count of drives ok next to failed ones would only confuse, as only S.M.A.R.T. goes in their status
259 345 ▶ my $any_failed = grep { defined( $_->{failed}[0] ) || $_->{failed_count} } @{ $found->{volumes} };
Condition66%2/3
defined $_->{'failed'}[0] || $_->{'failed_count'}
l!l&&r!l&&!r
650272
MC/DC50%1/2
defined $_->{'failed'}[0] || $_->{'failed_count'}
defined $_->{'failed'}[0] $_->{'failed_count'}
Truth table66%2/3
A || B
A= defined $_->{'failed'}[0]B= $_->{'failed_count'}
ABresult
1X1
011
000
260 345 ▶ push( @parts, scalar(@drives) . ' drives ok' ) if defined( $drives[0] ) && !defined( $bad[0] ) && !$any_failed;
Branch: 1 branch
BranchTrueFalseTotal
if defined $drives[0] and not defined $bad[0] and not $any_failed 236 109 345
Condition100%6/6
defined $drives[0] and not defined $bad[0] and not $any_failed
!ll&&!rl&&r
4465236
defined $drives[0] and not defined $bad[0]
!ll&&!rl&&r
539301
MC/DC100%3/3
defined $drives[0] and not defined $bad[0] and not $any_failed
defined $drives[0] not defined $bad[0] not $any_failed
Truth table100%4/4
A and not(B) and not(C)
A= defined $drives[0]B= not defined $bad[0]C= not $any_failed
ABCresult
0XX0
10X0
1100
1111
261  
262 345 foreach my $enclosure ( @{ $found->{enclosures} } ) {
263 24 ▶ next if $enclosure->{status} eq 'OK';
Branch: 1 branch
BranchTrueFalseTotal
if $enclosure->{"status"} eq "OK" 12 12 24
264 12 push( @codes, $self->CRITICAL );
265 12 push( @parts, 'enclosure ' . $enclosure->{name} . ' ' . lc( $enclosure->{status} ) );
266 }
267 345 foreach my $trouble ( @{ $found->{cache} } ) {
268 90 ▶ push( @codes, $self->WARNING ) if !$self->opt('ignore-cache');
Branch: 1 branch
BranchTrueFalseTotal
unless $self->opt("ignore-cache") 38 52 90
269 90 push( @parts, $device . ' ' . lc($trouble) );
270 }
271 345 foreach my $problem ( @{ $found->{problems} } ) {
272 0 push( @codes, $self->WARNING );
273 0 push( @parts, $device . ' ' . lc($problem) );
274 }
275  
276 345 return ( $self->worst(@codes), join( ', ', @parts ), $output );
277 } ## end sub controller_status
278  
279 # Parses the output of cciss_vol_status -u -s -V for one controller.
280 #
281 # Args...
282 #
283 # - output :: What cciss_vol_status printed.
284 #
285 # Returns a hash ref of...
286 #
287 # - controller :: Its name, if -V printed it.
288 # - volumes :: Array ref of hash refs of device, level, status, spares, a array ref of
289 # spare messages, failed and replacement, array refs of drive locations, and failed_count.
290 # - drives :: Array ref of hash refs of location and status, OK or predictive failure.
291 # - enclosures :: Array ref of hash refs of name and status.
292 # - cache :: Array ref of cache trouble, such as 'Write cache temporarily disabled'.
293 # - problems :: Array ref of other trouble, such as 'could not read a drive'.
294 #
295 # Example...
296 #
297 # my $found = _parse($output);
298 # # $found->{volumes}[0] is { device => '/dev/sda', level => 'RAID 5', status => 'OK', ... }
299 # # $found->{drives}[0] is { location => 'connector 1I box 1 bay 1', status => 'OK' }
300 351 ▶sub _parse {
Subroutine _parse: called CC=22 SCAR=31.3
301 351 my ($output) = @_;
302  
303 351 my %found = ( volumes => [], drives => [], enclosures => [], cache => [], problems => [] );
304 351 my $section = '';
305 351 foreach my $line ( split( /\n/, $output ) ) {
306 5260 ▶ if ( $line =~ /\AController: (.*?)\s*\z/ ) {
Branch: 10 branches
BranchTrueFalseTotal
if ($line =~ /\AController: (.*?)\s*\z/u) { } 340 4920 5260
elsif ($line =~ /\A(\S+): \(.*?\) (.+?) Volume \S+ status: (Unknown status [0-9]+|[^.]*)\.(.*)/u) { } 337 4583 4920
elsif ($line =~ m[\A\S+: \(.*?\) Enclosure (.*?) \(S/N: .*\) on Bus [0-9]+, Physical Port (\S+) status: (.*?)\.\s*\z]u) { } 24 4559 4583
elsif ($line =~ /\A\s*(Failed drives|'Replacement' drives|Drives currently substituted for by spares):\s*\z/u) { } 110 4449 4559
elsif ($line =~ /\A\s*Physical drives: [0-9]+/u) { } 340 4109 4449
elsif ($line =~ /\A\s*Total of ([0-9]+) failed physical drives/u) { } 65 4044 4109
elsif ($line =~ /\A\s+(?:b[0-9]+t[0-9]+\s+)?(connector \S+ box \S+ bay \S+)\s/u) { } 1520 2524 4044
elsif ((my $trimmed = $line =~ s/\A\s+|\s+\z//gru) =~ /$Monitoring::Sneck::Checks::cciss::CACHE_TROUBLE/u) { } 90 2434 2524
elsif ($line =~ /\ACannot get device information for/u) { } 0 2434 2434
elsif ($line =~ /\A\S/u) { } 340 2094 2434
307 340 $found{controller} = $1;
308 } elsif ( $line =~ /\A(\S+): \(.*?\) (.+?) Volume \S+ status: (Unknown status [0-9]+|[^.]*)\.(.*)/ ) {
309 337 my ( $device, $level, $status, $rest ) = ( $1, $2, $3, $4 );
310 push(
311 337 @{ $found{volumes} },
312 {
313 device => $device,
314 level => $level,
315 status => $status,
316 spares => [ $rest =~ /(At least one [^.]+)/g ],
317 failed => [],
318 replacement => [],
319 }
320 );
321 337 $section = '';
322 } elsif ( $line
323 =~ /\A\S+: \(.*?\) Enclosure (.*?) \(S\/N: .*\) on Bus [0-9]+, Physical Port (\S+) status: (.*?)\.\s*\z/
324 )
325 {
326 24 push( @{ $found{enclosures} }, { name => $1 . ' port ' . $2, status => $3 } );
327 } elsif (
328 $line =~ /\A\s*(Failed drives|'Replacement' drives|Drives currently substituted for by spares):\s*\z/ )
329 {
330 110 ▶ $section
Branch: 2 branches
BranchTrueFalseTotal
$1 eq 'Failed drives' ? : 65 45 110
$1 eq 'Drives currently substituted for by spares' ? : 22 23 45
331 = $1 eq 'Failed drives' ? 'failed'
332 : $1 eq 'Drives currently substituted for by spares' ? 'failed'
333 : 'replacement';
334 } elsif ( $line =~ /\A\s*Physical drives: [0-9]+/ ) {
335 340 $section = 'drives';
336 } elsif ( $line =~ /\A\s*Total of ([0-9]+) failed physical drives/ ) {
337 65 ▶ $found{volumes}[-1]{failed_count} = $1 if defined( $found{volumes}[0] );
Branch: 1 branch
BranchTrueFalseTotal
if defined $found{"volumes"}[0] 65 0 65
338 } elsif ( $line =~ /\A\s+(?:b[0-9]+t[0-9]+\s+)?(connector \S+ box \S+ bay \S+)\s/ ) {
339 1520 my $location = $1;
340 1520 ▶ if ( $section eq 'drives' ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($section eq 'drives') { } 1410 110 1520
elsif ($section eq 'failed' || $section eq 'replacement' and defined $found{'volumes'}[0]) { } 110 0 110
341 1410 ▶ my $status
Branch: 2 branches
BranchTrueFalseTotal
$line =~ /\sOK\s*\z/u ? : 1371 39 1410
$line =~ /S\.M\.A\.R\.T\. predictive failure/u ? : 39 0 39
342 = $line =~ /\sOK\s*\z/ ? 'OK'
343 : $line =~ /S\.M\.A\.R\.T\. predictive failure/ ? 'predictive failure'
344 : 'not OK';
345 1410 push( @{ $found{drives} }, { location => $location, status => $status } );
346 ▶ } elsif ( ( $section eq 'failed' || $section eq 'replacement' ) && defined( $found{volumes}[0] ) ) {
Condition50%3/6
$section eq "failed" || $section eq "replacement" and defined $found{"volumes"}[0]
!ll&&!rl&&r
00110
$section eq "failed" or $section eq "replacement"
l!l&&r!l&&!r
87230
MC/DC0%0/3
$section eq "failed" || $section eq "replacement" and defined $found{"volumes"}[0]
$section eq "failed" $section eq "replacement" defined $found{"volumes"}[0]
Truth table40%2/5
A or B and C
A= $section eq "failed"B= $section eq "replacement"C= defined $found{"volumes"}[0]
ABCresult
00X0
1X00
0100
1X11
0111
347 110 my $list = $found{volumes}[-1]{$section};
348 110 ▶ push( @{$list}, $location ) if !grep { $_ eq $location } @{$list};
Branch: 1 branch
BranchTrueFalseTotal
unless grep {$_ eq $location;} @{$list;} 88 22 110
349 }
350 } elsif ( ( my $trimmed = $line =~ s/\A\s+|\s+\z//gr ) =~ $CACHE_TROUBLE ) {
351 90 push( @{ $found{cache} }, $trimmed =~ s/:\z//r );
352 } elsif ( $line =~ /\ACannot get device information for/ ) {
353 0 push( @{ $found{problems} }, 'could not read a drive' );
354 } elsif ( $line =~ /\A\S/ ) {
355 340 $section = '';
356 }
357 } ## end foreach my $line ( split( /\n/, $output ) )
358  
359 351 return \%found;
360 } ## end sub _parse
361  
362 29 1;
« blib/lib/Monitoring/Sneck/Checks/jails.pm ↑ Summary blib/lib/Monitoring/Sneck/Checks/dns_sync.pm »