Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Perl script that scans session logs and reports on errors

Status
Not open for further replies.

hubud

Instructor
Oct 18, 2002
123
GB
Tested on Solaris Unix, using perl5.6.1.

You'll have to specify the correct location for your perl compiler at the top of the script. Hope this helps someone out.



#!/usr/local/perl5.6.1/bin/perl

# @(#) Script that checks last 150 session log files for any failures or errors and reports details to Production support.

use warnings;

#Declare variables, arrays and hashes

my $space = " ";
my $cause = " Root cause: ";
my $dir = '/apps/informat5/informatica/PowerCenter/SessLogs';
my $time = gmtime;
my $temp_count;
my $match_holder;
my $file_status;
my @pr_list = ();
my @pr_files = ();
my @pr_files2 = ();
my @pr_files3 = ();

#Hash contains a list of error conditions. The key holds the string to match, the value holds the output to print on that match
#For additional error strings add them here.

my %matchlist =
(
'No such file or directory' => 'File or Directory not found',
'ORA' => 'Oracle based error, see log file for details',
'cannot insert NULL' => 'An attempt was made to insert a Null value to a Non Null field',
'Error executing shell command...' => 'A pre or post Unix shell command failed',
'Error connecting to database...' => 'An error occurred connecting a database',
'Error initializing DTM for session...' => 'Error initializing DTM for session',
'An error occurred while connecting' => 'An error occurred attempting to connect to the Database',
'TNS:could not resolve service name' => 'TNS error, failed to resolve service name',
'fetched column value was truncated' => 'A column value was truncated, see log file for details',
'unexpected end of SQL command' => 'An unexpected end of SQL command error occurred',
'Received request to stop session run' => 'Session stopped by user',
'missing expression' => 'Missing expression',
'Failed to logon to Database server' => 'Failed to logon to Database server',
'Deadlock error encountered.' => 'Deadlock error occurred',
'table or view does not exist' => 'Table or view does not exist',
'STG_PROD.CHECK_SESSION' => 'Check session function failed',
'failed to extend rollback segment' => 'Rollback segment failed to extend',
'resource busy and acquire with NOWAIT specified' => 'NOWAIT specified for resource. Usually table locked by index creation',
'Joiner will not produce any output row' => 'Joiner transformation failed to produce output',
'unique constraint' => 'Unique constraint violation, Primary key error',
'Received request to abort session run' => 'Session aborted by user',
'Stopping debugger upon user requestsnapshot too old' => 'Debugger session. Stopped by user',
'end-of-file on communication channel' => 'End-of-file on communication channel',
'Error updating repository tables' => 'Error updating repository tables',
'synonym translation is no longer valid' => 'Synonym translation is no longer valid',
'invalid ROWID' => 'Invalid ROWID error occurred',
);

#Change to SessLogs directory, get files to process
chdir "$dir" or die "Can't chdir to SessLogs: $!";
chomp(my @srcfiles = `ls -rt | tail -170`);

chomp(my $file_running = `ls -rt | tail -1`);

#Call function to return the status of the most recent file to have run
my $return_val = file_status($file_running);

#Sort out logs that have failed and not failed into different arrays

foreach my $file (@srcfiles) {

my $curfile = `tail -1 $file`;

if ($curfile =~ /Session run completed with failure/) {

push (@pr_files, $file);
}
else {

push (@pr_files2, $file);
}
}


#HEADER INFORMATION
#Relates to only the files that Informatica believes has failed.

&pl("\n\tAUTOMATED SESSION LOG SEARCH RESULTS\n\t------------------------------------\n\nFiles scanned 170 Directory: $dir $space Time: $time\n\nMost recent file to run: $file_running $return_val (If part of concurrent batch may be incorrect)\n\n");


#Push failed logs onto a @temp array, these failures are ones that informatica states are failures
{


foreach my $file (@pr_files) {

@temp = ();

open FILE, "$file" or die "Cant open file: $file";

local $/ = undef;
my $hndlread = <FILE>;
study ($hndlread);
close FILE;

#Get start time from log file

if ($hndlread =~ /\bInitializing session\b.*\[(.*)\]/) {

&pl ("$1:-- $file failed");
}
#Replace match strings for output strings and push onto temp array

foreach my $match (sort keys %matchlist) {

if ($hndlread =~ /$match/) {

push (@temp, "$space$cause$matchlist{$match}");
}
}

foreach (@temp) {

&pl ("$_");
}
&pl ("");
}
}

#Second part of output. Informatica logs that may have failed but no Failure message given.
&pl("\n\tFILES CONTAINING ERROR CONDITIONS THAT MAY INDICATE FAILURE\n\t-----------------------------------------------------------\n\n\n");

#Process files, sort out logs that have a match for a failure. Others discarded.
foreach my $file (@pr_files2) {

$temp_count = undef;
@temp = ();

open FILE, "$file" or die "Cant open file: $file";

local $/ = undef;
my $hndlread = <FILE>;
study ($hndlread);
close FILE;

my $i = 0;

foreach my $match (keys %matchlist) {
if ($hndlread =~ /$match/) {
$i++;
}
}

if ($i > 0 ) {

push (@pr_files3,$file);
}
}


#Create output strings for "non failed" logs
foreach my $file (@pr_files3) {

$temp_count = undef;
@temp = ();

open FILE, "$file" or die "Cant open file: $file";

local $/ = undef;
my $hndlread = <FILE>;
study ($hndlread);
close FILE;


if ($hndlread =~ /\bInitializing session\b.*\[(.*)\]/) {

push (@temp, "$1:-- $file failed");
}

foreach my $match (sort keys %matchlist) {

if ($hndlread =~ /$match/) {

push (@temp, "$space$cause$matchlist{$match}");
}
}

$temp_count = @temp;

foreach (@temp) {

&pl ("$_");
}

if ($temp_count > 0) {
&pl ("");
}
}

#Output the logfile report

&output;



##################Start of subroutines#####################

sub file_status { #Identifies the status of the log file. Completed, running etc...

my ($file) = @_;
my $file_tail = `cat $file | tail -1`;

my %status_hash =
(
'Session run completed with failure' => ' completed with failure',
'session run terminated' => ' was terminated by user',
'successfully' => ' has completed',
);

my $file_status = '0';

foreach $key ( keys %status_hash ) {

if ($file_tail =~ /$key/) {
$file_status = $status_hash{$key};
}
}
close FILE;

if ($file_status eq 0) {
$file_status = ' is still running';
}

return $file_status;
}

sub pl { #Pushes output to final output array

push @pr_list, "$_[0]";
}

sub output { #Print out the final output array

system('clear');

foreach (@pr_list) {
print "$_\n";
}
}


cheers

simmo
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top