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 = '';
|
2013-01-29 12:33:13 +01:00
|
|
|
my $debug = 0;
|
|
|
|
my $version = 0;
|
2013-05-27 22:27:18 +02:00
|
|
|
my $build_date = '';
|
2013-05-29 01:03:58 +02:00
|
|
|
my $no_year_stat = 0;
|
2012-04-06 10:47:56 +02:00
|
|
|
|
|
|
|
# get the command line parameters
|
|
|
|
my $result = GetOptions (
|
|
|
|
"c|configfile=s" => \$configfile,
|
2013-05-27 22:27:18 +02:00
|
|
|
"b|build_date=s" => \$build_date,
|
2013-01-29 12:33:13 +01:00
|
|
|
"d|debug!" => \$debug,
|
2012-04-06 10:47:56 +02:00
|
|
|
"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,
|
2013-01-29 12:33:13 +01:00
|
|
|
"v|version!" => \$version,
|
2013-05-29 01:03:58 +02:00
|
|
|
"no-year-stat!" => \$no_year_stat,
|
2012-04-06 10:47:56 +02:00
|
|
|
);
|
|
|
|
|
2013-01-29 12:33:13 +01:00
|
|
|
# Show version and exit
|
|
|
|
if ($version) {
|
|
|
|
print "SquidAnalyzer version $SquidAnalyzer::VERSION\n";
|
|
|
|
exit 0;
|
|
|
|
}
|
|
|
|
|
2013-05-27 22:27:18 +02:00
|
|
|
if ($build_date) {
|
|
|
|
$rebuild = 1;
|
|
|
|
if ( ($build_date !~ /^\d{4}-\d{2}-\d{2}$/) && ($build_date !~ /^\d{4}-\d{2}$/) && ($build_date !~ /^\d{4}$/) ) {
|
|
|
|
die("FATAL: bad syntax for build_date, expecting format: yyyy-mm-dd, yyyy-mm or yyyy\n");
|
|
|
|
exit 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-05-29 16:27:56 +02:00
|
|
|
# Look at configuration file
|
|
|
|
if (!$configfile) {
|
|
|
|
# Backward compatibility with release < 4.0 with configuration
|
|
|
|
# file as single argument.
|
|
|
|
$configfile = $ARGV[0] if (($#ARGV == 0) && $ARGV[0]);
|
|
|
|
|
|
|
|
# Set default configuration file
|
|
|
|
$configfile ||= $DEFAULT_CONFFILE;
|
2012-04-06 10:47:56 +02:00
|
|
|
}
|
|
|
|
|
2013-05-29 16:27:56 +02:00
|
|
|
if ($help) {
|
2012-04-06 10:47:56 +02:00
|
|
|
&usage;
|
|
|
|
exit;
|
|
|
|
}
|
|
|
|
|
|
|
|
# Instanciate SquidAnalyzer.pm perl module
|
2013-05-27 22:27:18 +02:00
|
|
|
my $sa = new SquidAnalyzer($configfile, $logfile, $debug, $rebuild);
|
2012-04-06 10:47:56 +02:00
|
|
|
|
2013-05-29 01:03:58 +02:00
|
|
|
$sa->{no_year_stat} = $no_year_stat;
|
|
|
|
|
2013-05-27 22:27:18 +02:00
|
|
|
# Run parsing only if we have a log file or that we are not in rebuild mode
|
|
|
|
$sa->parseFile() if (!$rebuild || $logfile);
|
2012-04-06 10:47:56 +02:00
|
|
|
|
2013-01-29 12:19:07 +01:00
|
|
|
# Remove old statistics
|
|
|
|
if ($preserve) {
|
|
|
|
$sa->{preserve} = $preserve;
|
|
|
|
}
|
|
|
|
|
2013-05-27 22:27:18 +02:00
|
|
|
# In rebuild mode history time is not use and we must store the
|
|
|
|
# specific rebuild date if any is provided at command line.
|
2012-04-06 10:47:56 +02:00
|
|
|
if ($rebuild) {
|
|
|
|
$sa->{history_time} = '';
|
2013-05-27 22:27:18 +02:00
|
|
|
$sa->{build_date} = $build_date;
|
2012-04-06 10:47:56 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
# 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.
|
2014-02-14 11:41:52 +01:00
|
|
|
By default: $DEFAULT_CONFFILE
|
2013-05-27 22:27:18 +02:00
|
|
|
-b | --build_date date : set the date to be rebuilt, format: yyyy-mm-dd
|
|
|
|
or yyyy-mm or yyyy. Used with -r or --rebuild.
|
2013-01-29 12:33:13 +01:00
|
|
|
-d | --debug : show debug informations.
|
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.
|
2013-01-29 12:33:13 +01:00
|
|
|
-v | version : show version and exit.
|
2013-09-01 21:42:33 +02:00
|
|
|
--no-year-stat : disable years statistics, reports will start
|
|
|
|
from month level only.
|
2012-04-06 10:47:56 +02:00
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
exit 0;
|
|
|
|
}
|
|
|
|
|