ipacsum fix

Home

The first fix is more a side issue I came across when trying to figure out why my Linux firewall was clogging up with logs. Because I don't leave my firewall up and running twenty four seven or even when the summarising is scheduled to be kicked off at, literally thousands of separate logs started to pile up and there was nothing to catch them except for the next cron job rule which was just as likely to be missed.

The following code is designed to catch missed logs when ipacsum is run in relative mode ie. "the day 7 days ago".

The only two issues I see with the code is that I have not included any way to explicitly NOT run the code (may be an issue for some people/cases), secondly the routine works recursively so it is a little memory hungry.

The entire script is available here. Text file is in UNIX/Linux format.

For an additional script I wrote to be used on machines that are only switched on when intended to be used see this. As comments state in script, call script (with low priority) from some start up script and problem solvered.

Side issue

I believe the start and end times were not being adjusted for day light saving. (Was this deliberate?)

In subroutine set_time_frame
For the if blocks day, week, month & year add the following statements where they're the last statments in the block...

$starttime += (localtime($starttime))[2]?3600:0;
$endtime += (localtime($endtime))[2]?3600:0;

Proposed additions

The spot changes

Add...

push(@files_before, $file) if($file le $mystarttime && $file =~ /\d{8}-\d{6}/);

before...

next if ($file le $mystarttime || $file gt $myendtime);

Change...

push(@files, $file);

to...

push(@files, $file) if($file =~ /\d{8}-\d{6}/);

After...

@files = sort @files;

add...

@files_before = sort @files_before;

Now for the bulk

Add following straight after "@files_before = sort @files_before;" line just added.

if(defined(@files_before) && $starttime_explicit && $endtime_explicit){
   my $r_opt=$replace?'-r':'';
   if($opt_t=~/hour/i){
      my($hr,$done)=('0','0');
      foreach(@files_before){
         $_=~/(\d{8})-(\d\d)/;
         if($hr eq ($1.$2) && $done ne ($1.$2)){
            $done=$1.$2;
            makemytime(makeunixtime($hr)+3600)=~/(\d{4})(\d\d)(\d\d)-(\d\d)/;
            system(sprintf('%s %s -s %s0000 -e %s0000',$0,$r_opt,$hr,$1.$2.$3.$4));
         }
         $hr=length($1.$2)==10?($1.$2):$done;
      }
   }elsif($opt_t=~/day/i){
      my($dy,$done)=('0','0');
      foreach(@files_before){
         $_=~/(\d{8})/;
         if($dy eq $1 && $done ne $1){
            $done=$1;
            makemytime(makeunixtime($dy)+86400)=~/(\d{4})(\d\d)(\d\d)/;
            system(sprintf('%s %s -s %s000000 -e %s000000',$0,$r_opt,$dy,$1.$2.$3));
         }
         $dy=length($1)==8?$1:$done;
      }
   }elsif($opt_t=~/week/i){
      my($wk,$done)=('0','0');
      my $tmp;
      foreach(@files_before){
         $_=~/(\d{8})/;
         $tmp=makeunixtime($1.'000000');
         makemytime($tmp-(((localtime($tmp))[6]-1)%7)*86400)=~/(\d{8})/;
         if($wk eq $1 && $done ne $1){
            $done=$1;
            makemytime(makeunixtime($wk)+604800)=~/(\d{4})(\d\d)(\d\d)/;
            system(sprintf('%s %s -s %s000000 -e %s000000',$0,$r_opt,$wk,$1.$2.$3));
         }
         $wk=length($1)==8?$1:$done;
      }
   }elsif($opt_t=~/month/i){
      my($mon,$done)=('0','0');
      my($year,$month);
      foreach(@files_before){
         $_=~/(\d{6})/;
         if($mon eq $1 && $done ne $1){
            $done=$1;
            $year=int(substr($mon,0,4));
            $month=int(substr($mon,4,2))+1;
            $year+=int($month/12);
            $month%=12;
            system(sprintf('%s %s -s %s01000000 -e %d%02d01000000',$0,$r_opt,$mon,$year,$month));
         }
         $mon=$1;
      }
   }elsif($opt_t=~/year/i){
      my($yr,$done)=('0','0');
      foreach(@files_before){
         $_=~/(\d{4})/;
         if($yr eq $1 && $done ne $1){
            $done=$1;
            system(sprintf('%s %s -s %s0101000000 -e %d0101000000',$0,$r_opt,$yr,int($yr)+1));
         }
         $yr=$1;
      }
   }
}

Page last modified: Unknown since javascript not enabled

1