#!/usr/bin/perl #-------------------------------------------------------------------- # mkreport - reporting script for Deployment Tool (deploy.pl) # # This script parses all deploy.pl tracefiles in a given directory # and creates a deployment runtime report for all applications # (earfiles) deployed successfully. # A summary report is shown at the console, a more detailed one # is written into the file 'report_[timestamp].txt' #-------------------------------------------------------------------- use strict; use warnings; use Pod::Usage; use DirHandle; use FileHandle; use Time::localtime; use Getopt::Long; #-------------------------------------------------------------------- # read command line params #-------------------------------------------------------------------- our $config = {}; my $rc = GetOptions( "help" => \$config->{help}, "full" => \$config->{full}, "csvfile:s" => \$config->{csvfile}, "txtfile:s" => \$config->{txtfile}, ); # check for invalid options pod2usage() if ( !$rc || $config->{help} ); # we need a directory pod2usage("Please provide the path where to find the logs/tracefiles!\n") unless ( $ARGV[0] ); my $dir = $ARGV[0]; #-------------------------------------------------------------------- # format definitions #-------------------------------------------------------------------- # global variables to use in the format our ( $cluster, $app, $date, $start, $end, $saveStart, $saveEnd, $syncStart, $syncEnd, $status ) = undef; #-------------------------------------------------------------------- # format definition for summary heading # format summary_top = @>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> "Page $%" Application Deployment Summary Cluster Application Date Start End Status --------------------------------------------------------- . # #-------------------------------------------------------------------- #-------------------------------------------------------------------- # format definition for summary lines # format summary = @<<<<<<<< @<<<<<<<<<<< @<<<<<<<<< @<<<<<<< @<<<<<<< @|||| $cluster, $app, $date, $start, $end, $status . # #-------------------------------------------------------------------- #-------------------------------------------------------------------- # format definition for full report heading # format report_top = @>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> "Page $%" Deployment Report Cluster Application Date Start Save Synch End Status ------------------------------------------------------------------------------------------ . # #-------------------------------------------------------------------- #-------------------------------------------------------------------- # format definition for report file lines # format report = @<<<<<<< @<<<<<<<<< @<<<<<<<<< @<<<<<<< @|||||||-@||||||| @|||||||-@||||||| @<<<<<<< @|||| $cluster,$app, $date, $start,$saveStart,$saveEnd,$syncStart,$syncEnd,$end,$status . # #-------------------------------------------------------------------- #-------------------------------------------------------------------- # format definition for full report heading # format csv_top = Cluster;Application;Date;Start;saveStart;saveEnd;synchStart;synchEnd;End;Status . # #-------------------------------------------------------------------- #-------------------------------------------------------------------- # format definition for cvsfile lines # format csv = @<<<<<<<;@<<<<<<<<<;@<<<<<<<<<;@<<<<<<<;@<<<<<<<;@<<<<<<<;@<<<<<<<;@<<<<<<<;@<<<<<<<;@<<<<< $cluster,$app,$date,$start,$saveStart,$saveEnd,$syncStart,$syncEnd,$end,$status . # #-------------------------------------------------------------------- #-------------------------------------------------------------------- # map filehandles to formats # if ( $config->{full} ) { format_name STDOUT "report"; format_top_name STDOUT "report_top"; format_lines_per_page STDOUT 25; } else { format_name STDOUT "summary"; format_top_name STDOUT "summary_top"; format_lines_per_page STDOUT 25; } format_name TXTFILE "report"; format_top_name TXTFILE "report_top"; format_lines_per_page TXTFILE 60; format_name CSV "csv"; format_top_name CSV "csv_top"; format_lines_per_page CSV 9999; # #-------------------------------------------------------------------- #-------------------------------------------------------------------- # main script #-------------------------------------------------------------------- # open files if asked for... if ( $config->{txtfile} ) { open( TXTFILE, ">" . $config->{txtfile} ) or die "Can't open " . $config->{txtfile} . " for writing: $!\n"; } if ( $config->{csvfile} ) { open( CSV, ">" . $config->{csvfile} ) or die "Can't open " . $config->{csvfile} . " for writing: $!\n"; } # act on any file in $dir... my $dh = DirHandle->new($dir) or die "can't opendir $dir: $!"; while ( defined( my $file = $dh->read ) ) { $file = "$dir/$file"; # do only act on files next unless ( -f $file ); # do only act on files whose name ends with "log" next unless ( $file =~ /log$/ ); # analyse the file analyseLog($file); } # close preliminary opened file handles if ( $config->{txtfile} ) { close(TXTFILE); } if ( $config->{csvfile} ) { close(CSV); } #-------------------------------------------------------------------- # procedure to analyse one log file and print report lines #-------------------------------------------------------------------- sub analyseLog { my $file = shift; my ( $cluster, $application, $startTime, $endTime, $startSave, $endSave, $startSync, $endSync ); open( LOG, $file ) or die "Can't open file for reading $file: $!\n"; while ( my $line = ) { chomp($line); if ( $line =~ /Deploying application (.+)_(.{3,})$/ ) { $cluster = $1; $application = $2; $startTime = substr( $line, 12, 8 ); $endTime = undef; $startSave = undef; $endSave = undef; $startSync = undef; $endSync = undef; $status = undef; } elsif ( $line =~ /Saving configuration changes/ ) { $startSave = substr( $line, 12, 8 ); } elsif ( $line =~ /DEPL0001D\: \.\.\.done/ ) { $endSave = substr( $line, 12, 8 ); } elsif ( $line =~ /Synchronizing all nodes for cluster/ ) { $startSync = substr( $line, 12, 8 ); } elsif ( $line =~ /Synchronization succeeded/ ) { $endSync = substr( $line, 12, 8 ); } elsif ( $line =~ /Nothing to be done by wsadmin/ ) { $status = "NOWAS"; } elsif ( ( $line =~ /DONE with application (.+)_(.{3,})$/ ) || ( $line =~ /FATAL:/ ) ) { if ($line =~ /FATAL:/) { $status = "FATAL"; } elsif ($startSync && !$endSync){ $status = "ERROR"; } elsif (!$status) { $status = "OK"; } # omit deployments without WAS interaction next if ($status eq "NOWAS"); $endTime = substr( $line, 12, 8 ); my $lastSlash = rindex( $file, "/" ); my $date = substr( $file, $lastSlash ); $date = substr( $date, 11, 8 ); $date =~ s/(\d{4})(\d{2})(\d{2})/$3\.$2\.$1/g; &printReport( $cluster, $application, $date, $startTime, $endTime, $startSave, $endSave, $startSync, $endSync, $status ); } } close(LOG); return; } #-------------------------------------------------------------------- # procedure that actually prints out analysed data #-------------------------------------------------------------------- sub printReport { ( $cluster, $app, $date, $start, $end, $saveStart, $saveEnd, $syncStart, $syncEnd, $status ) = @_; $saveStart = "n/a" unless ($saveStart); $saveEnd = "n/a" unless ($saveEnd); $syncStart = "n/a" unless ($syncStart); $syncEnd = "n/a" unless ($syncEnd); select STDOUT; write; if ( $config->{txtfile} ) { select TXTFILE; write; } if ( $config->{csvfile} ) { select CSV; write; } } #-------------------------------------------------------------------- # procedure that generates a timestamp for us... #-------------------------------------------------------------------- sub timestamp { my $tm = localtime(); my $timestamp = sprintf( "%04d%02d%02d%02d%02d%02d", $tm->year() + 1900, $tm->mon() + 1, $tm->mday(), $tm->hour(), $tm->min(), $tm->sec() ); return $timestamp; } __END__ =head1 NAME mkreport.pl - reporting tool for WebSphere Deployment Tool I =head1 SYNOPSIS mkreport.pl [options] path "path" is the directory in which your logs/tracefiles reside Options: --help print this page --full print a full report to the console --csvfile filename create a csv report file --txtfile filename create a human readable report file =head1 OPTIONS =over4 =item --help Print the help (SYNOPSIS). =item --full Print the whole report to the console as it would be printed to a file when using C<--txtfile filename> option. =item --csvfile filename Write a report CSV file. This might be usefull if one wants to use the reported data in e.g. MS Excel. =item --txtfile filename Write a report in human readable table form to a text file. =back =cut