]> git.pld-linux.org Git - packages/calamaris.git/blob - calamaris-croniface
- drop obsolete and outdated manual inclusion of rpm macros
[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=
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 # 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"
46
47 # Calls Calamaris. Requires following arguments:
48 # $1 - Input file (globs are OK).
49 # $2 - Arguments list.
50 call_calamaris() {
51         (
52         for FILE in $1; do
53                 if [[ $FILE = *.gz ]]; then
54                         zcat $FILE
55                 elif [[ $FILE = *.bz2 ]]; then
56                         bzcat $FILE
57                 else
58                         cat $FILE
59                 fi
60         done
61         ) | calamaris $2
62 }
63
64 # Processes arguments and prepares arguments for Calamaris. Requires following
65 # arguments:
66 # $1 - Input file (globs are OK).
67 # $2 - Action: "save", "send" or both.
68 # $3 - Save filename.
69 make_stats() {
70         # Generate statistics and save them.
71         if [[ $2 = *save* ]]; then
72                 if [ "$SAVE_FORMAT" = "HTML" ]; then
73                         ARG="$ARG_HTML"
74                 else
75                         ARG="$ARG_PLAIN"
76                 fi
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!"
80                         exit 1
81                 fi
82                 call_calamaris "$1" "$ARG" > $3
83                 [ -n "$SAVE_OWNER" ] && chown $SAVE_OWNER $3
84                 [ -n "$SAVE_PERM" ] && chmod $SAVE_PERM $3
85         fi
86
87         # Generate statistics and send them.
88         if [[ $2 = *send* ]]; then
89                 if [ "$SEND_FORMAT" = "HTML" ]; then
90                         ARG="$ARG_HTML"
91                 else
92                         ARG="$ARG_PLAIN"
93                 fi
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
97                         (
98                         cat $3
99                         ) | mail -s "$MAIL_SUBJ" $SEND_TO
100                 else
101                         call_calamaris "$1" "$ARG" | mail -s "$MAIL_SUBJ" $SEND_TO
102                 fi
103         fi
104 }
105
106
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"
111 else
112         echo 'Make up your mind!' >&2
113 fi
114
This page took 0.04257 seconds and 3 git commands to generate.