#!/usr/bin/perl

#    Big Sister network monitor
#    Copyright (C) 1998-2001  Thomas Aeby
#
#    This program is free software; you can redistribute it and/or modify
#    it under the terms of the GNU General Public License as published by
#    the Free Software Foundation; either version 2 of the License, or
#    (at your option) any later version.
#
#    This program is distributed in the hope that it will be useful,
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#    GNU General Public License for more details.
#
#    You should have received a copy of the GNU General Public License
#    along with this program; if not, write to the Free Software
#    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
#

#=============================================================================
#
$BigSister::common::Usage	  = "[-D level] [-d date] reader [args]";
#
#=============================================================================
@BigSister::common::options = ( "d=s" );

use lib "."; use lib "uxmon"; use lib "platforms"; 		#inslib
use BigSister::common;
proginit();

use strict;
use RotatingLog;
use Time::Local;
use Reader::Reader;
use StatusLog;
use ReportCommon;

my $dl = $BigSister::common::dl;
my $reader = shift;
my ($start_time, $end_time) = ReportCommon::start_date( $BigSister::common::opt_d );

my( $mday, $mon, $year ) = ((localtime($start_time))[3,4,5]);
print sprintf( "reading %s for %02d.%02d.%04d\n", $reader, $mday, $mon+1, $year +1900 );

my $reader_args = {
    "start" => $start_time,
    "end" => $end_time,
    "args" => \@ARGV
};

foreach my $arg (@ARGV) {
    if( $arg =~/^(.*?)=(.*)$/ ) {
	$reader_args->{$1} = $2;
    }
}

my $log = Reader::Reader::create( $reader, $reader_args )->read();
$reader_args->{"args"} = [];
my $dbreader = Reader::Reader::create( "StatusDB", $reader_args );
my $former = $dbreader->read();

foreach my $item ($log->get_items()) {
    my $bla = $log->get( $item );
    if( $bla && @$bla ) {
	$former->put( $item, $log->get( $item ) );
    }
    else {
	$former->delete( $item );
    }
}

$dbreader->dump( $former ); 


