Add two new command line options to force file to be parsed from begining even

if an history file is present:
    --skip-history             : used to not take care of the history file. Log
                                 parsing offset will start at 0 but old history
                                 file will be preserved at end. Useful if you
                                 want to parse and old log file.
    --override-history         : when skip-history is used the current history
                                 file will be overriden by the offset of the
                                 last log file parsed.
Thanks to zeft2016 for the feature request.
This commit is contained in:
Gilles Darold 2018-01-28 15:37:32 +01:00
parent a8e60374a5
commit 4f0b3a713b
4 changed files with 38 additions and 6 deletions

7
README
View File

@ -185,6 +185,13 @@ USAGE
--with-month-stat : enable month stats when --no-year-stat is used.
--startdate YYYYMMDDHHMMSS : lines before this datetime will not be parsed.
--stopdate YYYYMMDDHHMMSS : lines after this datetime will not be parsed.
--skip-history : used to not take care of the history file. Log
parsing offset will start at 0 but old history
file will be preserved at end. Useful if you
want to parse and old log file.
--override-history : when skip-history is used the current history
file will be overriden by the offset of the
last log file parsed.
Log files to parse can be given as command line arguments or as a comma
separated list of file for the LogFile configuration directive. By

View File

@ -872,7 +872,7 @@ sub parseFile
}
# Set the current start time into history file
$self->save_current_line();
$self->save_current_line() if (!$self->{SkipHistory} || $self->{OverrideHistory});
# Force reordering and unique sorting of data files
my $child_count = 0;
@ -1523,7 +1523,7 @@ sub _clear_stats
sub _init
{
my ($self, $conf_file, $log_file, $debug, $rebuild, $pid_dir, $pidfile, $timezone) = @_;
my ($self, $conf_file, $log_file, $debug, $rebuild, $pid_dir, $pidfile, $timezone, $skip_history) = @_;
# Set path to pid file
$pidfile = $pid_dir . '/' . $pidfile;
@ -1590,6 +1590,8 @@ sub _init
$self->{UseUrlPort} = 1;
$self->{TimeStart} = $options{TimeStart} || '';
$self->{TimeStop} = $options{TimeStop} || '';
$self->{SkipHistory} = $skip_history || 0;
$self->{OverrideHistory} = 0;
# Cleanup old temporary files
foreach my $tmp_file ('last_parsed.tmp', 'sg_last_parsed.tmp', 'ug_last_parsed.tmp') {
@ -1719,7 +1721,7 @@ sub _init
}
# Get the last parsing date for Squid log incremental parsing
if (!$rebuild && -e "$self->{Output}/SquidAnalyzer.current") {
if (!$rebuild && !$self->{SkipHistory} && -e "$self->{Output}/SquidAnalyzer.current") {
my $current = new IO::File;
unless($current->open("$self->{Output}/SquidAnalyzer.current")) {
print STDERR "ERROR: Can't read file $self->{Output}/SquidAnalyzer.current, $!\n" if (!$self->{QuietMode});
@ -1737,7 +1739,7 @@ sub _init
}
# Get the last parsing date for SquidGuard log incremental parsing
if (!$rebuild && -e "$self->{Output}/SquidGuard.current") {
if (!$rebuild && !$self->{SkipHistory} && -e "$self->{Output}/SquidGuard.current") {
my $current = new IO::File;
unless($current->open("$self->{Output}/SquidGuard.current")) {
print STDERR "ERROR: Can't read file $self->{Output}/SquidGuard.current, $!\n" if (!$self->{QuietMode});
@ -1755,7 +1757,7 @@ sub _init
}
# Get the last parsing date for ufdbGuard log incremental parsing
if (!$rebuild && -e "$self->{Output}/ufdbGuard.current") {
if (!$rebuild && !$self->{SkipHistory} && -e "$self->{Output}/ufdbGuard.current") {
my $current = new IO::File;
unless($current->open("$self->{Output}/ufdbGuard.current")) {
print STDERR "ERROR: Can't read file $self->{Output}/ufdbGuard.current, $!\n" if (!$self->{QuietMode});

View File

@ -189,6 +189,13 @@ Usage: squid-analyzer [ -c squidanalyzer.conf ] [logfile(s)]
--with-month-stat : enable month stats when --no-year-stat is used.
--startdate YYYYMMDDHHMMSS : lines before this datetime will not be parsed.
--stopdate YYYYMMDDHHMMSS : lines after this datetime will not be parsed.
--skip-history : used to not take care of the history file. Log
parsing offset will start at 0 but old history
file will be preserved at end. Useful if you
want to parse and old log file.
--override-history : when skip-history is used the current history
file will be overriden by the offset of the
last log file parsed.
Log files to parse can be given as command line arguments or as a comma separated
list of file for the LogFile configuration directive. By default SquidAnalyer will

View File

@ -35,6 +35,8 @@ my $stop_time = '';
my $start_date = '';
my $stop_date = '';
my $outputdir = '';
my $skip_history = 0;
my $override_history = 0;
# get the command line parameters
my $result = GetOptions (
@ -57,6 +59,8 @@ my $result = GetOptions (
"with-month-stat!" => \$with_month_stat,
"startdate=s" => \$start_date,
"stopdate=s" => \$stop_date,
"skip-history!" => \$skip_history,
"override-history!" => \$override_history,
);
# Show warning for obsolete options
@ -93,6 +97,10 @@ if ($stop_date && $stop_date !~ /^\d{4}[-\\\/]?[0-1]\d[-\\\/]?[0-3]\d\s*[0-2]\d[
}
$stop_date =~ s/[-\\\/:\s]//g if ($stop_date);
if ($override_history and ! $skip_history) {
die("FATAL: --override-history option can be used only with --skip-history.\nSee usage (--help) for more information.\n");
}
# Add multiple log files given from command line
foreach my $f (@ARGV) {
push(@logfile, $f) if (-f $f && !-z $f);
@ -120,13 +128,14 @@ close(OUT);
unlink("$pid_dir/last_parsed.tmp");
# Instanciate SquidAnalyzer.pm perl module
my $sa = new SquidAnalyzer($configfile, join(',', @logfile), $debug, $rebuild, $pid_dir, $pidfile, $timezone);
my $sa = new SquidAnalyzer($configfile, join(',', @logfile), $debug, $rebuild, $pid_dir, $pidfile, $timezone, $skip_history);
$sa->{no_year_stat} = $no_year_stat;
$sa->{with_month_stat} = $with_month_stat;
$sa->{no_week_stat} = $no_week_stat;
$sa->{queue_size} = $queue_size;
$sa->{TimeStart} = $start_time;
$sa->{TimeStop} = $stop_time;
$sa->{OverrideHistory} = $override_history;
# Set start and end time (for custom date range reports)
if ($start_date && $start_date =~ /^(\d{4})(\d\d)(\d\d)(\d\d)(\d\d)(\d\d)/) {
@ -269,6 +278,13 @@ Usage: squid-analyzer [ -c squidanalyzer.conf ] [logfile(s)]
--with-month-stat : enable month stats when --no-year-stat is used.
--startdate YYYYMMDDHHMMSS : lines before this datetime will not be parsed.
--stopdate YYYYMMDDHHMMSS : lines after this datetime will not be parsed.
--skip-history : used to not take care of the history file. Log
parsing offset will start at 0 but old history
file will be preserved at end. Useful if you
want to parse and old log file.
--override-history : when skip-history is used the current history
file will be overriden by the offset of the
last log file parsed.
Log files to parse can be given as command line arguments or as a comma separated
list of file for the LogFile configuration directive. By default SquidAnalyer will