justinkala has asked for the wisdom of the Perl Monks concerning the following question:
I have this configuration file where i put the search words so that i can decide what kind of event it is. cat EventType.conf<#|2014 Jul 29 16:20:20|INFO|JAVA_TEST_1.0.0|sun.java.jsf.managedbean +.AuthenticationMgr|DEFAULT|Login successful for user 'usr0001'|APPLIC +ATION USER|#> <#|2014 Jul 29 16:26:08|INFO|JAVA_TEST_1.0.0|sun.java.jsf.managedbean. +AuthenticationMgr|DEFAULT|Login successful for user 'usr0005'|APPLICA +TION USER|#> <#|2014 Jul 28 16:20:55|INFO|JAVA_TEST_1.0.0|sun.java.jsf.managedbean +.AuthenticationMgr|DEFAULT|Login successful for user 'usr0006'|APPLIC +ATION USER|#> <#|2014 Jul 28 16:22:44|INFO|JAVA_TEST_1.0.0|sun.java.jsf.managedbean. +user.UserRoleMgr|DEFAULT|Assigned roles for user 'usr0002' were modif +ied by user 'usr0006'|APPLICATION USER|#>
This is the perl script which reads the message file and checks with the Configuration file and returns the event name such as Succesful Authorization.Application Error::Error Succesful Authorization::User Logged Succesfully Failed Authorization::User logon failed/unsuccesful
Help needed on how efficiently I can use the Regex or grep in perl so that i can extract those values .and It is not one search word that is compared with the message ,it can be multiple words. "Login, succesful" are sought against the value being passed in $Line6 which is a event message. Thanks/usr/bin/perl /dir/perl/test.pl ${infile} ${outfile} cat test.pl #!/usr/bin/perl $dir="/dir"; $infile = $ARGV[0]; $outfile = $ARGV[1]; $configfile="$dir/conf/EventType.conf"; open(FILE, $infile) or die("Could not open $infile."); $/ = "#>\n"; $\ = "\n"; open(OUTFILE, ">", $outfile) or die("Could not open $outfile."); for $line (<FILE>) { # chomp($line); #split each line into fields and process @Line = split (/\|/, $line); #Check ETYPE and change EOUTCOME if ($Line[2] eq 'INFO') { $Line[5] = "INFO"; } elsif ($Line[2] eq 'ERROR') { $Line[5] = "ERROR"; } #Check EMSG and create new field next to it open CONFIG, $configfile or die "Could not open $configfile... + $!"; for $configLine (<CONFIG>) { chomp($configLine); @configLineItems = split /::/, $configLine; for $checkItem (@configLineItems) { if ("$Line[6]" =~ $checkItem) { $Line[8] = $configLineItems[0]; } else { $Line[8] = "Other Application Event" +; } } } #Write output print OUTFILE "|", $Line[1], "|", $Line[2], "|", $Line[3], "|" +, $Line[4], "|", $Line[5], "|", $Line[6], "|", $Line[8], "|", $Line[7 +],"|" ; close CONFIG; } close (FILE); close (OUTFILE);
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Regex perl grep usage string match comparison
by Anonymous Monk on Aug 05, 2014 at 23:33 UTC | |
by justinkala (Initiate) on Aug 06, 2014 at 13:31 UTC | |
by Anonymous Monk on Aug 06, 2014 at 14:12 UTC | |
|
Re: Regex perl grep usage string match comparison
by Laurent_R (Canon) on Aug 05, 2014 at 21:27 UTC | |
|
Re: Regex perl grep usage string match comparison
by Anonymous Monk on Aug 06, 2014 at 18:32 UTC | |
by justinkala (Initiate) on Oct 12, 2014 at 02:51 UTC | |
by Athanasius (Archbishop) on Oct 12, 2014 at 04:15 UTC |