]> git.pld-linux.org Git - packages/calamaris.git/blob - calamaris-croniface
- updated to 2.51: bugfixes.
[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 # Default configuration.
15 SAVE_FORMAT="HTML"
16 SAVE_OWNER="nobody.nobody"
17 SAVE_PERM="u=rw,g=r,o=r"
18 SEND_FORMAT="plain"
19 SEND_TO="root"
20
21 # DAILY ---------------------------------------------------------------
22 DAILY_ACTION="send"
23 DAILY_FILES=
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
26 # a http server...
27 DAILY_SAVE_AS="/dev/null"
28
29 # WEEKLY --------------------------------------------------------------
30 WEEKLY_ACTION="send"
31 WEEKLY_FILES=
32 # See comment above.
33 WEEKLY_SAVE_AS="/dev/null"
34
35 HTML_LOGO="<H1>Caching Proxy Statistics</H1>"
36 CALAMARIS_ARGS="-a"
37
38 # Read configuration.
39 [ -f /etc/sysconfig/calamaris ] && . /etc/sysconfig/calamaris
40
41 # Parameter passed to Calamaris.
42 ARG_HTML="$CALAMARIS_ARGS -w -l $LOGO"
43 ARG_MAIL="$CALAMARIS_ARGS -a -m Calamaris report"
44 MAIL_SUBJ="Calamaris Report"
45
46 # Calls Calamaris. Requires following arguments:
47 # $1 - Input file (globs are OK).
48 # $2 - Arguments list.
49 call_calamaris() {
50         (
51         for FILE in $1; do
52                 if [[ $FILE = *.gz ]]; then
53                         zcat $FILE
54                 else
55                         cat $FILE
56                 fi
57         done
58         ) | calamaris $2
59 }
60
61 # Processes arguments and prepares arguments for Calamaris. Requires following
62 # arguments:
63 # $1 - Input file (globs are OK).
64 # $2 - Action: "save", "send" or both.
65 # $3 - Save filename.
66 make_stats() {
67         # Generate statistics and save them.
68         if [[ $2 = *save* ]]; then
69                 if [ "$SAVE_FORMAT" = "HTML" ]; then
70                         ARG="$ARG_HTML"
71                 else
72                         ARG="$ARG_PLAIN"
73                 fi
74                 call_calamaris "$1" "$ARG" > $3
75                 chown $SAVE_OWNER $3
76                 chmod $SAVE_PERM $3
77         fi
78
79         # Generate statistics and send them.
80         if [[ $2 = *send* ]]; then
81                 if [ "$SEND_FORMAT" = "HTML" ]; then
82                         ARG="$ARG_HTML"
83                 else
84                         ARG="$ARG_PLAIN"
85                 fi
86                 # If statistics have to be mailed in same format as they were
87                 # saved we don't need to call Calamaris again.
88                 if [[ $2 = *save* && $SAVE_FORMAT = $SEND_FORMAT ]]; then
89                         (
90                         cat $3
91                         ) | mail -s "$MAIL_SUBJ" $SEND_TO
92                 else
93                         call_calamaris "$1" "$ARG" | mail -s "$MAIL_SUBJ" $SEND_TO
94                 fi
95         fi
96 }
97
98
99 if [ "$1" = "daily" ]; then
100         make_stats "$DAILY_FILES" "$DAILY_ACTION" "$DAILY_SAVE_AS"
101 elif [ "$1" = "weekly" ]; then
102         make_stats "$WEEKLY_FILES" "$WEEKLY_ACTION" "$WEEKLY_SAVE_AS"
103 else
104         echo 'Make up your mind!' >&2
105 fi
106
This page took 0.047033 seconds and 3 git commands to generate.