From: Stephen L Johnson Date: Sun, 27 Jul 2003 03:04:27 +0000 (+0000) Subject: fixed time comparison problem in remove_old_events() and added -v flag for verbose... X-Git-Tag: spong-2_8_0-beta1~31 X-Git-Url: http://git.etc.gen.nz/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=19a5520ae7d69f5cf241fed7cd383c61ca1d9678;p=spong.git fixed time comparison problem in remove_old_events() and added -v flag for verbose output --- diff --git a/src/spong-cleanup.pl b/src/spong-cleanup.pl index 76bf247..920a69a 100755 --- a/src/spong-cleanup.pl +++ b/src/spong-cleanup.pl @@ -19,7 +19,7 @@ # History: # (1) Created (Ed Hill, 06/17/1998) # -# $Id: spong-cleanup.pl,v 1.7 2002/12/17 21:31:21 sljohnson Exp $ +# $Id: spong-cleanup.pl,v 1.8 2003/07/27 03:04:27 sljohnson Exp $ use POSIX; use Socket; @@ -36,6 +36,15 @@ $groups_file = "@@ETCDIR@@/spong.groups"; ($HOST) = gethostbyname(&Sys::Hostname::hostname()); $HOST =~ tr/A-Z/a-z/; +if ($#ARGV > -1) { + if ( $ARGV[0] ne '-v' ) { + print "Invalid parameter. Usage:\n\n spong-clean [-v] \n\n"; + } + else { + $VERBOSE = 1; + } +} + &load_config_files(); # Loads the user specified configuration information opendir( DIR, $main::SPONGDB ) || die "Can't open $main::SPONGDB: $!"; @@ -43,6 +52,8 @@ while( $host = readdir( DIR ) ) { next if $host eq "."; next if $host eq ".."; + print "Cleaning out host $host...\n" if $VERBOSE; + &remove_old_acks( $host ); &remove_old_services( $host ); &remove_old_history( $host ); # Yes, I suppose all history is old... @@ -63,6 +74,8 @@ sub remove_old_acks { return if ! -d $dir; + print " deleting old acks\n" if $VERBOSE; + opendir( ACK, $dir ) || die "Can't open $dir: $!"; while( $ack = readdir( ACK ) ) { next if $ack eq "."; @@ -96,6 +109,8 @@ sub remove_old_services { return if ! -d $dir; + print " deleting stale old status entries\n" if $VERBOSE; + opendir( SERVICE, $dir ) || die "Can't open $dir: $!"; while( $service = readdir( SERVICE ) ) { next if $service eq "."; @@ -130,6 +145,8 @@ sub remove_old_history { system "mkdir $main::SPONG_ARCHIVE/$host" || die "Could not mkdir $main::SPONG_ARCHIVE/$host : $!"; } + print " trimming history log files\n" if $VERBOSE; + open( HISTORY, $file ) || die "Can't open $file: $!"; open( ARCHIVE, ">> $archive" ) || die "Can't open $archive: $!"; @@ -178,6 +195,8 @@ sub remove_old_events { system "mkdir -p $archdir" || die "Could not mkdir $archdir : $!"; } + print " moving old history status files to archive\n" if $VERBOSE; + opendir( STDIR,$eventdir ) || die "Could not opendir $eventdir: $!"; while( my $file = readdir(STDIR) ) { @@ -185,7 +204,7 @@ sub remove_old_events { my( $stamp ) = ( $file =~ /^(\d+)-/ ); # Get the event timestamp - if ( $time < (time() - ($main::OLD_HISTORY * 24*60*60)) ) { + if ( $stamp < (time() - ($main::OLD_HISTORY * 24*60*60)) ) { system "mv $eventdir/$file $archdir/$file" || die "Could not mv $event/$file to $archdir/$file: $!"; }