summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul Buetow <paul@buetow.org>2023-01-07 01:20:41 +0200
committerPaul Buetow <paul@buetow.org>2023-01-07 01:20:41 +0200
commitbebd02423913b0586225088a798ab5e47d65d30f (patch)
treee9a905e4b8afc8e4eb058f3d544094c0e0e0fc75
parentbd20223f11aaedd9096b0dddcc8aaca50a3baf94 (diff)
skip line 1 of the syslog logs - also parse time from httpd logs
-rw-r--r--foostats.pl12
1 files changed, 7 insertions, 5 deletions
diff --git a/foostats.pl b/foostats.pl
index 0c8c595..f513bba 100644
--- a/foostats.pl
+++ b/foostats.pl
@@ -25,7 +25,7 @@ package Foostats::Tokenizer {
return ($ip_hash, $ip_proto);
}
- sub read_lines ($glob, $callback) {
+ sub read_lines ($glob, $callback, $skip_first_line = 1) {
my sub open_file ($path) {
my $flag = $path =~ /\.gz$/ ? '<:gzip' : '<';
open my $file, $flag, $path or die $!;
@@ -34,6 +34,7 @@ package Foostats::Tokenizer {
for my $path (glob $glob) {
my $file = open_file $path;
+ <$file> if $skip_first_line; # Contains 'logfile turned over' newsyslog message.
$callback->($path, split / +/) while <$file>;
close $file;
}
@@ -41,19 +42,20 @@ package Foostats::Tokenizer {
sub parse_www_logs ($callback) {
my sub parse_date ($date) {
- eval {
- Time::Piece->strptime($date, '[%d/%b/%Y:%H:%M:%S')->strftime('%Y-%m-%d')
- }
+ my $t = Time::Piece->strptime($date, '[%d/%b/%Y:%H:%M:%S');
+ ($t->strftime('%Y-%m-%d'), $t->strftime('%H:%M:%S'));
}
my sub parse_line (@line) {
my ($ip_hash, $ip_proto) = anonymize_ip $line[1];
+ my ($date, $time) = parse_date $line[4];
{
proto => 'http/s',
host => $line[0],
ip_hash => $ip_hash,
ip_proto => $ip_proto,
- date => parse_date($line[4]),
+ date => $date,
+ time => $time,
uripath => $line[7],
status => $line[9],
}