#!/usr/software/bin/perl # $Id: //depot/prod/test/Rsierranevada/storage/hdd/NADQ_SEA/NDATE/SUPPORT_SCRIPTS/post_job.thpl#3 $ # Copyright (c) 2005 Network Appliance, Inc. # All rights reserved # ## @summary Mode ## Delete extra log files ## @description ## Delete send_result_to_console.log file ## @param LOGDIR Location of the log file to be deleted ## @param LOGLVL Log level (delete logs if log level is less thsn 4) ## @status public ## @author maji@netapp.com #use strict; use Cwd qw(abs_path); use HTML::Mail; use NATE::TestInfo; use San; use Data::Dumper; use Net::SCP::Expect; use Storage::Common_Lib; sub clean_up_subdir(); my $status; my $Home = $ENV{HOME}; my $san_obj = new San( \*ntest::NTEST_STDOUT ); if ( $san_obj->error() ) { logresult( 'FATAL', "Failed to instantiate San object" . $san_obj->errmsg() ); } ######################################## ### Initialization/declaration ######################################### use vars qw( $LOGLVL $LOGDIR $TEST_CONFIG $RUNPYTH $PYTHPATH $AUTO_PUSH $MAIL_TO $MAIL_FROM $RUNID ); param( 'LOGDIR', '-default', '' ); param( 'LOGLVL', '-default', '2' ); param( 'RUNPYTH', '-default', '2' ); param( 'PYTHPATH', '-default', '/usr/software/bin/python' ); param( 'AUTO_PUSH', '-default', '0' ); param( 'MAIL_TO', '-default', '0' ); param( 'MAIL_FROM', '-default', '0' ); param( 'RUNID', '-default', '0' ); opendir( IMD, $LOGDIR ) || die("Cannot open directory"); logcomment("LOGDIR - $LOGDIR"); my @thefiles = readdir(IMD); logcomment("Files present in DIR: @thefiles"); my $consolefilename; closedir(IMD); my @par_log; my $mail_subject = "Final LEMUR Test Result : $LOGDIR"; my $mail_body; foreach my $file (@thefiles) { my $final_log; if ( $file =~ /Lemur/ ) { open( MAIN_LOG, "$LOGDIR" . "/" . "$file" ); $final_log = "$LOGDIR" . "/" . "PARSED_" . "$file"; my @total_data = ; logcomment( "Toatl number of actual lines " . scalar @total_data ); close MAIN_LOG; foreach my $line (@total_data) { #logcomment("$line"); #next if ( $line =~ /_mkpat|closed\s+filehandle|deprecated|redefined|/ ); $line =~ s/\[\S+\]//g; $line =~ s/X;X/ /g; $line =~ s/\[\.\]//g; logcomment("AFTER PAR SEEEE : $line"); next if ( $line =~ /closed filehandle|deprecated|redefined|Prototype|mkpat|Unrecognized|NOTE\:\:END|NOTE\:\:Log|eval\s+\{|error creating/ ); next if ( $line =~ /dpg_automation|GNOTE|uninitialized|Attempt to DESTROY|just omit|read: Failed/ ); push( @par_log, $line ); } logcomment("FILE : $final_log"); logcomment( "Total line : " . scalar @par_log ); open( PARS, ">$final_log" ); print( PARS @par_log ); close(PARS); } } opendir( IMD, $LOGDIR ) || die("Cannot open directory"); logcomment("LOGDIR - $LOGDIR"); my @thefiles = readdir(IMD); logcomment("Files present in DIR: @thefiles"); my $consolefilename; closedir(IMD); my $main_file; foreach my $file (@thefiles) { if ( $file =~ /PARSED/ ) { my $dest = "$LOGDIR/../"; my $sorc = "$LOGDIR/$file"; my $time_stamp = rename_log_file(); my $nw_f = $time_stamp . "_" . $file; $nw_f =~ s/PARSED_//g; system("sudo mv $LOGDIR/$file $dest/$nw_f"); $main_file = $dest / $nw_f; } } system("sudo rm -rf $LOGDIR/latest"); my $mail_out = `cat $Home/NDATE/default_params`; my @lines = split( /\n/, $mail_out ); foreach my $line (@lines) { logcomment("DEBUG MAIL : $line "); if ( $line =~ /EMAIL_TO=(.*)/ ) { $MAIL_TO = $1; } if ( $line =~ /EMAIL_FROM=(.*)/ ) { $MAIL_FROM = $1; } logcomment("MAIL : $MAIL_TO and FROM :$MAIL_FROM"); } ## PARSE FOR MAIL open( MAIN_LOG, $main_file ); @total_data = ; $flag = 0; my @fail; my @warn; my @fatal; my @no_run; my $tota_time; my $lemur_img; my $test_scp; my $log_dir; my $color; foreach (@total_data) { if ( $_ =~ /\*\*FAIL\*\*/ ) { $_ =~ s/. Comment: //; print "$_"; push( @fail, $_ ); $result = "FAILED"; $color = "#ff0000"; } if ( $_ =~ /\*\*FATAL\*\*/ ) { $_ =~ s/. Comment: //; print "$_"; $result = "FATAL"; $color = "#ff0000"; push( @fatal, $_ ); } if ( $_ =~ /\*\*WARNING\*\*/ ) { $_ =~ s/. Comment: //; print "$_"; push( @warn, $_ ); } if ( $_ =~ /LEMUR\s+IMAGE\s+\:/ ) { $_ =~ s/. Comment: //; print "$_"; $lemur_img = $_; } if ( $_ =~ /\#\#\s+TESTBED:\s+/ ) { $flag = 1; } if ( $flag == 1 ) { print "$_"; if ( $_ =~ /cfg\s+Failed|tst\s+Failed/ ) { print "####### FAILED ####\n"; $result = "FAILED"; $color = "#ff0000"; } else { $result = "PASSED"; $color = "#008000"; } } if ( $_ =~ /TESTSCRIPT:\s+(.*)/ ) { print "TESTSCRIPT : $1\n"; $test_scp = $1; } if ( $_ =~ /TESTLOG:\s+(.*)/ ) { print "TESTLOG : $1\n"; $log_dir = $1; } if ( $_ =~ /Time:\s+(.*)/ ) { print "Time is $1\n"; my $t = $1; my ( $hr, $min, $sec ) = $t =~ /(\S+)\:(\S+)\:(\S+)/; print "$hr Hrs $min Min $sec Sec\n"; $tota_time = $hr . "Hrs" . $min . "Min" . $sec . "Sec"; } } if ( !@fatal ) { push( @fatal, "No Fatal messages" ); } if ( !@fail ) { push( @fail, "No Failure messages" ); } if ( !@warn ) { push( @warn, "No Warining messages" ); } if ( !@no_run ) { push( @no_run, "No NO_RUN messages" ); } my $mail_body = "

