#!/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] [-h history_days] [-c computing_days] [date-spec]";
#
#=============================================================================
@BigSister::common::options = ( "c=i", "h=i" );

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

$BigSister::common::opt_h = 2;

proginit();

use strict;

my $dl = $BigSister::common::dl;
my $when = shift;

my $dir = "$BigSister::common::fs{'bin'}";
my $confdir = "$BigSister::common::fs{'adm'}/reporting";
my $reader = "$dir/report_read";
my $consolidater = "$dir/report_consolidate";

my $historydays = $BigSister::common::opt_h;
my $computingdays = (defined $BigSister::common::opt_c)?$BigSister::common::opt_c:(($historydays>10)?$historydays:10);

for( my $back = $historydays; $back > 0; $back-- ) {
    my $date = $when?$when:"- $back days";
    system( $reader, "-d", $date, "DisplayHistory" );
    system( $reader, "-d", $date, "ServiceHours",	"file=$confdir/servicehours" );
    system( $reader, "-d", $date, "Holidays",		"file=$confdir/holidays" );
    last if( $when );
}

for( my $back = $computingdays; $back > 0; $back-- ) {
    my $date = $when?$when:"- $back days";
    system( $reader, "-d", $date, "ManualOverride",	"file=$confdir/override" );
    system( $reader, "-d", $date, "Dependency",		"file=$confdir/dependencies" );
    system( $reader, "-d", $date, "Cumulator",		"file=$confdir/cumulators" );
    system( $consolidater, "-d", $date,			"$confdir/statistics" );
    last if( $when );
}

