Veritas-bu

[Veritas-bu] New available media script

2005-02-25 05:56:04
Subject: [Veritas-bu] New available media script
From: richard_hellier AT hotmail DOT com (Richard Hellier)
Date: Fri, 25 Feb 2005 10:56:04 -0000
This is a multi-part message in MIME format.

------=_NextPart_000_00BB_01C51B28.99CF7940
Content-Type: text/plain;
        charset="US-ASCII"
Content-Transfer-Encoding: 7bit



-----Original Message-----
From: veritas-bu-admin AT mailman.eng.auburn DOT edu
[mailto:veritas-bu-admin AT mailman.eng.auburn DOT edu] On Behalf Of Jerry
Sent: 24 February 2005 20:13
To: veritas-bu AT mailman.eng.auburn DOT edu
Subject: [Veritas-bu] New available media script

Someone a while ago posted a new available_media
script (perl) that works great and is fast.  I
upgraded to 5.0MP4 and I notice it's spitting an error
out.  I notice it's erroring on an option to
bpmedialist, but it seems to work other than that
error. (not sure if I'm missing info though).

Dale, you out there?
We should all get together and open a sourceforge
project for stuff like this so we can check things in
and out of cvs and collaborate.

----------------------------

Jerry,
        If I'm the "someone" (my script is at the end of the msg), by all
means let me know what bpmedialist is bleating about and I'll take a look.
I don't have a 5.x installation (only 3.4 and 4.5) to test on, so I'd need
someone's help.

Cheers,

Richard.


------=_NextPart_000_00BB_01C51B28.99CF7940
Content-Type: application/octet-stream;
        name="am.pl"
Content-Transfer-Encoding: quoted-printable
Content-Disposition: attachment;
        filename="am.pl"

#! /lsi/soft/CFR/bin/perl -wT=0A=
=0A=
############################################################=0A=
#=0A=
#       Filename:               am.pl=0A=
#=0A=
#       Version:                1.1=0A=
#=0A=
#       Date-Last-Modified:     06/16/04=0A=
#=0A=
#       Purpose:                This script is a re-write=0A=
#                               of the Veritas NetBackup=0A=
#                               "goodies" item "available_media"=0A=
#=0A=
#       Author:                 Richard Hellier <rlh AT lsil DOT com>=0A=
#=0A=
############################################################=0A=
=0A=
############################################################=0A=
################### Pragmas, Includes etc ##################=0A=
############################################################=0A=
=0A=
use strict;=0A=
=0A=
############################################################=0A=
################### Global Data ############################=0A=
############################################################=0A=
=0A=
use constant DEBUG      =3D> 0;=0A=
use constant VMPOOL     =3D> '/usr/openv/volmgr/bin/vmpool -listall |';=0A=
use constant VMQUERY    =3D> '/usr/openv/volmgr/bin/vmquery -pn ';=0A=
use constant BPMLIST    =3D> '/usr/openv/netbackup/bin/admincmd/bpmedialist =
-mlist -l |';=0A=
=0A=
############################################################=0A=
################### Function Definitions Begin Here ########=0A=
############################################################=0A=
=0A=
sub dumpVar ($$$) {=0A=
        my ($sep, $depth, $value) =3D @_; return unless $value;=0A=
#=0A=
#       Step 1) Is this is a scalar or compound type?=0A=
#=0A=
        my $valueType =3D ref($value);=0A=
        if (!$valueType) {=0A=
#=0A=
#               Step 1a) Scalar value -- just print it=0A=
#=0A=
                print $sep x $depth, "$value ";=0A=
        } else {=0A=
#=0A=
#               Step 1b) Compound value -- print the opening delimiter=0A=
#                        followed by the values followed by the closer=0A=
#=0A=
                print $sep x $depth;=0A=
                &{{=0A=
                 SCALAR =3D> sub { print "\\", $$value; },=0A=
                 ARRAY  =3D> sub { print "["; foreach my $v (@{$value}) { =
dumpVar($sep, 1+$depth, $v); print ", " } ; print "]";},=0A=
                 HASH   =3D> sub { print "{\n";=0A=
                                 foreach my $key (keys %{$value}) {=0A=
                                        print $sep x $depth, $key, " =3D> ";=0A=
                                         dumpVar($sep, 1+$depth, 
$$value{$key}|| 'NULL');=0A=
                                         print ",\n";=0A=
                                 }=0A=
                                 print $sep x $depth, "}"},=0A=
                 CODE   =3D> sub { print "\\CODE" },=0A=
                 REF    =3D> sub { print "\\"; dumpVar($sep, $depth, =
$$value); },=0A=
                 GLOB   =3D> sub { print "GLOB" },=0A=
                 LVALUE =3D> sub { print "LVALUE" },=0A=
                 }->{$valueType} || sub {print "UNKNOWN"}};=0A=
        }=0A=
=0A=
        print "\n" unless $depth;=0A=
}=0A=
=0A=
sub decode_status ($$) {=0A=
        my ($bpstat, $bpretlev) =3D @_;=0A=
=0A=
        my @status_terms;=0A=
=0A=
        my @decode_tab =3D (=0A=
        [ 128,  sub ($$) { my ($v,$bit) =3D @_; return 'IMPORTED' if ($v & 
$bit) =
} ],=0A=
        [  64,  sub ($$) { my ($v,$bit) =3D @_; return unless ($v & $bit); =
++$::asterisk_displayed; $bpretlev .=3D '*'} ],=0A=
        [   8,  sub ($$) { my ($v,$bit) =3D @_; return 'FULL' if ($v & $bit) } 
],=0A=
        [   2,  sub ($$) { my ($v,$bit) =3D @_; return 'SUSPENDED' if ($v & =
$bit) } ],=0A=
        [   1,  sub ($$) { my ($v,$bit) =3D @_; return 'FROZEN' if ($v & $bit) 
} =
],=0A=
        [ 512,  sub ($$) { my ($v,$bit) =3D @_; return 'MPX' if ($v & $bit) } 
],=0A=
        );=0A=
=0A=
        foreach my $dt (@decode_tab) {=0A=
                my ($bit, $func) =3D @$dt;=0A=
=0A=
                my $this_term =3D $func->($bpstat, $bit);=0A=
=0A=
                $status_terms[0] =3D 'ACTIVE' if ($bit =3D=3D 512 and 
!@status_terms); =
#YUK!!!=0A=
=0A=
                push @status_terms, $this_term if ($this_term);=0A=
        }=0A=
=0A=
        return (join('/', @status_terms), $bpretlev);=0A=
}=0A=
=0A=
sub read_ldif ($) {=0A=
#=0A=
#       Step 1) Grab the "command" argument=0A=
#=0A=
        my $cmd =3D shift;=0A=
#=0A=
#       Step 2) Open a pipe to the nominated command=0A=
#               and grab the output=0A=
#=0A=
        die "Cannot run the command $cmd" unless (open(X,  $cmd));=0A=
=0A=
        my $file_contents =3D do { local $/ =3D undef; <X> };=0A=
        close(X);=0A=
=0A=
        $file_contents =3D~ s/^=3D+\n//; $file_contents =3D~ s/=3D+\n$//;=0A=
=0A=
        my @results;=0A=
        foreach my $p (split(/\n=3D+\n/, $file_contents)) {=0A=
                my %hr =3D ();=0A=
=0A=
                while ($p =3D~ m/([ \w]+):\s+(.*)$/mg) {=0A=
                        $hr{$1} =3D $2;=0A=
                }=0A=
=0A=
                push @results, \%hr;=0A=
        }=0A=
=0A=
        DEBUG && dumpVar(' ', 0, \@results);=0A=
=0A=
        return @results;=0A=
}=0A=
=0A=
sub emit_volume ($$$$) {=0A=
        my ($volume, @extras) =3D @_;=0A=
=0A=
        my @volume_fields =3D (=0A=
        [ 'media ID',           undef ],=0A=
        [ 'media type',         sub ($) { my $v =3D shift; $v =3D~ s/\s.*//; 
return =
$v} ],=0A=
        [ 'robot type',         sub ($) { my $v =3D shift; $v =3D~ s/\s.*//; 
return =
$v} ],=0A=
        [ 'robot number',       undef ],=0A=
        [ 'robot slot',         undef ],=0A=
        [ 'vside',              undef ],=0A=
        );=0A=
=0A=
        my @format_fields;=0A=
=0A=
        foreach my $vf (@volume_fields) {=0A=
                my ($field_name, $field_fixup) =3D @$vf;=0A=
=0A=
                my $value =3D defined($volume->{$field_name}) ? 
$volume->{$field_name} =
: '-';=0A=
=0A=
                $value =3D $field_fixup->($value) if ($field_fixup);=0A=
=0A=
                push @format_fields, $value;=0A=
        }=0A=
=0A=
        push @format_fields, @extras;=0A=
=0A=
format STDOUT =3D=0A=
@<<<<<  @<<<<<< @<<<<<< @<<<<<< @<<<<<< @<<<<<< @<<<<< @>>>>>>>> =
@<<<<<<<<<<<=0A=
@format_fields=0A=
=0A=
=0A=
        write;=0A=
}=0A=
=0A=
sub get_media_list () {=0A=
        return unless (open(BPML, BPMLIST));=0A=
=0A=
        my %bpml_hash;=0A=
=0A=
        while (<BPML>) {=0A=
                my @fields =3D split;=0A=
=0A=
                $bpml_hash{$fields[0]} =3D [ $fields[11], $fields[8], 
$fields[14] ];=0A=
        }=0A=
        close(BPML);=0A=
=0A=
        DEBUG && dumpVar(' ', 0, \%bpml_hash);=0A=
=0A=
        return \%bpml_hash;=0A=
}=0A=
=0A=
sub show_available_media () {=0A=
#=0A=
#       Step 1) Emit the report header=0A=
#=0A=
print <<'EEEOOOFFF';=0A=
media   media   robot   robot   robot   side/   ret    size      status=0A=
 ID     type    type      #     slot    face    level  KBytes=0A=
-------------------------------------------------------------------------=
---=0A=
EEEOOOFFF=0A=
#=0A=
#       Step 2) Build the cache of bpmedialist entries (much=0A=
#               faster to grab 'em all and then just pick=0A=
#               out the ones we need=0A=
#=0A=
        my $bp_media_list =3D get_media_list();=0A=
#=0A=
#       Step 3) Loop through the list of volume pools ...=0A=
#=0A=
        foreach my $p (sort { $a->{'pool name'} cmp $b->{'pool name'} } =
&read_ldif(VMPOOL)) {=0A=
                my ($poolname) =3D $p->{'pool name'};=0A=
=0A=
                print $poolname, " pool\n";=0A=
#=0A=
#               Step 1a) Now find the media in this pool=0A=
#=0A=
                my $blank_line =3D "\n";=0A=
=0A=
                open(VMQ, VMQUERY . $poolname . ' -bx | tail +4 | sort|');=0A=
                while (my $vmq_line =3D <VMQ>) {=0A=
                        chomp($vmq_line);=0A=
=0A=
                        print $blank_line; $blank_line =3D '';=0A=
=0A=
                        my @v_fields =3D split(/\s+/, $vmq_line);=0A=
=0A=
                        DEBUG && dumpVar(' ', 0, \@v_fields);=0A=
=0A=
                        my @vmq_field_map =3D (=0A=
                                [ 'media ID',            0 ],=0A=
                                [ 'media type',          1 ],=0A=
                                [ 'robot type',          2 ],=0A=
                                [ 'robot number',        3 ],=0A=
                                [ 'robot slot',          4 ],=0A=
                                [ 'vside',               5 ],=0A=
                                [ 'asgndate',           11 ],=0A=
                                [ 'asgntime',           12 ],=0A=
                        );=0A=
=0A=
                        my $v;=0A=
                        $v->{$_->[0]} =3D $v_fields[$_->[1]] for 
@vmq_field_map;=0A=
=0A=
                        my $media_id =3D $v->{'media ID'};=0A=
=0A=
                        my ($bpkbytes, $bpretlev, $bpstat);=0A=
=0A=
                        if ($v->{asgndate} eq '---' && $v->{asgntime} eq '---') 
{=0A=
                                $bpretlev =3D '-';=0A=
                                $bpkbytes =3D '-';=0A=
                                $bpstat =3D 'AVAILABLE';=0A=
                        } else {=0A=
=0A=
                                if (exists($bp_media_list->{$media_id})) {=0A=
                                        ($bpretlev, $bpkbytes, $bpstat) =3D 
@{$bp_media_list->{$media_id}};=0A=
                                        ($bpstat, $bpretlev) =3D 
decode_status($bpstat, $bpretlev),=0A=
                                } else {=0A=
                                        ($bpretlev, $bpkbytes, $bpstat) =3D 
('-', '-', 'DBBACKUP');=0A=
                                }=0A=
                        }=0A=
=0A=
                        emit_volume(=0A=
                                $v,=0A=
                                $bpretlev,=0A=
                                $bpkbytes,=0A=
                                $bpstat,=0A=
                        );=0A=
                }=0A=
                close(VMQ);=0A=
=0A=
                print "\n";=0A=
        }=0A=
}=0A=
=0A=
END {=0A=
        if ($::asterisk_displayed) {=0A=
                print <<'EEEOOOFFF';=0A=
=0A=
* - More than 1 retention level present.=0A=
=0A=
EEEOOOFFF=0A=
        }=0A=
}=0A=
=0A=
############################################################=0A=
################### Execution Begins Here ##################=0A=
############################################################=0A=
=0A=
$ENV{PATH} =3D =
'/usr/openv/volmgr/bin;/usr/openv/netbackup/bin/admincmd:/usr/bin';=0A=
=0A=
++$|;=0A=
=0A=
show_available_media();=0A=
=0A=
__END__=0A=

------=_NextPart_000_00BB_01C51B28.99CF7940--