Poller/Backends/FBSD_graid3.pm

filter: Statementstmt 16.6% 10 / 60 Branchbran 0.0% 0 / 24 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 50.0% 3 / 6 Podpod 100% 3 / 3 totaltotal 16.3% 16 / 98 CC 15 SCAR 45.8
CC
15
Cov
11%
run
156.0
usable
20.0
new
2.0
CRAP 97.8
« Poller/Backends/FBSD_gmirror.pm ↑ Summary Poller.pm »
1  
2 package Device::RAID::Poller::Backends::FBSD_graid3;
3  
4 1 ▶use 5.006;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 =head1 NAME
9  
10 Device::RAID::Poller::Backends::FBSD_graid3 - FreeBSD GEOM RAID3 backend.
11  
12 =head1 VERSION
13  
14 Version 0.0.0
15  
16 =cut
17  
18 1 our $VERSION = '0.0.0';
19  
20  
21 =head1 SYNOPSIS
22  
23 use Device::RAID::Poller::Backends::FBSD_graid3;
24
25 my $backend = Device::RAID::Poller::Backends::FBSD_graid3->new;
26
27 my $usable=$backend->usable;
28 my %return_hash;
29 if ( $usable ){
30 %return_hash=$backend->run;
31 my %status=$backend->run;
32 use Data::Dumper;
33 print Dumper( \%status );
34 }
35  
36 =head1 METHODS
37  
38 =head2 new
39  
40 Initiates the backend object.
41  
42 my $backend = Device::RAID::Poller::Backends::FBSD_graid3->new;
43  
44 =cut
45  
46 0 ▶sub new {
Subroutine new: not called CC=1 SCAR=6.9
Pod documented
47 0 my $self = {
48 usable=>0,
49 };
50 0 bless $self;
51  
52 0 return $self;
53 }
54  
55 =head2 run
56  
57 Runs the poller backend and report the results.
58  
59 If nothing is nothing is loaded, load will be called.
60  
61 my %status=$backend->run;
62 use Data::Dumper;
63 print Dumper( \%status );
64  
65 =cut
66  
67 0 ▶sub run {
Subroutine run: not called CC=12 SCAR=50.5
Pod documented
68 0 my $self=$_[0];
69  
70 0 my %return_hash=(
71 'status'=>0,
72 'devices'=>{},
73 );
74  
75 # if not usable, no point in continuing
76 0 ▶ if ( ! $self->{usable} ){
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{"usable"}) 0 0 0
77 0 return %return_hash;
78 }
79  
80 # Fetch the raw gmirror status.
81 0 my $raw=`/sbin/graid3 status`;
82 0 ▶ if ( $? != 0 ){
Branch: 1 branch
BranchTrueFalseTotal
if ($? != 0) 0 0 0
83 0 return %return_hash;
84 }
85  
86 0 my @raw_split=split( /\n/, $raw );
87  
88 # The first line contains nothing of interest.
89 0 shift @raw_split;
90  
91 0 my $dev=undef;
92 0 foreach my $line (@raw_split){
93 0 my @line_split=split( /[\t ]+/, $line );
94  
95 # lines starting with mirror mean we have a new dev
96 0 ▶ if ( $line_split[0] =~ /^mirror/ ){
Branch: 1 branch
BranchTrueFalseTotal
if ($line_split[0] =~ /^mirror/) { } 0 0 0
97 0 $dev=$line_split[0];
98  
99 #create the device if needed in the return hash
100 0 ▶ if ( ! defined( $return_hash{$dev} ) ){
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $return_hash{$dev}) 0 0 0
101 0 $return_hash{devices}{$dev}={
102 'backend'=>'FBSD_graid3',
103 'name'=>$dev,
104 'good'=>[],
105 'bad'=>[],
106 'spare'=>[],
107 'type'=>'raid3',
108 'BBUstatus'=>'na',
109 'status'=>'unknown',
110 };
111 }
112  
113 # Check known mirror status values.
114 # Values pulled from sys/geom/mirror/g_mirror.c
115 0 ▶ if ( $line_split[1] eq 'COMPLETE' ){
Branch: 2 branches
BranchTrueFalseTotal
if ($line_split[1] eq 'COMPLETE') { } 0 0 0
elsif ($line_split[1] eq 'DEGRADED') { } 0 0 0
116 0 $return_hash{devices}{$dev}{status}='good';
117 }elsif( $line_split[1] eq "DEGRADED" ){
118 0 $return_hash{devices}{$dev}{status}='bad';
119 }
120  
121 # Check known disk status values.
122 # Values pulled from sys/geom/mirror/g_mirror.c
123 0 ▶ if ( $line_split[3] eq "(SYNCHRONIZING)" ){
Branch: 2 branches
BranchTrueFalseTotal
if ($line_split[3] eq '(SYNCHRONIZING)') { } 0 0 0
elsif ($line_split[3] eq '(ACTIVE)') { } 0 0 0
124 0 $return_hash{devices}{$dev}{status}='rebuilding';
125 0 push( @{ $return_hash{devices}{$dev}{good} }, $line_split[2] );
126 }elsif( $line_split[3] eq "(ACTIVE)" ){
127 0 push( @{ $return_hash{devices}{$dev}{good} }, $line_split[2] );
128 }else{
129 0 push( @{ $return_hash{devices}{$dev}{bad} }, $line_split[2] );
130 }
131  
132 }else{
133 # Check known disk status values.
134 # Values pulled from sys/geom/mirror/g_mirror.c
135 0 ▶ if ( $line_split[2] eq "(SYNCHRONIZING)" ){
Branch: 2 branches
BranchTrueFalseTotal
if ($line_split[2] eq '(SYNCHRONIZING)') { } 0 0 0
elsif ($line_split[2] eq '(ACTIVE)') { } 0 0 0
136 0 $return_hash{$dev}{status}='rebuilding';
137 0 push( @{ $return_hash{devices}{$dev}{good} }, $line_split[1] );
138 }elsif( $line_split[2] eq "(ACTIVE)" ){
139 0 push( @{ $return_hash{devices}{$dev}{good} }, $line_split[1] );
140 }else{
141 0 push( @{ $return_hash{devices}{$dev}{bad} }, $line_split[1] );
142 }
143 }
144 }
145  
146 0 $return_hash{status}=1;
147  
148 0 return %return_hash;
149 }
150  
151 =head2 usable
152  
153 Returns a perl boolean for if it is usable or not.
154  
155 my $usable=$backend->usable;
156 if ( ! $usable ){
157 print "This backend is not usable.\n";
158 }
159  
160 =cut
161  
162 0 ▶sub usable {
Subroutine usable: not called CC=4 SCAR=30.0
Pod documented
163 0 my $self=$_[0];
164  
165 0 ▶ if (
Branch: 1 branch
BranchTrueFalseTotal
unless ($^O =~ /freebsd/ or -x "/sbin/graid3") 0 0 0
Condition0%0/3
$^O =~ /freebsd/ or -x "/sbin/graid3"
l!l&&r!l&&!r
000
MC/DC0%0/2
$^O =~ /freebsd/ or -x "/sbin/graid3"
$^O =~ /freebsd/ -x "/sbin/graid3"
Truth table0%0/3
A or B
A= $^O =~ /freebsd/B= -x "/sbin/graid3"
ABresult
1X1
011
000
166 ( $^O !~ 'freebsd' ) &&
167 ( ! -x '/sbin/graid3' )
168 ){
169 0 $self->{usable}=0;
170 0 return 0;
171 }
172  
173 # Test for it this way as '/sbin/kldstat -q -n geom_raid3' will error
174 # if it is compiled in.
175 0 system('/sbin/sysctl -q kern.features.geom_raid3 > /dev/null');
176 0 ▶ if ( $? != 0 ){
Branch: 1 branch
BranchTrueFalseTotal
if ($? != 0) 0 0 0
177 0 $self->{usable}=0;
178 0 return 0;
179 }
180  
181 0 $self->{usable}=1;
182 0 return 1;
183 }
184  
185 =head1 AUTHOR
186  
187 Zane C. Bowers-Hadley, C<< <vvelox at vvelox.net> >>
188  
189 =head1 BUGS
190  
191 Please report any bugs or feature requests to C<bug-device-raid-poller at rt.cpan.org>, or through
192 the web interface at L<https://rt.cpan.org/NoAuth/ReportBug.html?Queue=Device-RAID-Poller>. I will be
193 notified, and then you'll automatically be notified of progress on your bug as I make changes.
194  
195  
196  
197  
198 =head1 SUPPORT
199  
200 You can find documentation for this module with the perldoc command.
201  
202 perldoc Device::RAID::Poller
203  
204  
205 You can also look for information at:
206  
207 =over 4
208  
209 =item * RT: CPAN's request tracker (report bugs here)
210  
211 L<https://rt.cpan.org/NoAuth/Bugs.html?Dist=Device-RAID-Poller>
212  
213 =item * AnnoCPAN: Annotated CPAN documentation
214  
215 L<http://annocpan.org/dist/Device-RAID-Poller>
216  
217 =item * CPAN Ratings
218  
219 L<https://cpanratings.perl.org/d/Device-RAID-Poller>
220  
221 =item * Search CPAN
222  
223 L<https://metacpan.org/release/Device-RAID-Poller>
224  
225 =back
226  
227  
228 =head1 ACKNOWLEDGEMENTS
229  
230  
231 =head1 LICENSE AND COPYRIGHT
232  
233 This software is Copyright (c) 2019 by Zane C. Bowers-Hadley.
234  
235 This is free software, licensed under:
236  
237 The Artistic License 2.0 (GPL Compatible)
238  
239  
240 =cut
241  
242 1 1; # End of Device::RAID::Poller
« Poller/Backends/FBSD_gmirror.pm ↑ Summary Poller.pm »