2012-04-06 10:47:56 +02:00
|
|
|
#!/usr/bin/perl
|
|
|
|
#
|
|
|
|
# Perl frontend to SquidAnalyzer.pm.
|
|
|
|
#
|
|
|
|
use strict;
|
|
|
|
use SquidAnalyzer;
|
|
|
|
use Getopt::Long;
|
|
|
|
|
|
|
|
$| = 1;
|
|
|
|
|
|
|
|
my $DEFAULT_CONFFILE = '/etc/squidanalyzer/squidanalyzer.conf';
|
|
|
|
|
2013-01-29 12:19:07 +01:00
|
|
|
my $logfile = '';
|
2012-04-06 10:47:56 +02:00
|
|
|
my $configfile = '';
|
2013-01-29 12:19:07 +01:00
|
|
|
my $help = '';
|
|
|
|
my $rebuild = '';
|
|
|
|
my $preserve = '';
|
2012-04-06 10:47:56 +02:00
|
|
|
|
|
|
|
# get the command line parameters
|
|
|
|
my $result = GetOptions (
|
|
|
|
"c|configfile=s" => \$configfile,
|
|
|
|
"h|help" => \$help,
|
2013-01-29 12:19:07 +01:00
|
|
|
"l|logfile=s" => \$logfile,
|
2012-04-06 10:47:56 +02:00
|
|
|
"r|rebuild!" => \$rebuild,
|
2013-01-29 12:19:07 +01:00
|
|
|
"p|preserve=i" => \$preserve,
|
2012-04-06 10:47:56 +02:00
|
|
|
);
|
|
|
|
|
2012-04-06 11:07:52 +02:00
|
|
|
# Allow backward compatibility with release < 4.0
|
2012-04-06 10:47:56 +02:00
|
|
|
$configfile = $ARGV[0] if (($#ARGV == 0) && $ARGV[0]);
|
|
|
|
if (($#ARGV < 0) && -e $DEFAULT_CONFFILE) {
|
|
|
|
$configfile = $DEFAULT_CONFFILE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!$configfile || $help) {
|
|
|
|
&usage;
|
|
|
|
exit;
|
|
|
|
}
|
|
|
|
|
|
|
|
# Instanciate SquidAnalyzer.pm perl module
|
|
|
|
my $sa = new SquidAnalyzer($configfile, $logfile);
|
|
|
|
|
|
|
|
# Run parsing
|
|
|
|
$sa->parseFile();
|
|
|
|
|
2013-01-29 12:19:07 +01:00
|
|
|
# Remove old statistics
|
|
|
|
if ($preserve) {
|
|
|
|
$sa->{preserve} = $preserve;
|
|
|
|
}
|
|
|
|
|
2012-04-06 10:47:56 +02:00
|
|
|
# Recover month and year statistics from day stats
|
|
|
|
if ($rebuild) {
|
|
|
|
$sa->{history_time} = '';
|
|
|
|
}
|
|
|
|
|
|
|
|
# Generate graphics and html
|
|
|
|
$sa->buildHTML();
|
|
|
|
|
|
|
|
exit(0);
|
|
|
|
|
|
|
|
|
|
|
|
sub usage
|
|
|
|
{
|
|
|
|
print qq{
|
|
|
|
Usage: squid-analyzer [ -c squidanalyzer.conf ] [-l logfile]
|
|
|
|
|
|
|
|
-c | --configfile filename : path to the SquidAnalyzer configuration file.
|
|
|
|
By default: /etc/squidanalyzer.conf
|
2013-01-29 12:19:07 +01:00
|
|
|
-h | --help : show this message and exit.
|
|
|
|
-l | --logfile filename : path to the Squid logfile to parse.
|
|
|
|
By default: /var/log/squid/access.log
|
|
|
|
-p | --preserve number : used to set the statistic obsolescence in
|
|
|
|
number of month. Older stats will be removed.
|
2012-04-06 10:47:56 +02:00
|
|
|
-r | --rebuild : use this option to rebuild all html and graphs
|
|
|
|
output from all data files.
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
exit 0;
|
|
|
|
}
|
|
|
|
|