Package: sarg
Version: 2.3.6-1+b1
Severity: normal
Tags: patch

sarg-reports is a very useful script called by sarg script in 
cron.{daily,weekly,monthly}
to create Squid analysis reports under the respective Daily, Weekly, or Monthly 
directory.

However, as the warning in the script says, logrotate needs to be
applied only AFTER the monthly report is generated.

This is unacceptable since the access log after a month will have grown
to a very large size, and regardless the logrotate shipped with sarg
specifies weekly rotation, so a monthly report is NEVER generated in
the unmodified Debian installation.

However for quite some time, sarg supports multiple input log files
and these can even be in compressed format, so a simple modification
to the sarg-reports script results in Daily, Weekly, and Monthly
reports generated from multiple files including the compressed ones.

This patch also allows the passing of additional parameters, if desired,
using the "${@}" shell parameter to the respective functions.

The patch assumes that the rotated log files are variations on the
access log file specified with access_log in /etc/sarg/sarg.conf, eg

access_log /var/log/squid3/access.log

and the logrotate files will match this path with a wildcard "*" appended, eg

ll /var/log/squid3/access.log*
1436 -rw-r----- 1 proxy proxy 1463629 2016-03-17 00:12 
/var/log/squid3/access.log
 528 -rw-r----- 1 proxy proxy  540356 2016-01-31 15:36 
/var/log/squid3/access.log-20160131.bz2
 596 -rw-r----- 1 proxy proxy  608083 2016-02-07 16:40 
/var/log/squid3/access.log-20160207.bz2
 544 -rw-r----- 1 proxy proxy  556129 2016-02-15 15:10 
/var/log/squid3/access.log-20160215.bz2
 680 -rw-r----- 1 proxy proxy  692678 2016-02-21 17:16 
/var/log/squid3/access.log-20160221.bz2
 608 -rw-r----- 1 proxy proxy  620463 2016-02-29 05:22 
/var/log/squid3/access.log-20160229.bz2
 476 -rw-r----- 1 proxy proxy  486777 2016-03-06 04:11 
/var/log/squid3/access.log-20160306.bz2
5576 -rw-r----- 1 proxy proxy 5702654 2016-03-14 16:01 
/var/log/squid3/access.log-20160314


--------------------------<snip><Start of 
patch><snip>----------------------------
--- sarg-reports.ORIG   2011-02-17 01:25:22.000000000 +0100
+++ sarg-reports        2011-02-17 01:25:22.000000000 +0100
@@ -218,7 +218,7 @@
     then
       echo "No date given, please specify a valid date (DD/MM/YYYY)"
     else
-      $SARG -f $CONFIG -d $MANUALDATE -o $DAILYOUT
+      $SARG -f $CONFIG -d $MANUALDATE -o $DAILYOUT ${@} ${ACCESS_LOG}*
   fi
 }

@@ -227,7 +227,7 @@
   DAILYOUT=$HTMLOUT/$DAILY
   mkdir -p $DAILYOUT
   create_index_html
-  $SARG -f $CONFIG -d $TODAY -o $DAILYOUT >$ERRORS 2>&1
+  $SARG -f $CONFIG -d $TODAY -o $DAILYOUT ${@} ${ACCESS_LOG}*
   >$ERRORS 2>&1
   exclude_from_log
 }

@@ -236,7 +236,7 @@
   DAILYOUT=$HTMLOUT/$DAILY
   mkdir -p $DAILYOUT
   create_index_html
-  $SARG -f $CONFIG -d day-1 -o $DAILYOUT >$ERRORS 2>&1
+  $SARG -f $CONFIG -d day-1 -o $DAILYOUT ${@} ${ACCESS_LOG}* >$ERRORS 2>&1
   exclude_from_log
 }

@@ -245,7 +245,7 @@
   WEEKLYOUT=$HTMLOUT/$WEEKLY
   mkdir -p $WEEKLYOUT
   create_index_html
-  $SARG -f $CONFIG -d week-1 -o $WEEKLYOUT >$ERRORS 2>&1
+  $SARG -f $CONFIG -d week-1 -o $WEEKLYOUT ${@} ${ACCESS_LOG}*
   >$ERRORS 2>&1
   exclude_from_log
 }

@@ -254,25 +254,32 @@
   MONTHLYOUT=$HTMLOUT/$MONTHLY
   mkdir -p $MONTHLYOUT
   create_index_html
-  $SARG -f $CONFIG -d month-1 -o $MONTHLYOUT >$ERRORS 2>&1
+  $SARG -f $CONFIG -d month-1 -o $MONTHLYOUT ${@} ${ACCESS_LOG}*
   >$ERRORS 2>&1
   exclude_from_log
 }

+ACCESS_LOG=$(sed -ne 's|^access_log[[:space:]]*||p' /etc/sarg/sarg.conf)
+
 case $1 in
     manual)
-        manual
+       shift 1
+        manual "${@}"
         ;;
     today)
-        today
+       shift 1
+        today "${@}"
         ;;
     daily)
-        daily
+       shift 1
+        daily "${@}"
         ;;
     weekly)
-        weekly
+       shift 1
+        weekly "${@}"
         ;;
     monthly)
-        monthly
+       shift 1
+        monthly "${@}"
         ;;
      *)
         echo "SARG - Daily / Weekly / Monthly - Squid proxy usage
         reports creation tool"
---------------------------<snip><End of 
patch><snip>----------------------------


/bin/sh /usr/sbin/sarg-reports monthly

SARG: Ignoring old log file /var/log/squid3/access.log-20160131.bz2
SARG: Decompressing log file "/var/log/squid3/access.log-20160207.bz2"
with bzcat
SARG: Decompressing log file "/var/log/squid3/access.log-20160215.bz2"
with bzcat
SARG: Decompressing log file "/var/log/squid3/access.log-20160221.bz2"
with bzcat
SARG: Decompressing log file "/var/log/squid3/access.log-20160229.bz2"
with bzcat
SARG: Decompressing log file "/var/log/squid3/access.log-20160306.bz2"
with bzcat
SARG: Period covered by log files: 01/02/2016-29/02/2016


ll /srv/www/squid-reports/Monthly/

total 24
4 drwxr-sr-x 4 root www-data 4096 2016-03-17 00:18 ./
4 drwxr-sr-x 6 root www-data 4096 2016-03-16 23:06 ../
4 drwxr-sr-x 4 root www-data 4096 2016-03-17 00:18 01Feb2016-29Feb2016/
4 drwxr-sr-x 2 root www-data 4096 2016-03-17 00:18 images/
8 -rw-r--r-- 1 root www-data 4438 2016-03-17 00:18 index.html


And finally a Monthly report is generated ...

Reply via email to