#!/bin/sh # # $Id$ # # This file is to be called by crond in order to create statistical reports # on usage of caching proxy. It is a wrapper for Calamaris - reads # configuration and calls Calamaris with appropriate arguments. # # One argument should be passed. It can be 'daily' or 'weekly' in order to # select what actions to take. # # Author: Micha³ Kochanowicz # Default configuration. SAVE_FORMAT="HTML" SAVE_OWNER="nobody.nobody" SAVE_PERM="u=rw,g=r,o=r" SEND_FORMAT="plain" SEND_TO="root" # DAILY --------------------------------------------------------------- DAILY_ACTION="send" DAILY_FILES= # If you have an idea of better default setting for this variable you are # welcome to change it, but please don't assume that caching proxy is also # a http server... DAILY_SAVE_AS="/dev/null" # WEEKLY -------------------------------------------------------------- WEEKLY_ACTION="send" WEEKLY_FILES= # See comment above. WEEKLY_SAVE_AS="/dev/null" HTML_LOGO="

Caching Proxy Statistics

" CALAMARIS_ARGS="-a" # Read configuration. [ -f /etc/sysconfig/calamaris ] && . /etc/sysconfig/calamaris # Parameter passed to Calamaris. ARG_HTML="$CALAMARIS_ARGS -w -l $LOGO" ARG_MAIL="$CALAMARIS_ARGS -a -m Calamaris report" MAIL_SUBJ="Calamaris Report" # Calls Calamaris. Requires following arguments: # $1 - Input file (globs are OK). # $2 - Arguments list. call_calamaris() { ( for FILE in $1; do if [[ $FILE = *.gz ]]; then zcat $FILE else cat $FILE fi done ) | calamaris $2 } # Processes arguments and prepares arguments for Calamaris. Requires following # arguments: # $1 - Input file (globs are OK). # $2 - Action: "save", "send" or both. # $3 - Save filename. make_stats() { # Generate statistics and save them. if [[ $2 = *save* ]]; then if [ "$SAVE_FORMAT" = "HTML" ]; then ARG="$ARG_HTML" else ARG="$ARG_PLAIN" fi call_calamaris "$1" "$ARG" > $3 chown $SAVE_OWNER $3 chmod $SAVE_PERM $3 fi # Generate statistics and send them. if [[ $2 = *send* ]]; then if [ "$SEND_FORMAT" = "HTML" ]; then ARG="$ARG_HTML" else ARG="$ARG_PLAIN" fi # If statistics have to be mailed in same format as they were # saved we don't need to call Calamaris again. if [[ $2 = *save* && $SAVE_FORMAT = $SEND_FORMAT ]]; then ( cat $3 ) | mail -s "$MAIL_SUBJ" $SEND_TO else call_calamaris "$1" "$ARG" | mail -s "$MAIL_SUBJ" $SEND_TO fi fi } if [ "$1" = "daily" ]; then make_stats "$DAILY_FILES" "$DAILY_ACTION" "$DAILY_SAVE_AS" elif [ "$1" = "weekly" ]; then make_stats "$WEEKLY_FILES" "$WEEKLY_ACTION" "$WEEKLY_SAVE_AS" else echo 'Make up your mind!' >&2 fi