From 7158637fed495b1bf1025cb792498025ec241784 Mon Sep 17 00:00:00 2001 From: Stephen L Johnson Date: Tue, 17 Dec 2002 21:31:21 +0000 Subject: [PATCH] new history achive format to handle history status event files --- src/spong-cleanup.pl | 55 ++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 51 insertions(+), 4 deletions(-) diff --git a/src/spong-cleanup.pl b/src/spong-cleanup.pl index c412c31..76bf247 100755 --- a/src/spong-cleanup.pl +++ b/src/spong-cleanup.pl @@ -1,4 +1,4 @@ -#!@@PERL@@ +#!/usr/bin/perl # # This program performs nightly maintanence to the spong database. # @@ -19,7 +19,7 @@ # History: # (1) Created (Ed Hill, 06/17/1998) # -# $Id: spong-cleanup.pl,v 1.6 2000/10/16 15:34:32 sljohnson Exp $ +# $Id: spong-cleanup.pl,v 1.7 2002/12/17 21:31:21 sljohnson Exp $ use POSIX; use Socket; @@ -46,6 +46,7 @@ while( $host = readdir( DIR ) ) { &remove_old_acks( $host ); &remove_old_services( $host ); &remove_old_history( $host ); # Yes, I suppose all history is old... + &remove_old_events( $host ); # Old event status data } closedir( DIR ); @@ -116,10 +117,20 @@ sub remove_old_services { sub remove_old_history { my( $host ) = @_; my $file = "$main::SPONGDB/$host/history/current"; - my $archive = "$main::SPONG_ARCHIVE/$host"; + my $archive = "$main::SPONG_ARCHIVE/$host/history"; return if ! -f $file; + if ( -f "$main::SPONG_ARCHIVE/$host" ) { + warn "Refusing to overwrite $host archive file, please the run convert-history Spong utility"; + return; + } + + if ( ! -d "$main::SPONG_ARCHIVE/$host" ) { + system "mkdir $main::SPONG_ARCHIVE/$host" || die "Could not mkdir $main::SPONG_ARCHIVE/$host : $!"; + } + + open( HISTORY, $file ) || die "Can't open $file: $!"; open( ARCHIVE, ">> $archive" ) || die "Can't open $archive: $!"; open( NEW, "> $file.new" ) || die "Can't create $file.new: $!"; @@ -146,7 +157,43 @@ sub remove_old_history { system( "cp $file.new $file && rm $file.new" ); } - + +# This function scans through all of the event status of the given host, +# and moved old event status files older then N days to the host's archive + +sub remove_old_events { + my ( $host ) = @_; + my ( $eventdir ) = "$main::SPONGDB/$host/history/status"; + my ( $archdir ) = "$main::SPONG_ARCHIVE/$host/status"; + + + return if ! -d $eventdir; + + if ( -f "$main::SPONG_ARCHIVE/$host" ) { + warn "Refusing to overwrite $host archive file, please the run convert-history Spong utility"; + return; + } + + if ( ! -d $archdir ) { + system "mkdir -p $archdir" || die "Could not mkdir $archdir : $!"; + } + + opendir( STDIR,$eventdir ) || die "Could not opendir $eventdir: $!"; + + while( my $file = readdir(STDIR) ) { + next if $file =~ /^\./ || $file =~ /^\.\./ ; # Skip . and .. dirs + + my( $stamp ) = ( $file =~ /^(\d+)-/ ); # Get the event timestamp + + if ( $time < (time() - ($main::OLD_HISTORY * 24*60*60)) ) { + system "mv $eventdir/$file $archdir/$file" || + die "Could not mv $event/$file to $archdir/$file: $!"; + } + } + + closedir(STDIR); + +} # This function just loads in all the configuration information from the # spong.conf. The spong.hosts and spong.group files are not needed - all the -- 2.30.2