# 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;
($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: $!";
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...
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 ".";
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 ".";
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: $!";
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) ) {
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: $!";
}