Regex to filter error codes

Any questions involving matching text strings to patterns - the pattern is called a "regular expression."

Moderator: General Moderators

Post Reply
User avatar
Jenk
DevNet Master
Posts: 3587
Joined: Mon Sep 19, 2005 6:24 am
Location: London

Regex to filter error codes

Post by Jenk »

One of the systems I support scans through oracle and siebel error logs (using perl), and raises alerts for errors that are not known.

EDIT: Just to add that this does work; however I just wanted to ask if anyone can see any loopholes where an error message in the below format could slip through.

Code: Select all

	while (<OUTPUTFILE>) 
	{
		$permittedSBL = "00426|01042";

		$permittedORA = "00000|00001";

		if ( $_ =~ /(SBL-EIM-[0-9]{5}(?<!(?:$permittedSBL))|ORA-[0-9]{5}(?<!(?:$permittedORA)))/i )
		{
			push(@return, 8);
			next;
		}
		if ( $_ =~ /Command completed successfully/i )
		{
			push(@return, 0);
			next;	
		}	
	}
Can anyone see any flaws in the regex? I've tested to a certain degree but am out of ideas. The errors are always, for example:

Code: Select all

ORA-12345: Error message
or:

Code: Select all

SBL-EIM-12345: Error Message
and the message is not always at the start of the line. I've been instructed to add an allowance of certain errors (despite my concerns that it is bad practice .. ) thus the use of a regex to test the type of error as well as the error message itself.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

It appears okay.
Post Reply