]> git.pld-linux.org Git - packages/calamaris.git/blob - calamaris-croniface
dec6c7123e000d371968073f8e1f95ef09cce081
[packages/calamaris.git] / calamaris-croniface
1 #!/bin/sh
2 #
3 # $Id$
4 #
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.
8 #
9 # One argument should be passed. It can be 'daily' or 'weekly' in order to
10 # select what actions to take.
11 #
12 # Author:       Micha³ Kochanowicz <mkochano@pld.org.pl>
13
14 # Wrapper for Calamaris. Reads configuration and calls Calamaris with
15 # appropriate arguments.
16
17 # Default configuration.
18 SAVE_FORMAT="HTML"
19 SEND_FORMAT="plain"
20 SEND_TO="root"
21 DAILY_ACTION="send"
22 DAILY_FILES=
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
25 # a http server...
26 DAILY_SAVE_AS="/dev/null"
27 WEEKLY_ACTION="send"
28 WEEKLY_FILES=
29 # See comment above.
30 WEEKLY_SAVE_AS="/dev/null"
31 HTML_LOGO="<H1>Caching Proxy Statistics</H1>"
32 CALAMARIS_ARGS="-a"
33
34 # Read configuration.
35 [ -f /etc/sysconfig/calamaris ] && . /etc/sysconfig/calamaris
36
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"
41
42 # Calls Calamaris. Requires following arguments:
43 # $1 - Input file (globs are OK).
44 # $2 - Arguments list.
45 call_calamaris() {
46         (
47         for FILE in $1; do
48                 if [[ $FILE = *.gz ]]; then
49                         zcat $FILE
50                 else
51                         cat $FILE
52                 fi
53         done
54         ) | calamaris $2
55 }
56
57 # Processes arguments and prepares arguments for Calamaris. Requires following
58 # arguments:
59 # $1 - Input file (globs are OK).
60 # $2 - Action: "save", "send" or both.
61 # $3 - Save filename.
62 make_stats() {
63         # Generate statistics and save them.
64         if [[ $2 = *save* ]]; then
65                 if [ "$SAVE_FORMAT" = "HTML" ]; then
66                         ARG="$ARG_HTML"
67                 else
68                         ARG="$ARG_PLAIN"
69                 fi
70                 call_calamaris "$1" "$ARG" > $3
71         fi
72
73         # Generate statistics and send them.
74         if [[ $2 = *send* ]]; then
75                 if [ "$SEND_FORMAT" = "HTML" ]; then
76                         ARG="$ARG_HTML"
77                 else
78                         ARG="$ARG_PLAIN"
79                 fi
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
83                         (
84                         cat $3
85                         ) | mail -s "$MAIL_SUBJ" $SEND_TO
86                 else
87                         call_calamaris "$1" "$ARG" | mail -s "$MAIL_SUBJ" $SEND_TO
88                 fi
89         fi
90 }
91
92
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
97 else
98         echo 'Make up your mind!' >&2
99 fi
100
This page took 0.027374 seconds and 3 git commands to generate.