5 # This file is to be called by crond in order to create statistical reports
6 # on usage of caching proxy. It is a wrapper for Calamaris - reads
7 # configuration and calls Calamaris with appropriate arguments.
9 # One argument should be passed. It can be 'daily' or 'weekly' in order to
10 # select what actions to take.
12 # Author: Micha³ Kochanowicz <mkochano@pld.org.pl>
14 # Default configuration.
17 SAVE_PERM="u=rw,g=r,o=r"
21 # DAILY ---------------------------------------------------------------
24 # If you have an idea of better default setting for this variable you are
25 # welcome to change it, but please don't assume that caching proxy is also
27 DAILY_SAVE_AS="/dev/null"
29 # WEEKLY --------------------------------------------------------------
33 WEEKLY_SAVE_AS="/dev/null"
35 HTML_LOGO="<H1>Caching Proxy Statistics</H1>"
39 [ -f /etc/sysconfig/calamaris ] && . /etc/sysconfig/calamaris
41 # Parameter passed to Calamaris.
42 # XXX: passing -l HTML_LOGO breaks here due
43 ARG_HTML="$CALAMARIS_ARGS -F html"
44 ARG_MAIL="$CALAMARIS_ARGS -a -m Calamaris report"
45 MAIL_SUBJ="Calamaris Report"
47 # Calls Calamaris. Requires following arguments:
48 # $1 - Input file (globs are OK).
49 # $2 - Arguments list.
53 if [[ $FILE = *.gz ]]; then
55 elif [[ $FILE = *.bz2 ]]; then
64 # Processes arguments and prepares arguments for Calamaris. Requires following
66 # $1 - Input file (globs are OK).
67 # $2 - Action: "save", "send" or both.
70 # Generate statistics and save them.
71 if [[ $2 = *save* ]]; then
72 if [ "$SAVE_FORMAT" = "HTML" ]; then
77 local dir=$(dirname "$3")
78 if [ ! -d "$dir" ]; then
79 echo >&2 "$3 can not be saved as it's parent dir $dir does not exist!"
82 call_calamaris "$1" "$ARG" > $3
83 [ -n "$SAVE_OWNER" ] && chown $SAVE_OWNER $3
84 [ -n "$SAVE_PERM" ] && chmod $SAVE_PERM $3
87 # Generate statistics and send them.
88 if [[ $2 = *send* ]]; then
89 if [ "$SEND_FORMAT" = "HTML" ]; then
94 # If statistics have to be mailed in same format as they were
95 # saved we don't need to call Calamaris again.
96 if [[ $2 = *save* && $SAVE_FORMAT = $SEND_FORMAT ]]; then
99 ) | mail -s "$MAIL_SUBJ" $SEND_TO
101 call_calamaris "$1" "$ARG" | mail -s "$MAIL_SUBJ" $SEND_TO
107 if [ "$1" = "daily" ]; then
108 make_stats "$DAILY_FILES" "$DAILY_ACTION" "$DAILY_SAVE_AS"
109 elif [ "$1" = "weekly" ]; then
110 make_stats "$WEEKLY_FILES" "$WEEKLY_ACTION" "$WEEKLY_SAVE_AS"
112 echo 'Make up your mind!' >&2