2008-Feb-01 00:00:02 UTC (GMT +0000) - id = 000000001, Status = failed
2008-Feb-01 00:10:02 UTC (GMT +0000) - id = 000000002, Status = success
2008-Feb-01 00:20:02 UTC (GMT +0000) - id = 000000003, Status = failed
2008-Feb-01 00:30:02 UTC (GMT +0000) - id = 000000004, Status = success
2008-Feb-01 00:40:02 UTC (GMT +0000) - id = 000000001, Status = success
2008-Feb-01 00:50:02 UTC (GMT +0000) - id = 000000001, Status = success
2008-Feb-01 01:00:02 UTC (GMT +0000) - id = 000000001, Status = failed
2008-Feb-01 01:10:02 UTC (GMT +0000) - id = 000000007, Status = success
2008-Feb-01 01:20:02 UTC (GMT +0000) - id = 000000003, Status = failed
2008-Feb-01 01:30:02 UTC (GMT +0000) - id = 000000009, Status = success
####
ID last attempted attempts
============================================================
000000001 2008-Feb-01 01:00:02 1
000000003 2008-Feb-01 01:20:02 1
####
use strict;
use warnings;
use DateTime::Format::Strptime;
# my $Strp = new DateTime::Format::Strptime(pattern => '%Y-%b-%d %T',);
my $Strp = new DateTime::Format::Strptime(pattern => '%Y-%b-%d %T', on_error => 'croak');
my $infile = 'ReadLog.txt';
my $outfile = 'ReportLog.txt';
my($fh_out, $fh);
my %lookup;
my $status = 'failed';
my $time_delta = 3600; # seconds = 1 hour
open($fh_out, '>', $outfile) or die "Could not open outfile: $!";
open($fh, '<', $infile) or die "Could not open logfile: $!";
while (<$fh>) {
next unless /$status/;
$_ =~ m/^(.*) UTC.*refs = (\d+)$/;
# my $dt = $Strp->parse_datetime("$1");
unless (my $dt = $Strp->parse_datetime($1))
{
warn "invalid datetime: $1";
next;
}
my $timestamp = $dt ->epoch();
my $refs = "$2";
if ( defined($lookup{$refs}) && $lookup{$refs} + $time_delta <= $timestamp ) {
print $fh_out "REFS $refs: occurrences at " . $lookup{$refs} . "and $timestamp \n";
print "REFS $refs: occurrences at " . $lookup{$refs} . " and $timestamp \n";
}
$lookup{$refs} = $timestamp;
}
close $fh_out;
#close $fh;