]> git.pld-linux.org Git - packages/calamaris.git/commitdiff
- Calamaris-cron interface.
authormkochano <mkochano@pld-linux.org>
Sat, 18 Mar 2000 21:39:54 +0000 (21:39 +0000)
committercvs2git <feedback@pld-linux.org>
Sun, 24 Jun 2012 12:13:13 +0000 (12:13 +0000)
Changed files:
    calamaris-croniface -> 1.1

calamaris-croniface [new file with mode: 0644]

diff --git a/calamaris-croniface b/calamaris-croniface
new file mode 100644 (file)
index 0000000..1425250
--- /dev/null
@@ -0,0 +1,104 @@
+#!/bin/sh
+#
+# $Id$
+#
+# This file is to be called by crond in order to create statistical reports
+# on usage of caching proxy. It is a wrapper for Calamaris - reads
+# configuration and calls Calamaris with appropriate arguments.
+#
+# One argument should be passed. It can be 'daily' or 'weekly' in order to
+# select what actions to take.
+#
+# Author:      Micha³ Kochanowicz <mkochano@pld.org.pl>
+
+# Wrapper for Calamaris. Reads configuration and calls Calamaris with
+# appropriate arguments.
+
+# Default configuration.
+SAVE_FORMAT="HTML"
+SEND_FORMAT="plain"
+SEND_TO="root"
+DAILY_ACTION="send"
+DAILY_FILES=
+# If you have an idea of better default setting for this variable you are
+# welcome to change it, but please don't assume that caching proxy is also
+# a http server...
+DAILY_SAVE_AS="/dev/null"
+WEEKLY_ACTION="send"
+WEEKLY_FILES=
+# See comment above.
+WEEKLY_SAVE_AS="/dev/null"
+HTML_LOGO="<H1>Caching Proxy Statistics</H1>"
+CALAMARIS_ARGS="-a"
+
+# Read configuration.
+[ -f /etc/sysconfig/calamaris ] && . /etc/sysconfig/calamaris
+
+# Parameter passed to Calamaris.
+ARG_HTML="$CALAMARIS_ARGS -w -l $LOGO"
+ARG_MAIL="$CALAMARIS_ARGS -a -m Calamaris report"
+MAIL_SUBJ="Calamaris Report"
+
+# Calls Calamaris. Requires following arguments:
+# $1 - Input file (globs are OK).
+# $2 - Arguments list.
+call_calamaris() {
+       (
+       for FILE in $1; do
+               echo Processing $FILE >&2
+               if [[ $FILE = *.gz ]]; then
+                       zcat $FILE
+               else
+                       cat $FILE
+               fi
+       done
+       ) | calamaris $2
+}
+
+# Processes arguments and prepares arguments for Calamaris. Requires following
+# arguments:
+# $1 - Input file (globs are OK).
+# $2 - Action: "save", "send" or both.
+# $3 - Save filename.
+make_stats() {
+       # Generate statistics and save them.
+       if [[ $2 = *save* ]]; then
+               if [ "$SAVE_FORMAT" = "HTML" ]; then
+                       ARG="$ARG_HTML"
+               else
+                       ARG="$ARG_PLAIN"
+               fi
+#              echo "Saving to $3...">&2
+               call_calamaris "$1" "$ARG" > $3
+       fi
+
+       # Generate statistics and send them.
+       if [[ $2 = *send* ]]; then
+               if [ "$SEND_FORMAT" = "HTML" ]; then
+                       ARG="$ARG_HTML"
+               else
+                       ARG="$ARG_PLAIN"
+               fi
+               # If statistics have to be mailed in same format as they were
+               # saved we don't need to call Calamaris again.
+               if [[ $2 = *save* && $SAVE_FORMAT = $SEND_FORMAT ]]; then
+#                      echo "Sending already generated report to $SEND_TO" >&2
+                       (
+                       cat $3
+                       ) | mail -s "$MAIL_SUBJ" $SEND_TO
+               else
+#                      echo "Sending to $SEND_TO" >&2
+                       call_calamaris "$1" "$ARG" | mail -s "$MAIL_SUBJ" $SEND_TO
+               fi
+       fi
+}
+
+
+if [ "$1" = "daily" ]; then
+       make_stats "$DAILY_FILES" "$DAILY_ACTION" $DAILY_SAVE_AS
+elif [ "$1" = "weekly" ]; then
+       make_stats "$WEEKLY_FILES" "$WEEKLY_ACTION" $WEEKLY_SAVE_AS
+else
+       echo 'Make up your mind!' >&2
+fi
+
This page took 0.220899 seconds and 4 git commands to generate.