Parse-NetApp-ASUP
view release on metacpan or search on metacpan
lib/Parse/NetApp/ASUP.pm view on Meta::CPAN
if ( $line =~ /Volume.*State.*Status.*Options/ ) { # header row
$header_count++;
next;
}
last if $header_count > 1;
if ( scalar(@chunk) > 0 and $line =~ /^\s*([\w\-]+)\s+(online|offline)\s+(.+?)\s\s\s+(.+)$/ ) {
push @next_chunk, $line;
my ( $volname, $volopts ) = Parse::NetApp::ASUP::_parse_volstatus_block(@chunk);
$vols{$volname} = $volopts;
@chunk = @next_chunk;
@next_chunk = ();
} else {
push @chunk, $line;
}
}
if (@chunk) {
my ( $volname, $volinfo ) = Parse::NetApp::ASUP::_parse_volstatus_block(@chunk);
$vols{$volname} = $volinfo;
}
return wantarray ? %vols : \%vols;
}
sub _parse_volstatus_block {
my @lines = @_;
my %volinfo;
my ( $volname, $volstate, $voloptions, $volstatus, $volaggr ) = ('','','','','');
for my $line (@lines) {
# v7 unused
next if $line =~ /Plex \//;
next if $line =~ /RAID group/;
next if $line =~ /Snapshot autodelete settings/;
next if $line =~ /Volume autosize settings/;
# v8
next if $line =~ /Volume UUID: /;
next if $line =~ /Volinfo mode: /;
next if $line =~ /Volume has clones: /;
next if $line =~ /Clone, backed by volume '/;
if ( $line =~ /^\s*([\w\-]+)\s+(online|offline|restricted)\s+(.+?)\s\s\s+(.+)$/ ) {
$volname = $1;
$volstate = $2;
$volstatus = $3;
$voloptions = $4;
} elsif ( $line =~ /^(\s{27,30}\s*|\t{5})(\S+)\s\s\s+(\S.+)$/ ) { # v7 and earlier
$volstatus .= ', ' . $2;
$voloptions .= $3;
} elsif ( $line =~ /^(\s{27,30}\s*|\t{5})(.*)$/ ) { # v7 and earlier
$voloptions .= $2;
} elsif ( $line =~ /^\s*(\w+=[\w\(\)]+,?)$/ ) { # v8
$voloptions .= $1;
} elsif ( $line =~ /^vol status: Volume '(.*?)' is temporarily busy \(snapmirror destination\)/ ) {
$volname = $1;
$volstate = 'busy';
} elsif ( $line =~ /Containing aggregate: ('[\w\-]+'|<N\/A>)/ ) {
$volaggr = $1;
$volaggr = $1 if $volaggr =~ /^'(.+)'$/;
} else {
Carp::croak "Bad Vol Status Line: [$line]\n";
}
}
$volinfo{state} = $volstate;
$volinfo{status} = $volstatus;
$volinfo{options} = $voloptions;
$volinfo{aggregate} = $volaggr;
$volinfo{notes} = '';
$volinfo{notes} = 'Volume is offline' if $volstate eq 'offline';
$volinfo{notes} = 'Volume is busy' if $volstate eq 'busy';
push(@Parse::NetApp::ASUP::concerns, "$volname is marked as $volstate") if $volstate eq 'offline' or $volstate eq 'busy';
return ( $volname, \%volinfo );
}
=head3 parse_xheader()
=cut
sub parse_xheader {
my %xheader = ();
return ( wantarray ? %xheader : \%xheader ) unless defined $_[0];
my @lines = split "\n", $_[0];
shift @lines if $lines[0] eq '===== X-HEADER DATA =====';
for my $line (@lines) {
next if $line =~ /^\s*$/;
if ( $line =~ /^([\w\-]+): (.*)$/ ) {
$xheader{$1} = $2;
} else {
Carp::croak "Bad x-header line: [$line]";
}
}
return wantarray ? %xheader : \%xheader;
}
=head1 EXTRACT METHODS:
=head3 extract_acp_list_all()
=cut
sub extract_acp_list_all {
my $raw = defined $_[0]->{asup} ? $_[0]->{asup} : $_[0];
my $trim = '';
if ( $raw =~ /(===== ACP LIST ALL =====.*?)=====/s ) {
$trim = $1;
while ( $trim !~ /\n\n$/s ) { $trim .= "\n"; }
}
undef($raw);
return $trim;
}
=head3 extract_aggr_status()
=cut
sub extract_aggr_status {
my $raw = defined $_[0]->{asup} ? $_[0]->{asup} : $_[0];
my $trim = '';
if ( $raw =~ /(===== AGGR-STATUS =====.*?)=====/s ) {
$trim = $1;
while ( $trim !~ /\n\n$/s ) { $trim .= "\n"; }
}
undef($raw);
return $trim;
}
=head3 extract_cf_monitor()
( run in 0.903 second using v1.01-cache-2.11-cpan-39bf76dae61 )