IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 17271


Ignore:
Timestamp:
Apr 1, 2008, 4:10:55 PM (18 years ago)
Author:
jhoblitt
Message:

fix identification of the latest timestamp in the db

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/arclog/arclog.pl

    r17269 r17271  
    9595}
    9696
     97# figure out the last record that we saw
     98# since the order in the sqllite db isn't guarenteed and we can't sort in the
     99# db, we have to do this by hand
     100my $last_recorded_time;
     101{
     102    my $strptime = DateTime::Format::Strptime->new(
     103        pattern => '%Y-%m-%dT%H:%M:%S'
     104    );
     105
     106    # read in the entire database
     107    my $query = $dbh->prepare("SELECT * FROM log")
     108    or die "database error: $!";
     109    $query->execute or die "database error: $!";
     110    my $records = $query->fetchall_arrayref;
     111
     112    # sort it for the latest timestamp
     113    foreach my $rec (@$records) {
     114        my ($host, $time, $device, $event, $elapse_time, $errors)
     115            = split(/\|/, $rec->[0]);
     116
     117        my $dt = $strptime->parse_datetime($time);
     118
     119        if (! defined $last_recorded_time) {
     120            $last_recorded_time = $dt;
     121        } elsif ($dt > $last_recorded_time) {
     122            $last_recorded_time = $dt;
     123        }
     124
     125    }
     126
     127#    warn "latest timestamp is: $last_recorded_time\n";
     128
     129    unless (defined $last_recorded_time) {
     130        warn "failed to determine the time of the last recorded record\n";
     131    }
     132}
     133
    97134#use Data::Dumper;
    98135#print Dumper(\@records);
     
    120157        next RECORDS if $event =~ /$filter/;
    121158    }
    122     print "$host $time $device $event $elapse_time $errors\n";
     159   
     160    if ($time > $last_recorded_time) {
     161        print "$host $time $device $event $elapse_time $errors\n";
     162    }
    123163
    124164    use warnings;
Note: See TracChangeset for help on using the changeset viewer.