#!/usr/bin/perl use strict; use warnings; # Author: David Morris # Version: $Id: vxreport,v 1.4 2004/11/10 19:50:42 davey Exp $ # Purpose: Print a report of Veritas Disk Groups # OS: Veritas 3.5 # License: Released under the GNU Public Licence (GPL) # The terms of the GPL are available at: # http://www.gnu.org/licenses/gpl.html use POSIX; use Getopt::Long; my $VRTSDIR = "/opt/VRTS/bin"; my @diskgroups; sub Usage { print <<"EOF"; Usage: $0 [ --totals ] Examples: $0 --totals EOF } my ( $dg, $dgdiskcount, $dgsz, $maxvoldg, $dgdate, %dgdatehash ); my ( $totaldiskcount, $totaldgsz, $totalunass ); GetOptions( "totals" => \ (my $totals), "help" => \ (my $help), "<>" => sub {print "Error\n"}, ) or die Usage(); if ( defined $help ) { Usage(); exit; } if ( defined $totals ) { Report(); Totalizer(); } if ( ! defined @ARGV ) { Report(); } sub Report { format STDOUT_TOP = Diskgroup Disks Diskgroup Unassigned Date/Time Size Mb. Mb. Created ------------------------------------------------------------------------------- . format STDOUT = @<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< @>>>> @>>>>>>>>>> @>>>>>>>>> @>>>>>>>>>>>>>>> $dg, $dgdiskcount, $dgsz, $maxvoldg, $dgdate . @diskgroups = VXDG(); foreach $dg (@diskgroups) { my @dgdisks = VXDSK($dg); $dgsz = DGSIZE(@dgdisks); $totaldgsz += $dgsz; $dgsz = commify($dgsz); $maxvoldg = MAXVOLDG($dg); $totalunass += $maxvoldg; $maxvoldg = commify($maxvoldg); $dgdiskcount = @dgdisks; $totaldiskcount += $dgdiskcount; $dgdate = $dgdatehash{$dg}; write; } } sub Totalizer { #print STDERR "-"x69, "\n"; #printf STDERR "%-23s %4s %11s %10s\n","Totals:",commify($totaldiskcount), commify($totaldgsz), commify($totalunass); #print STDERR "="x69, "\n"; format TOTALS = ------------------------------------------------------------------------------- Totals: @>>>> @>>>>>>>>>> @>>>>>>>>> $totaldiskcount, commify($totaldgsz), commify($totalunass) =============================================================================== . #no strict; $~ = "TOTALS"; write; } sub VXDG { # vxdg list output looks like this: #dg_archlogs_cashpw01 enabled 1074707830.3454.rhine-f # We want to break it up and return just the diskgroups: my ($diskgroup, $diskgroups); my $vxdg = "vxdg -q list |"; open(VXDG,"$VRTSDIR/$vxdg") or die "Cannot run $vxdg: $!"; my @dgs = ; close VX; foreach (@dgs) { my ($dg, $state, $id) = split /\s+/,$_; push @diskgroups, $dg; $dgdatehash{$dg} = DGDATE($id); } #@diskgroups="rootdg"; return @diskgroups; } sub DGDATE { my $id = shift; my ($ctime,$pad,$host) = split /\./, $id, 3; my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime($ctime); my $str = POSIX::strftime("%d/%m/%Y %H:%M", localtime($ctime)); my $createdate = "$str"; chomp($createdate); return $createdate; } sub MAXVOLDG { # Get the size of the largest volume that can be created on the disk group, i.e. diskgroup free space # vxassist -g dg_apps_rhine-c maxsize # Maximum volume size: 76453888 (37331Mb) my $dg = shift; open(VX,"$VRTSDIR/vxassist -g $dg maxsize 2>/dev/null |") or die "Cannot run vxassist: $!"; my $maxsize = ; close VX; if ( defined $maxsize ) { if ( $maxsize =~ /Maximum/ ) { chomp $maxsize; my ($mx, $vl, $ssz, $size) = split / /,$maxsize; $maxsize = block2gb($size); } } else { $maxsize="0"; } return $maxsize; } sub VXDSK { my $dg = shift; my ($dgdisks, $disk, @dgdisks); my $vxprint = "$VRTSDIR/vxprint -g $dg -q -d |"; open (VX, "$vxprint"); my @disks = ; foreach $disk (@disks) { my ($dm, $medianame, $accessname, $dash, $size) = split /\s+/,$disk; push @dgdisks, "$dg,$medianame,$accessname,$size\n"; } return @dgdisks; } sub DGSIZE { # Return size of a diskgroup; my @dgdisks = @_; my $dgsize=0; foreach (@dgdisks) { my ( $dg, $medianame, $dash, $size ) = split /,/,$_; $dgsize += $size; } my $dggbytes = block2gb($dgsize); return $dggbytes; } sub block2gb { my $val = shift; my $kbytes = 0; if ($^O eq "hpux" ){ $kbytes = $val; } elsif ($^O eq "solaris") { $kbytes = $val/2; }; my $gbytes = $kbytes/1024; return sprintf "%d",$gbytes; } sub commify { my $text = reverse $_[0]; $text =~ s/(\d\d\d)(?=\d)(?!\d*\.)/$1,/g; return scalar reverse $text; } __END__ =head1 NAME vxreport - report on veritas diskgroups, total number of disks in diskgroup, size of diskgroup in Mb, size of free space on diskgroup. =head1 SYNOPSIS vxreport [ --totals ] =head1 DESCRIPTION Finds and reports on all Veritas diskgroups on a system. The options are as follows: --totals =head1 EXAMPLES Sample Output: Diskgroup Disks Diskgroup Unassigned Date/Time Size Mb. Mb. Created ------------------------------------------------------------------------------- rootdg 2 139,999 735 25/11/2003 15:23 dg_oracle_u01 26 170,141 141 27/04/2004 14:25 dg_oracle_u02 3 21,012 811 21/04/2004 12:17 dg_oracle_u03 1 7,004 804 21/04/2004 12:00 ------------------------------------------------------------------------------- Totals: 32 338,,56 2,491 ===============================================================================