Written by James McDonald

March 31, 2010

Sarg is a Squid Report Generator that scans your Squid logs and generates html reports that are available via a web page.

I have used sarg for years on Redhatian boxes with no troubles. My issues started when I moved to Ubuntu as my Squid Proxy. No Daily, Weekly or Monthly Sarg reports are generated with a default Sarg install.

Using this link pointed me in the right direction and a comment on the post helped further.

So here is what I did to configure a working Sarg+Squid setup.

  1. Edit /etc/logrotate.d/squid and change the daily option to monthly and change the command line for prerotate to actually do something
  2. #
    #       Logrotate fragment for squid.
    #
    /var/log/squid/*.log {
            # comment out daily and add monthly
            # this means squid will rotate the logs on a monthly basis
            # daily
            monthly
            compress
            delaycompress
            rotate 2
            missingok
            nocreate
            sharedscripts
            prerotate
                    # The default command does nothing but return a usage message
                    # test ! -x /usr/sbin/sarg-reports || /usr/sbin/sarg-reports
    
                    # change the command so prior to the logs being rotated it does a monthly report
                    # the first part (before the ||) checks for the executeable sarg-reports 
                    # and the second part is the actual command
                    test ! -x /usr/sbin/sarg-reports || /usr/sbin/sarg-reports monthly
            endscript
            postrotate
                    test ! -e /var/run/squid.pid || /usr/sbin/squid -k rotate
            endscript
    }
    
  3. I also commented out the contents of /etc/cron.monthly because it will be run by the logrotate prerotate command. I don’t remove the cron file because I want to be able to revert just in case.
  4.  
    #!/bin/sh
    
    # Skipping Monthly log rotate because it is done in the squid logrotate prerotate command
    
    # if [ -x /usr/sbin/sarg-reports ]; then
    #  /usr/sbin/sarg-reports monthly
    # fi
    
  5. Finally I have moved the /etc/cron.daily/sarg /etc/cron.weekly/sarg files so they run before any possible logrotate command by renaming them with a prefix of 0
  6. mv /etc/cron.daily/sarg /etc/cron.daily/0sarg
    mv /etc/cron.weekly/sarg /etc/cron.weekly/0sarg
    

2 Comments

  1. Dave

    Nice post! I really like this method. Thanks man, just what I was looking for!

    Reply
  2. KegRaider

    Thanks! The above mention posts are no longer available, but I’m sure this will fix my issue too.

    Reply

Submit a Comment

Your email address will not be published. Required fields are marked *

This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

The reCAPTCHA verification period has expired. Please reload the page.

You May Also Like…

Clear HSTS Settings in CHrome

Open chrome://net-internals/#hsts enter the domain in the query field and click Query to confirm it has HSTS settings...

Ubuntu on Hyper-v

It boils town to installing linux-azure # as root or sudo apt-get update apt-get install linux-azure...