1) Apache Web server
<code>
apt-get install apache2
</code>
It serves pages from folder : /var/www
<code>
head /etc/apache2/sites-available/default
<VirtualHost *:80>
ServerAdmin webmaster@localhost
DocumentRoot /var/www
</code>
create folder :
<code>
mkdir -p /var/www/sarg
</code>
2) SARG
<code>
apt-get install sarg
</code>
edit sarg conf file : /etc/sarg/sarg.conf
and change the following lines, the last only if you use dansguardian :
<code>
access_log /var/log/squid3/access.log
date_format e
output_dir /var/www/sarg
#
dansguardian_conf /etc/dansguardian/dansguardian.conf
</code>
3) SARG Report
configure sarg report, here it' in french
<code>
cat <<EOF>/etc/sarg/sarg-reports.conf
SARG=/usr/bin/sarg
CONFIG=/etc/sarg/sarg.conf
HTMLOUT=/var/www/sarg
PAGETITLE="Statitics Proxy $(hostname)"
LOGOIMG=/sarg/images/sarg.png
LOGOLINK="http://$(hostname)/"
DAILY=Jour
WEEKLY=Semaine
MONTHLY=Mois
EXCLUDELOG1="SARG: Pas d enregistrement trouvé"
EXCLUDELOG2="SARG: Fin"
EOF
</code>
modify the lines contanint $SARG to add the log floder "/var/log/squid3/access.log*" in the script /usr/sbin/sarg-reports
to have :
<code>
grep \$SARG sarg-reports
$SARG -f $CONFIG -d $MANUALDATE -o $DAILYOUT /var/log/squid3/access.log*
$SARG -f $CONFIG -d $TODAY -o $DAILYOUT /var/log/squid3/access.log* >$ERRORS 2>&1
$SARG -f $CONFIG -d day-1 -o $DAILYOUT /var/log/squid3/access.log* >$ERRORS 2>&1
$SARG -f $CONFIG -d week-1 -o $WEEKLYOUT /var/log/squid3/access.log* >$ERRORS 2>&1
$SARG -f $CONFIG -d month-1 -o $MONTHLYOUT /var/log/squid3/access.log* >$ERRORS 2>&1
</code>
4) generate report manually
<code>
/usr/sbin/sarg-reports daily
/usr/sbin/sarg-reports weekly
/usr/sbin/sarg-reports monthly
</code>
there are un /var/www/sarg/
5) automate report generation with cron
edit root crontab and add the following lines :
<code>
crontab -e
@daily /usr/sbin/sarg-reports daily
0 01 * * 1 /usr/sbin/sarg-reports weekly
03 01 1 * * /usr/sbin/sarg-reports monthly
service cron restart
</code>
6) Logrotate
change logroate to only rotate logs monthly so we keep information for SARG
For Squid
<code>
sed -i 's/daily/monthly/' /etc/logrotate.d/squid3
</code>
For Dansguardian :
<code>
cat<<EOF>/etc/logrotate.d/dansguardian
/var/log/dansguardian/access.log {
rotate 12
monthly
compress
delaycompress
prerotate
/etc/init.d/dansguardian stop > /dev/null 2>&1 || true
/usr/sbin/sarg-reports weekly > /dev/null 2>&1 || true
/usr/sbin/sarg-reports monthly > /dev/null 2>&1 || true
endscript
postrotate
/etc/init.d/dansguardian start > /dev/null 2>&1
endscript
}
EOF
<code>