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

filter: Statementstmt 97.3% 149 / 153 Branchbran 92.2% 83 / 90 Conditioncond 76.4% 26 / 34 MC/DCmcdc 57.8% 11 / 19 Subroutinesub 100% 11 / 11 Podpod 100% 5 / 5 totaltotal 91.3% 285 / 312 CC 63 SCAR 30.0
CC
63
Cov
93%
_parse_status
24.2
pool_status
24.2
check
17.2
CRAP 20.0
« blib/lib/Monitoring/Sneck/Checks/auditd.pm ↑ Summary blib/lib/Monitoring/Sneck/Checks/vrrp.pm »
1 package Monitoring::Sneck::Checks::zfs;
2  
3 21 ▶use 5.014;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 21 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 21 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 21 ▶use parent 'Monitoring::Sneck::Checks::base';
Subroutine BEGIN: called CC=1 SCAR=0.0
7 21 ▶use Time::Local qw(timelocal);
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 =head1 NAME
10  
11 Monitoring::Sneck::Checks::zfs - checks ZFS pools, health, capacity, scrubs, and device errors
12  
13 =head1 VERSION
14  
15 Version 0.0.1
16  
17 =cut
18  
19 21 our $VERSION = '0.0.1';
20  
21 # Where zpool is. Set by tests. ZPOOL undef means the first of ZPOOL_PATHS
22 # that is there.
23 21 our $ZPOOL;
24 21 our @ZPOOL_PATHS = ( '/sbin/zpool', '/usr/sbin/zpool', '/usr/local/sbin/zpool' );
25  
26 # Month numbers, as timelocal wants them, by the names zpool status uses.
27 21 our %MONTHS = (
28 Jan => 0,
29 Feb => 1,
30 Mar => 2,
31 Apr => 3,
32 May => 4,
33 Jun => 5,
34 Jul => 6,
35 Aug => 7,
36 Sep => 8,
37 Oct => 9,
38 Nov => 10,
39 Dec => 11,
40 );
41  
42 # Device states that are fine, AVAIL and INUSE being those of spares.
43 21 our %DEVICE_FINE = map { $_ => 1 } ( 'ONLINE', 'AVAIL', 'INUSE' );
44  
45 =head1 SYNOPSIS
46  
47 zfs|perl:zfs
48 zfs_tank|perl:zfs -p tank -w 70 -c 85
49 zfs_scrubs|perl:zfs --scrub-warning 35 --scrub-critical 60
50 zfs_frag|perl:zfs --frag-warning 50
51  
52 =head1 DESCRIPTION
53  
54 Checks pools through zpool list and zpool status.
55  
56 - CRITICAL :: A pool not ONLINE, such as DEGRADED or FAULTED. Data
57 errors. A pool given with --pool not being there. Capacity,
58 fragmentation, or scrub age over their critical.
59  
60 - WARNING :: A resilver running. A device not ONLINE, such as a
61 FAULTED disk or UNAVAIL spare. A device with read, write, or checksum
62 errors. Capacity, fragmentation, or scrub age over their warning.
63  
64 - UNKNOWN :: zpool not being there, or failing.
65  
66 - OK :: Everything else, including a scrub running and having no
67 pools.
68  
69 Scrub age is the days since the last scrub or resilver finished, as
70 zpool status only says the last. A pool with neither finished, such as
71 a new one or one whose scrub was canceled, is over any scrub range.
72  
73 Device error counts stay until zpool clear is run.
74  
75 A line for each pool follows the status line.
76  
77 =head1 OPTIONS
78  
79 - -p, --pool :: A pool to check, instead of all of them. May be given
80 more than once.
81  
82 - -w, --warning :: Range for capacity, in percent.
83 Default :: 80
84  
85 - -c, --critical :: Range for capacity, in percent.
86 Default :: 90
87  
88 - --frag-warning :: Range for fragmentation, in percent.
89  
90 - --frag-critical :: Range for fragmentation, in percent.
91  
92 - --scrub-warning :: Range for scrub age, in days.
93 Default :: 40
94  
95 - --scrub-critical :: Range for scrub age, in days.
96  
97 =cut
98  
99 102 ▶sub option_spec {
Subroutine option_spec: called CC=1 SCAR=0.0
Pod documented
100 return (
101 102 'pool|p=s@', 'warning|w=s', 'critical|c=s', 'frag-warning=s',
102 'frag-critical=s', 'scrub-warning=s', 'scrub-critical=s',
103 );
104 }
105  
106 102 ▶sub defaults { return { warning => '80', critical => '90', 'scrub-warning' => '40' } }
Subroutine defaults: called CC=1 SCAR=0.0
Pod documented
107  
108 102 ▶sub ranges {
Subroutine ranges: called CC=1 SCAR=0.0
Pod documented
109 102 return ( 'warning', 'critical', 'frag-warning', 'frag-critical', 'scrub-warning', 'scrub-critical' );
110 }
111  
112 =head1 METHODS
113  
114 =head2 check
115  
116 Does the check.
117  
118 =cut
119  
120 102 ▶sub check {
Subroutine check: called CC=17 SCAR=28.5
Pod documented
121 102 my ($self) = @_;
122  
123 0 ▶ my $zpool = $ZPOOL // ( grep { -x $_ } @ZPOOL_PATHS )[0];
Condition33%1/3
$Monitoring::Sneck::Checks::zfs::ZPOOL // (grep {-x $_;} @Monitoring::Sneck::Checks::zfs::ZPOOL_PATHS)[0]
l!l&&r!l&&!r
10200
MC/DC0%0/2
$Monitoring::Sneck::Checks::zfs::ZPOOL // (grep {-x $_;} @Monitoring::Sneck::Checks::zfs::ZPOOL_PATHS)[0]
$Monitoring::Sneck::Checks::zfs::ZPOOL (grep {-x $_;} @Monitoring::Sneck::Checks::zfs::ZPOOL_PATHS)[0]
Truth table33%1/3
A // B
A= $Monitoring::Sneck::Checks::zfs::ZPOOLB= (grep {-x $_;} @Monitoring::Sneck::Checks::zfs::ZPOOL_PATHS)[0]
ABresult
1X1
011
000
124 102 ▶ return $self->finish( $self->UNKNOWN, 'zpool is not there' ) if !defined($zpool);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $zpool 0 102 102
125 102 ▶ return $self->finish( $self->UNKNOWN, $zpool . ' is not there' ) if !-x $zpool;
Branch: 1 branch
BranchTrueFalseTotal
unless -x $zpool 1 101 102
126  
127 # so numbers and dates come out the same everywhere
128 101 local $ENV{LC_ALL} = 'C';
129  
130 101 my ( $list_exit, $list ) = $self->run_command( $zpool, 'list', '-Hp', '-o', 'name,health,capacity,fragmentation' );
131 91 ▶ return $self->finish( $self->UNKNOWN, 'zpool list exited ' . $list_exit . ', ' . ( $list =~ s/\s+\z//r ) )
Branch: 1 branch
BranchTrueFalseTotal
if $list_exit 1 90 91
132 if $list_exit;
133 90 my %pools;
134 90 foreach my $line ( split( /\n/, $list ) ) {
135 158 my ( $name, $health, $capacity, $fragmentation ) = split( /\t/, $line );
136 158 ▶ next if !defined($fragmentation);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $fragmentation 0 158 158
137 158 $pools{$name}
138 = { health => $health, capacity => $capacity =~ s/%\z//r, fragmentation => $fragmentation =~ s/%\z//r };
139 }
140  
141 90 ▶ my @names = @{ $self->opt('pool') // [] };
Condition100%2/2
$self->opt("pool") // []
l!l
2664
MC/DC100%1/1
$self->opt("pool") // []
$self->opt("pool")
Truth table100%2/2
A
A= $self->opt("pool")
Aresult
11
00
142 90 ▶ @names = sort( keys(%pools) ) if !defined( $names[0] );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $names[0] 64 26 90
143 90 ▶ return $self->finish( $self->OK, 'no pools' ) if !defined( $names[0] );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $names[0] 2 88 90
144  
145 88 my ( $status_exit, $status ) = $self->run_command( $zpool, 'status', '-p' );
146 80 ▶ return $self->finish( $self->UNKNOWN, 'zpool status exited ' . $status_exit . ', ' . ( $status =~ s/\s+\z//r ) )
Branch: 1 branch
BranchTrueFalseTotal
if $status_exit 0 80 80
147 if $status_exit;
148 80 my $statuses = _parse_status($status);
149  
150 80 my @codes;
151 my @parts;
152 80 my @details;
153 80 my $ok_count = 0;
154 80 foreach my $name (@names) {
155 136 ▶ if ( !defined( $pools{$name} ) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $pools{$name}) 15 121 136
156 15 push( @codes, $self->CRITICAL );
157 15 push( @parts, $name . ' is not there' );
158 15 next;
159 }
160 121 my ( $code, $says, $detail ) = $self->pool_status( $name, $pools{$name}, $statuses->{$name} );
161 121 push( @codes, $code );
162 121 push( @details, $detail );
163 121 ▶ defined($says) ? push( @parts, $says ) : $ok_count++;
Branch: 1 branch
BranchTrueFalseTotal
defined $says ? : 50 71 121
164 } ## end foreach my $name (@names)
165 80 ▶ if ($ok_count) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ok_count) 54 26 80
166 54 ▶ my $noun = defined( $parts[0] ) ? 'other' : 'pool';
Branch: 1 branch
BranchTrueFalseTotal
defined $parts[0] ? : 28 26 54
167 54 ▶ $noun = $noun . 's' if $ok_count > 1;
Branch: 1 branch
BranchTrueFalseTotal
if $ok_count > 1 17 37 54
168 54 push( @parts, $ok_count . ' ' . $noun . ' ok' );
169 }
170  
171 # pools are split by ; as what is said about each has commas
172 80 return $self->finish( $self->worst(@codes), join( '; ', @parts ), @details );
173 } ## end sub check
174  
175 =head2 pool_status
176  
177 Works out how a pool is.
178  
179 - name :: The pool's name.
180  
181 - listed :: Hash ref from zpool list, of health, capacity, and
182 fragmentation, which is - if the pool has none.
183  
184 - status :: Hash ref of what zpool status said about it, as from
185 _parse_status, or undef if it said nothing.
186  
187 Returns the code, what to say about the pool in the status line, undef
188 if it is fine, and the line about it for after the status line.
189  
190 my ( $code, $says, $detail )
191 = $check->pool_status( 'tank', { health => 'ONLINE', capacity => 85, fragmentation => 10 }, $status );
192 # ( 1, 'tank 85% full', 'tank ONLINE, 85% full, 10% fragmented, scrubbed 3 days ago' )
193  
194 =cut
195  
196 121 ▶sub pool_status {
Subroutine pool_status: called CC=24 SCAR=31.9
Pod documented
197 121 my ( $self, $name, $listed, $status ) = @_;
198  
199 121 my @codes = ( $self->OK );
200 121 my @problems;
201 121 my @detail = ( $name . ' ' . $listed->{health}, $listed->{capacity} . '% full' );
202  
203 121 ▶ if ( $listed->{health} ne 'ONLINE' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($listed->{"health"} ne "ONLINE") 11 110 121
204 11 push( @codes, $self->CRITICAL );
205 11 push( @problems, $listed->{health} );
206 }
207  
208 121 my $capacity_code = $self->threshold_status( $listed->{capacity}, $self->opt('warning'), $self->opt('critical') );
209 121 push( @codes, $capacity_code );
210 121 ▶ push( @problems, $listed->{capacity} . '% full' ) if $capacity_code != $self->OK;
Branch: 1 branch
BranchTrueFalseTotal
if $capacity_code != $self->OK 26 95 121
211 $self->perfdata(
212 label => $name . '_capacity',
213 value => $listed->{capacity},
214 121 uom => '%',
215 warning => $self->opt('warning'),
216 critical => $self->opt('critical'),
217 min => 0,
218 max => 100,
219 );
220  
221 121 ▶ if ( $listed->{fragmentation} =~ /\A[0-9]+\z/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($listed->{"fragmentation"} =~ /\A[0-9]+\z/u) 101 20 121
222 101 my $fragmentation = $listed->{fragmentation};
223 101 my $fragmentation_code
224 = $self->threshold_status( $fragmentation, $self->opt('frag-warning'), $self->opt('frag-critical') );
225 101 push( @codes, $fragmentation_code );
226 101 ▶ push( @problems, $fragmentation . '% fragmented' ) if $fragmentation_code != $self->OK;
Branch: 1 branch
BranchTrueFalseTotal
if $fragmentation_code != $self->OK 13 88 101
227 101 push( @detail, $fragmentation . '% fragmented' );
228 101 $self->perfdata(
229 label => $name . '_fragmentation',
230 value => $fragmentation,
231 uom => '%',
232 warning => $self->opt('frag-warning'),
233 critical => $self->opt('frag-critical'),
234 min => 0,
235 max => 100,
236 );
237 } ## end if ( $listed->{fragmentation} =~ /\A[0-9]+\z/)
238  
239 121 ▶ if ( !defined($status) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $status) 0 121 121
240 0 push( @codes, $self->UNKNOWN );
241 0 push( @problems, 'not in zpool status' );
242 0 return ( $self->worst(@codes), $name . ' ' . join( ', ', @problems ), join( ', ', @detail ) );
243 }
244  
245 121 my $scan = $status->{scan};
246 121 ▶ if ( defined( $scan->{running} ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $scan->{'running'}) { } 41 80 121
247 41 ▶ my $running = ( $scan->{running} eq 'scrub' ? 'scrubbing ' : 'resilvering ' ) . $scan->{done} . '%';
Branch: 1 branch
BranchTrueFalseTotal
$scan->{'running'} eq 'scrub' ? : 30 11 41
248 41 push( @detail, $running );
249 41 ▶ if ( $scan->{running} eq 'resilver' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($scan->{"running"} eq "resilver") 11 30 41
250 11 push( @codes, $self->WARNING );
251 11 push( @problems, $running );
252 }
253 } else {
254 # a pool never scrubbed is as old as can be
255 80 ▶ my $age = defined( $scan->{finished} ) ? ( time - $scan->{finished} ) / 86400 : 9**9**9;
Branch: 1 branch
BranchTrueFalseTotal
defined $scan->{'finished'} ? : 60 20 80
256 my $says
257 = defined( $scan->{finished} )
258 80 ▶ ? $scan->{verb} . ' ' . int($age) . ' days ago'
Branch: 1 branch
BranchTrueFalseTotal
defined $scan->{'finished'} ? : 60 20 80
259 : 'no finished scrub';
260 80 my $scan_code = $self->threshold_status( $age, $self->opt('scrub-warning'), $self->opt('scrub-critical') );
261 80 push( @codes, $scan_code );
262 80 ▶ push( @problems, $says ) if $scan_code != $self->OK;
Branch: 1 branch
BranchTrueFalseTotal
if $scan_code != $self->OK 23 57 80
263 80 push( @detail, $says );
264 80 ▶ if ( defined( $scan->{finished} ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $scan->{"finished"}) 60 20 80
265 60 $self->perfdata(
266 label => $name . '_scrub_age',
267 value => sprintf( '%.2f', $age ),
268 warning => $self->opt('scrub-warning'),
269 critical => $self->opt('scrub-critical'),
270 min => 0,
271 );
272 }
273 } ## end else [ if ( defined( $scan->{running} ) ) ]
274  
275 121 foreach my $device ( @{ $status->{devices} } ) {
276 # a group such as raidz1-0 or spare-1 is only DEGRADED for what is under it, which is said itself
277 my $bad_state = !$DEVICE_FINE{ $device->{state} }
278 558 ▶ && !( $device->{state} eq 'DEGRADED' && $device->{name} =~ /-[0-9]+\z/ );
Condition83%5/6
$Monitoring::Sneck::Checks::zfs::DEVICE_FINE{$device->{'state'}} || $device->{'state'} eq 'DEGRADED' && $device->{'name'} =~ /-[0-9]+\z/u
l!l&&r!l&&!r
5142222
$device->{"state"} eq "DEGRADED" and $device->{"name"} =~ /-[0-9]+\z/u
!ll&&!rl&&r
22022
MC/DC66%2/3
$Monitoring::Sneck::Checks::zfs::DEVICE_FINE{$device->{'state'}} || $device->{'state'} eq 'DEGRADED' && $device->{'name'} =~ /-[0-9]+\z/u
$Monitoring::Sneck::Checks::zfs::DEVICE_FINE{$device->{'state'}} $device->{"state"} eq "DEGRADED" $device->{"name"} =~ /-[0-9]+\z/u
Truth table75%3/4
A || B and C
A= $Monitoring::Sneck::Checks::zfs::DEVICE_FINE{$device->{'state'}}B= $device->{"state"} eq "DEGRADED"C= $device->{"name"} =~ /-[0-9]+\z/u
ABCresult
1XX1
0111
00X0
0100
279 558 my @errors = map { $device->{$_} . ' ' . $_ } grep { $device->{$_} ne '0' } ( 'read', 'write', 'checksum' );
280 558 ▶ next if !$bad_state && !defined( $errors[0] );
Branch: 1 branch
BranchTrueFalseTotal
unless $bad_state or defined $errors[0] 525 33 558
Condition100%3/3
$bad_state or defined $errors[0]
l!l&&r!l&&!r
2211525
MC/DC100%2/2
$bad_state or defined $errors[0]
$bad_state defined $errors[0]
Truth table100%3/3
A or B
A= $bad_stateB= defined $errors[0]
ABresult
1X1
011
000
281  
282 33 my $says = $device->{name};
283 33 ▶ $says = $says . ' ' . $device->{state} if $bad_state;
Branch: 1 branch
BranchTrueFalseTotal
if $bad_state 22 11 33
284 33 ▶ $says = $says . ' with ' . join( ', ', @errors ) . ' errors' if defined( $errors[0] );
Branch: 1 branch
BranchTrueFalseTotal
if defined $errors[0] 22 11 33
285 33 push( @codes, $self->WARNING );
286 33 push( @problems, $says );
287 } ## end foreach my $device ( @{ $status->{devices} } )
288  
289 121 ▶ if ( defined( $status->{data_errors} ) && $status->{data_errors} !~ /\ANo known data errors/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $status->{"data_errors"} and not $status->{"data_errors"} =~ /\ANo known data errors/u) 11 110 121
Condition66%2/3
defined $status->{"data_errors"} and not $status->{"data_errors"} =~ /\ANo known data errors/u
!ll&&!rl&&r
011011
MC/DC50%1/2
defined $status->{"data_errors"} and not $status->{"data_errors"} =~ /\ANo known data errors/u
defined $status->{"data_errors"} not $status->{"data_errors"} =~ /\ANo known data errors/u
Truth table66%2/3
A and not(B)
A= defined $status->{"data_errors"}B= not $status->{"data_errors"} =~ /\ANo known data errors/u
ABresult
0X0
100
111
290 11 push( @codes, $self->CRITICAL );
291 push( @problems,
292 11 ▶ $status->{data_errors} =~ /\A([0-9]+) data errors/ ? $1 . ' data errors' : $status->{data_errors} );
Branch: 1 branch
BranchTrueFalseTotal
$status->{'data_errors'} =~ /\A([0-9]+) data errors/u ? : 11 0 11
293 }
294  
295 return (
296 121 ▶ $self->worst(@codes),
Branch: 1 branch
BranchTrueFalseTotal
defined $problems[0] ? : 50 71 121
297 defined( $problems[0] ) ? $name . ' ' . join( ', ', @problems ) : undef,
298 join( ', ', @detail )
299 );
300 } ## end sub pool_status
301  
302 # Parses the output of zpool status -p, for every pool.
303 #
304 # Args...
305 #
306 # - output :: What zpool status -p printed.
307 #
308 # Returns a hash ref of pool names to hash refs of...
309 #
310 # - state :: The pool's state, such as ONLINE.
311 # - scan :: Hash ref of running, scrub or resilver if one is running, and done, the
312 # percent done, or of finished, the epoch the last finished, and verb, scrubbed or
313 # resilvered. Empty if none has finished and none is running.
314 # - devices :: Array ref of hash refs of name, state, read, write, and checksum, the
315 # error counts, for every vdev and device but the pool itself, spares and logs included.
316 # Counts a line does not have, as for spares, are 0.
317 # - data_errors :: What the errors line says, such as 'No known data errors'.
318 #
319 # Example...
320 #
321 # my $statuses = _parse_status($output);
322 # # $statuses->{tank}{scan} is { finished => 1793583466, verb => 'scrubbed' }
323 # # $statuses->{tank}{devices}[0] is { name => 'raidz1-0', state => 'ONLINE', read => 0, ... }
324 80 ▶sub _parse_status {
Subroutine _parse_status: called CC=24 SCAR=31.9
325 80 my ($output) = @_;
326  
327 80 my %pools;
328 my $name;
329 80 my $section = '';
330 80 foreach my $line ( split( /\n/, $output ) ) {
331 2615 ▶ if ( $line =~ /\A\s*pool: (\S+)/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($line =~ /\A\s*pool: (\S+)/u) 145 2470 2615
332 145 $name = $1;
333 145 $pools{$name} = { scan => {}, scan_text => '', devices => [] };
334 145 $section = '';
335 145 next;
336 }
337 2470 ▶ next if !defined($name);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $name 0 2470 2470
338  
339 # device names can have colons in them, such as pci-0000:00:1f.2-ata-1, so only errors ends the config
340 2470 ▶ if ( $section eq 'config' ) {
Branch: 3 branches
BranchTrueFalseTotal
if ($section eq 'config') { } 1555 915 2470
elsif ($line =~ /\A\s*([a-z_]+):\s*(.*?)\s*\z/u) { } 565 350 915
elsif ($section eq 'scan') { } 130 220 350
341 1555 ▶ if ( $line =~ /\Aerrors:\s*(.*?)\s*\z/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($line =~ /\Aerrors:\s*(.*?)\s*\z/u) 145 1410 1555
342 145 $pools{$name}{data_errors} = $1;
343 145 $section = '';
344 145 next;
345 }
346 # the NAME header and section names such as logs or spares have no state
347 1410 my ( $device, $state, @counts ) = split( ' ', $line );
348 1410 ▶ next if !defined($state) || $device eq $name || ( $device eq 'NAME' && $state eq 'STATE' );
Branch: 1 branch
BranchTrueFalseTotal
if not defined $state or $device eq $name or $device eq "NAME" and $state eq "STATE" 735 675 1410
Condition88%8/9
not defined $state or $device eq $name or $device eq "NAME" and $state eq "STATE"
l!l&&r!l&&!r
590145675
not defined $state or $device eq $name
l!l&&r!l&&!r
445145820
$device eq "NAME" and $state eq "STATE"
!ll&&!rl&&r
6750145
MC/DC75%3/4
not defined $state or $device eq $name or $device eq "NAME" and $state eq "STATE"
not defined $state $device eq $name $device eq "NAME" $state eq "STATE"
Truth table80%4/5
not(A) or B or C and D
A= not defined $stateB= $device eq $nameC= $device eq "NAME"D= $state eq "STATE"
ABCDresult
1XXX1
01XX1
00111
000X0
00100
349 675 ▶ @counts = map { defined($_) && /\A[0-9]/ ? $_ : 0 } @counts[ 0 .. 2 ];
Branch: 1 branch
BranchTrueFalseTotal
defined $_ && /\A[0-9]/u ? : 1770 255 2025
Condition100%3/3
defined $_ and /\A[0-9]/u
!ll&&!rl&&r
1551001770
MC/DC100%2/2
defined $_ and /\A[0-9]/u
defined $_ /\A[0-9]/u
Truth table100%3/3
A and B
A= defined $_B= /\A[0-9]/u
ABresult
0X0
100
111
350 push(
351 675 @{ $pools{$name}{devices} },
352 {
353 name => $device,
354 state => $state,
355 read => $counts[0],
356 write => $counts[1],
357 checksum => $counts[2]
358 }
359 );
360 } elsif ( $line =~ /\A\s*([a-z_]+):\s*(.*?)\s*\z/ ) {
361 565 $section = $1;
362 565 ▶ $pools{$name}{state} = $2 if $section eq 'state';
Branch: 1 branch
BranchTrueFalseTotal
if $section eq "state" 145 420 565
363 565 ▶ $pools{$name}{scan_text} = $2 if $section eq 'scan';
Branch: 1 branch
BranchTrueFalseTotal
if $section eq "scan" 145 420 565
364 } elsif ( $section eq 'scan' ) {
365 130 $pools{$name}{scan_text} = $pools{$name}{scan_text} . ' ' . ( $line =~ s/\A\s+|\s+\z//gr );
366 }
367 } ## end foreach my $line ( split( /\n/, $output ) )
368  
369 80 foreach my $pool ( values(%pools) ) {
370 145 my $text = delete( $pool->{scan_text} );
371 145 my ($running) = $text =~ /\A(scrub|resilver) in progress/;
372 145 ▶ if ( defined($running) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $running) 65 80 145
373 65 ▶ $pool->{scan} = { running => $running, done => ( $text =~ /([0-9.]+)% done/ )[0] // '?' };
Condition50%1/2
($text =~ /([0-9.]+)% done/u)[0] // "?"
l!l
650
MC/DC0%0/1
($text =~ /([0-9.]+)% done/u)[0] // "?"
($text =~ /([0-9.]+)% done/u)[0]
Truth table50%1/2
A
A= ($text =~ /([0-9.]+)% done/u)[0]
Aresult
11
00
374 65 next;
375 }
376 80 my $verb;
377 80 ▶ $verb = 'scrubbed' if $text =~ /\Ascrub repaired/;
Branch: 1 branch
BranchTrueFalseTotal
if $text =~ /\Ascrub repaired/u 45 35 80
378 80 ▶ $verb = 'resilvered' if $text =~ /\Aresilvered/;
Branch: 1 branch
BranchTrueFalseTotal
if $text =~ /\Aresilvered/u 15 65 80
379 80 ▶ next if !defined($verb);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $verb 20 60 80
380 # the end is a date as ctime prints it, such as "on Sun Nov 1 01:47:46 2026"
381 60 my ( $month, $day, $hour, $minute, $second, $year )
382 = $text =~ /\bon \w{3} (\w{3})\s+([0-9]+) ([0-9]+):([0-9]+):([0-9]+) ([0-9]{4})\z/;
383 60 ▶ next if !defined($year) || !defined( $MONTHS{$month} );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $year and defined $Monitoring::Sneck::Checks::zfs::MONTHS{$month} 0 60 60
Condition33%1/3
defined $year and defined $Monitoring::Sneck::Checks::zfs::MONTHS{$month}
!ll&&!rl&&r
0060
MC/DC0%0/2
defined $year and defined $Monitoring::Sneck::Checks::zfs::MONTHS{$month}
defined $year defined $Monitoring::Sneck::Checks::zfs::MONTHS{$month}
Truth table33%1/3
A and B
A= defined $yearB= defined $Monitoring::Sneck::Checks::zfs::MONTHS{$month}
ABresult
0X0
100
111
384 $pool->{scan}
385 60 = { verb => $verb, finished => timelocal( $second, $minute, $hour, $day, $MONTHS{$month}, $year ) };
386 } ## end foreach my $pool ( values(%pools) )
387  
388 80 return \%pools;
389 } ## end sub _parse_status
390  
391 21 1;
« blib/lib/Monitoring/Sneck/Checks/auditd.pm ↑ Summary blib/lib/Monitoring/Sneck/Checks/vrrp.pm »