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 # Wrapper for Calamaris. Reads configuration and calls Calamaris with
15 # appropriate arguments.
17 # Default configuration.
23 # If you have an idea of better default setting for this variable you are
24 # welcome to change it, but please don't assume that caching proxy is also
26 DAILY_SAVE_AS="/dev/null"
30 WEEKLY_SAVE_AS="/dev/null"
31 HTML_LOGO="<H1>Caching Proxy Statistics</H1>"
35 [ -f /etc/sysconfig/calamaris ] && . /etc/sysconfig/calamaris
37 # Parameter passed to Calamaris.
38 ARG_HTML="$CALAMARIS_ARGS -w -l $LOGO"
39 ARG_MAIL="$CALAMARIS_ARGS -a -m Calamaris report"
40 MAIL_SUBJ="Calamaris Report"
42 # Calls Calamaris. Requires following arguments:
43 # $1 - Input file (globs are OK).
44 # $2 - Arguments list.
48 if [[ $FILE = *.gz ]]; then
57 # Processes arguments and prepares arguments for Calamaris. Requires following
59 # $1 - Input file (globs are OK).
60 # $2 - Action: "save", "send" or both.
63 # Generate statistics and save them.
64 if [[ $2 = *save* ]]; then
65 if [ "$SAVE_FORMAT" = "HTML" ]; then
70 call_calamaris "$1" "$ARG" > $3
73 # Generate statistics and send them.
74 if [[ $2 = *send* ]]; then
75 if [ "$SEND_FORMAT" = "HTML" ]; then
80 # If statistics have to be mailed in same format as they were
81 # saved we don't need to call Calamaris again.
82 if [[ $2 = *save* && $SAVE_FORMAT = $SEND_FORMAT ]]; then
85 ) | mail -s "$MAIL_SUBJ" $SEND_TO
87 call_calamaris "$1" "$ARG" | mail -s "$MAIL_SUBJ" $SEND_TO
93 if [ "$1" = "daily" ]; then
94 make_stats "$DAILY_FILES" "$DAILY_ACTION" $DAILY_SAVE_AS
95 elif [ "$1" = "weekly" ]; then
96 make_stats "$WEEKLY_FILES" "$WEEKLY_ACTION" $WEEKLY_SAVE_AS
98 echo 'Make up your mind!' >&2