Perl script to scan isaerror logs and report/email unplanned errors

Sometimes the ISA server goes very wrong and some unplanned exception are thrown, this script here is a quick and dirty script that scans those logs and find errors, then outputs a list of errors (and stacktrace) out.

It also sends the "new" (since last run) errors by email.

Notice LOG_FOLDER, why do isa log files end-up in that folder (ipcpricing), i have no idea ... weird !
We have a bunch of "exclusions" for errors we know are harmless and we ust want to ignore

ISA alerts scanscript ''
#Thibaut Colar
# Scans SAP isa logs and create report file & send email alert

# Uses Mail:sendmail to send directly through socket on smtp server
use Mail::Sendmail;

### Constants ####
$END_NO_EMAIL=195; #3:15AM

##### Main ###############
$lastErr=`cat lasterr.txt`;
print "Prev Run:".$lastErr."\n";
$now=`date +%s`;

open(LS,"ls -1t --color=never ${LOG_FOLDER}isaerror* | ");
# files are rotated, so we use last two, so not to miss anything
`cat '$data_file2' > scan.tmp`;
`cat '$data_file' >> scan.tmp`;
print "Ran At:".$now."\n";
print `date`;
print "Using files ".$data_file2." & ".$data_file."\n\n";
close LS;

open(LOG, "scan.tmp") || die("Could not open file!");

while($i < $#lines)
	# find errors
	if($line =~ m/ Error /i)
		# exclusions
		if( ! (
   $line =~ m/ 
|| $lines[$i] =~ m/Logon is invalid/
|| $lines[$i] =~ m/Payment card\s+\S+\s+has expired/
|| $lines[$i] =~ m/An error occurred during card authorization/
|| $lines[$i] =~ m/Use another card or another payment type/
|| $lines[$i] =~ m/for card type \S+ incorrect/
			# Do we have a stack trace ?
			if($lines[$i+1] =~ m/[Exception]/)
				# traces start with a non space char(tab)
				while(! ($lines[$i] =~ m/^\S+\s+\d+/) && $i< $#lines)
					#traces to be ignored
   $lines[$i] =~ m/Error at user change: internet user is unknown/
|| $lines[$i] =~ m/com.tealeaf.sdk.UserConfiguration.getCookie/
# We should fix those in code
|| $lines[$i] =~ m/ The connection is closed./
|| $lines[$i] =~ m/CM_NO_DATA_RECEIVED/
|| $lines[$i] =~ m/java.lang.NumberFormatException: For input string/
|| $lines[$i] =~ m/error for text CRM_ORDERI/
					if($traceCpt<$MAX_TRACE_LENGTH || $lines[$i] =~ m/^Caused by/)

			# print the error / send email
				if($line =~ m/^(\S+ \d+, \d+ \d+:\d+:\d+ \w+)/)
					$time=`date -d "$1" +%s`;
					if($time > $lastErr)
						print "---NEW ERROR---\n";
				print $title;
				print $trace;
close LOG;
print "----- Errors found: ".$nbError." ------\n";

	`echo "$newLastErr" > lasterr.txt`; 
$mn=`date +%M`;
$h=`date +%H`;
	if($total>$START_NO_EMAIL && $total<$END_NO_EMAIL)
		print "NOT Sending alerts by email. ($START_NO_EMAIL>$total<$END_NO_EMAIL)\n";
		print "Sending new alerts by email.\n";
		%mail = ( To      => "$EMAIL_RCPTS",
                From    => "$EMAIL_FROM",
                Message => "$email",
                Subject => "New($newCpt) SA Alerts(Maple)!",
		smtp => "$SMTP_SERVER"
		sendmail(%mail) or die $Mail::Sendmail::error;

Example report after running 'perl'
Prev Run:1205776848
Ran At:1205776872
Mon Mar 17 11:01:12 PDT 2008
Using files /usr/sap/XYZ/JC01/j2ee/cluster/server0/apps/ & /usr/sap/XYZ/JC01/j2ee/cluster/server0/apps/

Mar 14, 2008 11:30:49 AM,973 SAPEngine_Application_Thread[impl:3]_17   Error Error occcurred in EAI layer "$Exception: (102) RFC_ERROR_COMMUNICATION:      I/O error for text CRM_ORDERI 47DAD56FCDF81BCDE1000000C7F9D70B Z001 ". 
[EXCEPTION]$Exception: (102) RFC_ERROR_COMMUNICATION:      I/O error for text CRM_ORDERI 47DAD56FCDF81BCDE1000000C7F9D70B Z001 
	at com.pcf.b2c.rfc.AddOrderText.executeRFC(
	at com.pcf.b2c.rfc.RFCAction.executeRFC(
	at jsp_acknowledgement_2e_inc1201230851220._jspService(
Mar 14, 2008 12:44:07 PM,479 SAPEngine_Application_Thread[impl:3]_38   Error Backend Error: When payment form is payment card, please enter card data 
----- Errors found: 3 ------

Script to run the scan and store the result under the 'admin' section of the site, so it can be easily checked at http://myisasite/myisaapp/admin/scan.txt In the 'admin' section so it requires authentication, since we don't want anyone to see this file (may contain sensitive data)
cd /home/me
./ > /usr/sap/XYZ/JC01/j2ee/cluster/server0/apps/

Cron entry to run this every 3 mn
cron entry
*/3 * * * * /home/me/ >/dev/null &


Add a new Comment