File Coverage

blib/lib/Device/RAID/Poller/Backends/FBSD_graid3.pm
Criterion Covered Total %
statement 8 58 13.7
branch 0 24 0.0
condition 0 3 0.0
subroutine 3 6 50.0
pod 3 3 100.0
total 14 94 14.8


line stmt bran cond sub pod time code
1              
2             package Device::RAID::Poller::Backends::FBSD_graid3;
3              
4 1     1   65362 use 5.006;
  1         13  
5 1     1   7 use strict;
  1         2  
  1         20  
6 1     1   5 use warnings;
  1         2  
  1         601  
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             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             sub new {
47 0     0 1   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             sub run {
68 0     0 1   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 0         if ( ! $self->{usable} ){
77 0           return %return_hash;
78             }
79              
80             # Fetch the raw gmirror status.
81 0           my $raw=`/sbin/graid3 status`;
82 0 0         if ( $? != 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 0         if ( $line_split[0] =~ /^mirror/ ){
97 0           $dev=$line_split[0];
98              
99             #create the device if needed in the return hash
100 0 0         if ( ! defined( $return_hash{$dev} ) ){
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 0         if ( $line_split[1] eq 'COMPLETE' ){
    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 0         if ( $line_split[3] eq "(SYNCHRONIZING)" ){
    0          
124 0           $return_hash{devices}{$dev}{status}='rebuilding';
125 0           push( @{ $return_hash{devices}{$dev}{good} }, $line_split[2] );
  0            
126             }elsif( $line_split[3] eq "(ACTIVE)" ){
127 0           push( @{ $return_hash{devices}{$dev}{good} }, $line_split[2] );
  0            
128             }else{
129 0           push( @{ $return_hash{devices}{$dev}{bad} }, $line_split[2] );
  0            
130             }
131              
132             }else{
133             # Check known disk status values.
134             # Values pulled from sys/geom/mirror/g_mirror.c
135 0 0         if ( $line_split[2] eq "(SYNCHRONIZING)" ){
    0          
136 0           $return_hash{$dev}{status}='rebuilding';
137 0           push( @{ $return_hash{devices}{$dev}{good} }, $line_split[1] );
  0            
138             }elsif( $line_split[2] eq "(ACTIVE)" ){
139 0           push( @{ $return_hash{devices}{$dev}{good} }, $line_split[1] );
  0            
140             }else{
141 0           push( @{ $return_hash{devices}{$dev}{bad} }, $line_split[1] );
  0            
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             sub usable {
163 0     0 1   my $self=$_[0];
164              
165 0 0 0       if (
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 0         if ( $? != 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<< >>
188              
189             =head1 BUGS
190              
191             Please report any bugs or feature requests to C, or through
192             the web interface at L. 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
212              
213             =item * AnnoCPAN: Annotated CPAN documentation
214              
215             L
216              
217             =item * CPAN Ratings
218              
219             L
220              
221             =item * Search CPAN
222              
223             L
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; # End of Device::RAID::Poller