NDATE version" . $value ."
Build date". $date ."
Log Directory" .$log_dir ."
SCRIPT NAME :" .$test_scp ."
LEMUR IMAGE :" .$lemur_img ."

TOTAL TIME TAKEN : ". $tota_time."

SCRIPT RESULT : " .$result. "

LOG FILE : ". $main_file. "

#########################################################

WARNING MESSAGES:

".@warn."

NO_RUN MESSGES:

".@no_run."

FAILURE MESSAGES:

".@fail."

FATAL MESSAGES:

".@fatal."

#########################################################

 

"; =head ##### my $mail_body = "

NDATE version $value
Build date $date
Log Directory $log_dir
SCRIPT NAME : $test_scp
LEMUR IMAGE : $lemur_img

TOTAL TIME TAKEN : $tota_time

SCRIPT RESULT : $result

LOG FILE : $main_file

#########################################################

WARNING MESSAGES:

@warn

NO_RUN MESSGES:

@no_run

FAILURE MESSAGES:

@fail

FATAL MESSAGES:

@fatal

#########################################################

 

"; #### =cut my %mail_params = ( HTML => $mail_body, Text => $mail_body, From => $MAIL_FROM, To => $MAIL_TO, Subject => $mail_subject, ); $mail_params{HTML} = "
$mail_params{Text}<\\HTML>";
my $mail = HTML::Mail->new(%mail_params);
$mail->send() or logresult( "CONFIG", "trouble sending mail" );

sub rename_log_file {
    my $timestamp;
    $a = scalar( localtime() );
    $a =~ s/\s\s*/ /g;
    $a =~ s/ /:/g;
    $a =~ s/:/ /g;
    $a =~ s/ /_/g;
    my @time_a = split( /_/, $a );
    my @final;
    my @abbr    = qw( Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec );
    my %mon_num = qw(
      Jan 01  Feb 02  Mar 03  Apr 04  May 05  Jun 06
      Jul 07  Aug 08  Sep 09  Oct 10 Nov 11 Dec 12
    );

    foreach my $val (@time_a) {
        if ( grep( /$val/i, @abbr ) ) {
            my $mon_val = $mon_num{"$time_a[1]"};
            push( @final, $mon_val );
        } else {
            if ( $val =~ /^[0-9]$/ ) {
                $val = "0" . $val;
                push( @final, $val );
            } else {
                push( @final, $val );
            }
        }
    }

    #$timestamp = $final[6].$final[1].$final[2]."_".$final[3].$final[4].$final[5];
    my ( $year_1, $year_2 ) = $final[6] =~ /^(\d{2})(\d{2})\z/;
    $timestamp = $year_2 . $final[1] . $final[2] . "_" . $final[3] . $final[4];
    logcomment("time - $timestamp");
    return $timestamp;
}