Perl module for analyzing log files?

D

D. Alvarado

Can anyone recommend a module that I can use to break apart Apache log
files? We are doing out log file analysis on a separate machine and I
would like to find a Perl module to help me code a primitive log file
analysis program that will analyze log files as they are dumped to the
machine. Thanks - Dave
 
J

J. Gleixner

D. Alvarado said:
Can anyone recommend a module that I can use to break apart Apache log
files? We are doing out log file analysis on a separate machine and I
would like to find a Perl module to help me code a primitive log file
analysis program that will analyze log files as they are dumped to the
machine. Thanks - Dave

To find modules, start with CPAN:

http://search.cpan.org/

Apache::parseLog is probably what you're after.
 
M

Massi

More specifically, what would be the right module to generically parse
timestamps in any of these log files and do date arithmetic (ie. find
all lines from a specified time period)?

I'd like to put proper date parsing in the logwatch package
(http://www.logwatch.org/) and I'd like to use a date parser that's
generally available on most OS's that run syslog/Apache/BIND.

Try using Date::parse
I used in the past to generate a filtered "messages".
For example: I told the script to output me the messages generated in the
last xxx hours.
Here is a snippet of code:

#!/bin/perl -w
use Date::parse;
my $HoursBefore=24;
$HoursBefore=time()-($HoursBefore*3600); # transform in second
open(MESSFILE, "</var/log/syslog");
while (<MESSFILE>) {
my $date = /^(.+?\s.+?\s.+?\s)/
# transform in second ???? maybe. But I'm sure there is a way to do it.
# See POD file of the module.
my $dateNum = str2time($date);

if ($dateNum > $HoursBefore) {
.... positive command
} else {
.... negative commands
}
}
close MESSFILE;

This is something I resume from an old (and maybe not functioning)
script.

I never used to parse Apache/BIND logs ... but I think you can with some
trials.

Massi
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,008
Latest member
HaroldDark

Latest Threads

Top