chris2013 has asked for the wisdom of the Perl Monks concerning the following question:
I'd like to parse a Charon (StrongSwan) logfile.
Somewhere it logs a failed login. If this is found, I'd like to lookup the username and IP address, that are mentioned some lines above.
What's the best approach? Is there any framework that can do that? Where I only have to fill-in the regex?
Should I read the whole logfile to an array and then go back? Or is there something like grep? I've tried to use a shell script and let perl one-liners do the regex stuff. Unfortunately I couldn't escape the single quotes in front and after the e-mail address. They have to be quoted because of the shell and the regex. Tried to write them to an evironment variable but that didn't work. Probably, there are completely different and better solutions.
export MYP="identity '([A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,})'" EMAIL=`grep -B15 "$DATE" $LOGFILE | grep "$CONID" | grep identity | pe +rl -nle 'print "$1" if /$ENV{MYP}/'`
Example:
Apr 29 10:01:10 vpn.example.com charon: 07[NET] <con1|33> received pac +ket: from 2.204.0.13[55842] to 27.3.213.112[4500] (80 bytes) Apr 29 10:01:10 vpn.example.com charon: 14[IKE] <con1|33> received EAP + identity 'jd@example.com' Apr 29 10:01:11 vpn.example.com charon: 14[IKE] <con1|33> EAP-MS-CHAPv +2 verification failed, retry (1)
- Chris
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Parse multiline logfile
by BrowserUk (Patriarch) on Apr 29, 2016 at 21:25 UTC | |
|
Re: Parse multiline logfile
by choroba (Cardinal) on Apr 29, 2016 at 20:50 UTC | |
by chris2013 (Initiate) on May 03, 2016 at 16:53 UTC |