Perl Script: Oracle Database Alert Log Parser, Send Email Notification if Error is Found
\s+(\d+):(\d+):(\d+)\s+ # the time
\d+ # the year
/x;$now = $1 *60*60 + $2 * 60 + $3 if (defined $1 && defined $2 && defined $3);
if (m/^(\S+\s+)(\S+)(\s+\d+) # word (like Wed) followed by Mon and Day
(\s+\d+:\d+:\d+\s+) # the time - ignored
(\d+) # the year
/x)
{$has_error=0;
$log_date_tag = $1 . $2. $3. ” “. $5 if (defined $1 && defined $2 && defined $3 && defined $5);
#print $log_date_tag .”\n”;
#print $today_date_tag .”\n”;
next if ($today_date_tag ne $log_date_tag ) ;
if ($timestamp ne $_)
{
$timestamp= $_;
}
#print $timestamp.”\n”;
next if ($last_timestamp eq $timestamp);$cur_log_timestamp_str = $2. $3. ” “. $5. $4 if (defined $2 && defined $3 && defined $4 && defined $5);
if (m/^(\S+\s+)(\S+)(\s+\d+) # word (like Wed) followed by Mon and Day
\s+(\d+):(\d+):(\d+)\s+ # the time
(\d+) # the year
/x)
{
$cur_log_timestamp = ($4 *60*60 + $5 * 60 + $6) if (defined $4 && defined $5 && defined $6);
}
#print $cur_log_timestamp .”\n”;
$newtime = 1;
}
else # not timestamp
{
$newtime = 0;
$elapsed = $cur_log_timestamp - $last_log_timestamp;
#print $cur_log_timestamp.” “. $last_log_timestamp .” “.$elapsed.”\n”;
($has_error, $trc_file)= check_error($_);if (check_error($_ ) && $elapsed >=0 )
{
print $trc_file .”\n”;
push (@trc_files, $trc_file);
# $has_error =1;
if ( m/ORA-/ || m/Error/)
{
$counter++;
}
if ($timestamp ne $error_started_time)
{
$error_started_time = $timestamp;
push @error_msg, “” ;
push @error_msg, $error_started_time ;
#print $error_started_time .”\n”;
}
}
else
{
$has_error =0;
}if ($has_error == 1 && $newtime==0 && $elapsed >=0 && ($timestamp ne $last_timestamp))
{
#print $timestamp .”\n” .$last_timestamp .”\n”. $_.”\n”;
push @error_msg, $_;
}
#print $elapsed .”\n”;if ( $elapsed >=0 && $timestamp ne ” && ( /$mesg1/ or
(/$mesg2/ and /$mesg5/ ) or
/$mesg3/ or
(/$mesg4/ && /$mesg5/ ) or
(/$mesg6/ && /$mesg7/) )
)
{
#print $timestamp .”\n”;
$db_shutdown_status = check_db_status($_);
$db_start_status = check_db_status($_);
if ($db_start_status == 1)
{
$message .=”ORACLE startup: $timestamp.<br>”;
$text_message .=”ORACLE startup: $timestamp.\n”;
}
if ($db_start_status == 2 )
{
$message .=”ORACLE was started: $timestamp.<br>”;
$text_message .=”ORACLE was opened: $timestamp.\n”;
$db_status_subject .=” DB was up “;
}
if ($db_shutdown_status == 3)
{
$message .=”ORACLE shutdown: $timestamp.<br>”;
$text_message .=”ORACLE shutdown: $timestamp.\n”;
}
if ($db_shutdown_status == 5)
{
$message .=”ORACLE shutdown immediate: $timestamp.<br>”;
$text_message .=”ORACLE shutdown by immediate: $timestamp.\n”;
}
if ($db_shutdown_status == 4)
{
$message .=”ORACLE shutdown completed: $timestamp.<br>”;
$text_message .=”ORACLE shutdown completed: $timestamp.\n”;
$db_status_subject =”DB was down, “;
}}
}
}
Popularity: 14%



















































ron reidy said,
June 28, 2007 @ 5:06 pm
Please remove this script from this site, or remove the author name listed and “All Rights Reserved” clause.
The person who put hist name on this script along with the “All Rights Reserved” clause did not right this Perl program - I did. I posted it to orafaq.com/scripts/perl/trlogmon.pl in 1999. The Windows changes are a minor addition to a program that was originally written to run on Solaris and Linux
Very unoriginal of a Ph.D., indeed.