#!/usr/local/bin/perl5
############################################################################
# Script : query_tape
#
# Obtain various media reports for tapes located within the robot
#
# Call format:
#
#query_tape [parameter]
#
#where [parameter] is an optional parameter that can take the next values:
#
#volume: List of all the volumes known to ADSM and/or the robot
# (like what was provided in the previous version of the report).
#storage: give the count of the tapes found in each storage pool.
#scratch: give the number of tapes seen by the ADSM servers as scratch.
#empty: give the number of tapes seen by the ADSM servers as private and
empty.
#full: give a compilation of all the previous reports.
#
# If no parameter is passed to this script, a prompt will be send out to
# STDERR, asking for the type of report which is desired.
#
# For each report type a subroutine is called
#
# Written by: F. Dequenne (ECMWF) on 12 nov 95
# MOD: FD 17 Jan 96: Improve the inline doc.
#
# MOD: G Walker - 10 May 1996: Add reporting of scratch tapes, empty tapes
#
# MOD: FD 13 Nov 96: V2.0 display more info related to the tapes.
############################################################################
#
# The next variables are site dependant. In principle, these are the only
# statement that would need to be changed.
#
$admin_id="???????"; # Name and password of an admin user
$admin_pass="?????????"; # that exists on all servers that will be
# checked.
#
@server_list=("server1","server2","server3");
# #list of all servers that will be checked.
#
@robot_list=("/dev/lmcp0"); # list of the robots from which we want to
# get the info.
#
# End of site dependant info.
##############################################################################
#
@report_list=("volume","storage","scratch","empty","full");
# if no command line input given ask user for report type
if ($ARGV[0] eq "")
{
# Ask user for type of report required.
print STDERR "\nSelect Report Required\n";
print STDERR "1. Volume\n";
print STDERR "2. Storage Pool\n";
print STDERR "3. Scratch tapes per Storage Pool\n";
print STDERR "4. Empty tapes per Storage Pool\n";
print STDERR "5. Full compilation of above reports\n\n";
print STDERR "Please enter 1,2,3,4 or 5\n";
$report=<STDIN>; chop $report;
if ($report !~ /^[12345]/)
{die "Invalid Report Selected - Enter either 1,2,3,4 or
5\n";}
$report=$report_list[$report-1];
}
else
{
$report=$ARGV[0];
$report=lc $report;
if (index(join(" ",@report_list),$report)<0)
{
die "Invalid parameter $ARGV[0]\n";
}
};
print STDERR "\nReport requested=$report\n\n";
#
# Get the information
# First from the robots.
foreach $robot (@robot_list)
{
open (ROBOT,"mtlib -l $robot -qI|");
while ($_=<ROBOT>)
{
chop;
if (/\s*(\w{6}) (\w{4}) \w\w \w\w \w\w/)
{
$tape_defined{$1}=1;
$robot_cat_hex{$1}=$2;
};
}
close ROBOT;
};
# Now get data from the servers.
foreach $server (@server_list)
{
# let's first get the lib vol info.
$server_reachable{$server}=1;
open (SERVER,"yes|dsmadmc -server=$server -id=$admin_id
-password=$admin_pass q libv 2>&1 |");
while ($_=<SERVER>)
{
chop;
if (/ANS510[012]/ ||/ANS5519/|| /Rights/ || /Library Name/ ||
/------/|| /Highest/)
{#these are rubbish lines that we just skip.
next;
}
elsif (/(\w+)\s+(\w{6})\s+(\w*)\s*(\w*)/)
{
print STDERR "WARNING >>> $2 is defined in two
libraries, on $lib_server{$2} and $server\n"
if defined($library{$2});
$tape_defined{$2}=1;
$library{$2}=$1;
$lib_status{$2}=$3;
$lib_use{$2}=$4;
$lib_server{$2}=$server;
}
elsif (/ANS5658E TCP\/IP failure/)
{$server_reachable{$server}=0;}
};
close SERVER;
if ($server_reachable{$server})
{ # let's get the volumes info
open (SERVER,"yes|dsmadmc -server=$server -id=$admin_id
-password=$admin_pass q v f=d |");
while ($_=<SERVER>)
{
chop;
if (/ANS5658E TCP\/IP failure/)
{$server_reachable{$server}=0;}
elsif (/Highest/||/ANS510[012]/)
{ next;}
elsif (/Volume Name: (\S+)\s*$/)
{$volname=$1;}
elsif (/Storage Pool Name: (\S+)\s*$/)
{$stgpoolname=$1;}
elsif (/Device Class Name: (\S+)\s*$/)
{$devclname=$1;}
elsif (/Estimated Capacity \(MB\): (\S+)\s*$/)
{$devcap=$1;}
elsif (/\%Util: (\S+)\s*$/)
{$pctutil=$1;}
elsif (/Volume Status: (\S+)\s*$/)
{$volstatus=$1;}
elsif (/Access: (\S+)\s*$/)
{$volaccess=$1;}
elsif (/Pct. Reclaimable Space: (\S+)\s*$/)
{$pctreclaim=$1;}
elsif (/Scratch Volume\?: (\S+)\s*$/)
{$scratchvol=$1;}
elsif (/In Error State\?: (\S+)\s*$/)
{$volinerror=$1;}
elsif (/Last Update Date/)
{#time to fill our permanent arrays.
next if ($devclname eq "DISK");
print STDERR "WARNING >>> $1 is defined in two
servers: on $vol_server{$1} and $server\n"
if defined($vol_server{$volname});
$tape_defined{$volname}=1;
$vol_server{$volname}=$server;
$vol_pool{$volname}=$stgpoolname;
undef $stgpoolname;
$vol_devc{$volname}=$devclname;
undef $devclname;
$vol_full{$volname}=$pctutil;
undef $pctutil;
$vol_status{$volname}=$volstatus;
undef $volstatus;
$vol_access{$volname}=$volaccess;
undef $volaccess;
$vol_in_error{$volname}=$volinerror;
undef $volinerror;
$vol_reclaim{$volname}=$pctreclaim;
undef $volinerror;
}
};
close SERVER;
};
};
# We are now on the fringe of producing a report.
# First, let's define the formats to be used.
format STDOUT_TOP_volume =
ADSM Tape Allocation report
@#-@#-@# @#:@#:@# Page @>>
$year,$month+1,$day,$hour,$min,$sec,$%
Tape Server Library Stg Pool Dev Class %Util %recl Vol stat Lib sta
Last use Cat Tape Acces Err
------ -------- ---------- ----------- ---------- ----- ----- -------- -------
--------- ---- ------ ----------- ---
.
.
format STDOUT_volume =
@<<<<< @<<<<<<< @<<<<<<<<< @<<<<<<<<<< @<<<<<<<<< @##.# @##.# @<<<<<<< @<<<<<<
@<<<<<<<< @<<< @<<<<< @<<<<<<<<<< @<<
$key,$server,$library{$key},$vol_pool{$key},$vol_devc{$key},$vol_full{$key},$vol_reclaim{$key},$vol_status{$key},$lib_status{$key},$lib_use{$key},$robot_cat_hex{$key},$key,$vol_access{$key},$vol_in_error{$key}
.
format STDOUT_TOP_storage =
ADSM Tape Allocation report
@#-@#-@# @#:@#:@# Page @>>
$year,$month+1,$day,$hour,$min,$sec,$%
Server Stg Pool Tapes defined
-------- ----------- -------------
.
.
format STDOUT_storage =
@<<<<<<< @<<<<<<<<<< @>>>>
$server, $pool, $stg_ctr{$poolkey}
.
format STDOUT_TOP_scratch =
ADSM Tape Allocation report
@#-@#-@# @#:@#:@# Page @>>
$year,$month+1,$day,$hour,$min,$sec,$%
Server Scratch tapes
-------- -------------
.
.
format STDOUT_scratch =
@<<<<<<< @>>>>
$poolkey,$scratch_ctr{$poolkey}
.
format STDOUT_TOP_empty =
ADSM Tape Allocation report
@#-@#-@# @#:@#:@# Page @>>
$year,$month+1,$day,$hour,$min,$sec,$%
Server Stg Pool Empty Tapes
-------- ----------- -----------
.
.
format STDOUT_empty =
@<<<<<<< @<<<<<<<<<< @>>>>
$server, $pool, $empty_ctr{$poolkey};
.
# Then let's get the current time and day info.
($sec,$min,$hour,$day,$month,$year)=localtime(time);
# call report subroutine requested
eval("&$report"."_info");
$all_good=1;
foreach $server (@server_list)
{
if (!($server_reachable{$server}))
{
print STDERR "$server can not be reached\n";
$all_good=0;
}
};
print STDERR "All servers were reached.\n" if ($all_good);
# end of processing
####################################################################################
Define various print functions - using subroutines
#
# Display volume information
sub volume_info {
$^="STDOUT_TOP_volume"; #set the format attributes
$~="STDOUT_volume"; #
foreach $key (sort(keys %tape_defined))
{
if (defined($lib_server{$key}) && defined($vol_server{$key})
&& ($lib_server{$key} ne $vol_server{$key}))
{
print STDERR
"WARNING>>> tape $key is cross defined in $lib_server{$key} and
$vol_server{$key}\n";
};
$server=$vol_server{$key};
$server=$lib_server{$key} if (!defined($vol_server{$key}));
write;
};
print "\n";
}; # close subroutine
# end of subroutine volume_info
#############################################################################################
#
# Display Storage pool info by server
sub storage_info {
#Count the volumes.
foreach $key (sort(keys %tape_defined))
{
if ($vol_pool{$key})
{
$stg_ctr{$vol_server{$key}." ".$vol_pool{$key}}+=1;
}
else
{
$stg_ctr{"not defined"}+=1;
}
};
#
$^="STDOUT_TOP_storage"; #set the format attributes
$~="STDOUT_storage"; #
$-=0; #force a form feed before the first record is written.
for $poolkey (sort(keys %stg_ctr))
{
($server,$pool)=split / /,$poolkey;
write
};
}; # close subroutine
# end of subroutine storage_info
#############################################################################################
#
# Display Scratch Tape info by Storage Pool
sub scratch_info {
#Count the scratch tapes.
foreach $key (sort(keys %tape_defined))
{
if ($lib_status{$key} eq "Scratch")
{
$scratch_ctr{$lib_server{$key}}+=1;
}
};
#print the results.
$^="STDOUT_TOP_scratch"; #set the format attributes
$~="STDOUT_scratch"; #
$-=0; #force a form feed before the first record is written.
for $poolkey (sort(keys %scratch_ctr))
{
write
};
};
# end of subroutine scratch_pool_info
###############################################################################
#
# Display Empty Tape info by Storage Pool
sub empty_info {
#Let's count the number of empty tapes that we have.
foreach $key (sort(keys %tape_defined))
{
if ($vol_status{$key} eq "Empty")
{
$empty_ctr{$vol_server{$key}." ".$vol_pool{$key}}+=1;
}
};
#Let's print the results.
$^="STDOUT_TOP_empty"; #set the format attributes
$~="STDOUT_empty"; #
$-=0; #force a form feed before the first record is written.
for $poolkey (sort(keys %empty_ctr))
{
($server,$pool)=split / /,$poolkey;
write;
};
};
# end of subroutine empty_info
###############################################################################
#
# Display all prevoius reports together
sub full_info {
&volume_info;
&storage_info;
&scratch_info;
&empty_info;
print STDERR "\nReport Complete\n\n";
};
# end of subroutine full_info
--PART-BOUNDARY=.19702111943.ZM12506.draupnir--
=========================================================================
|