File: EXAMPLES

package info (click to toggle)
calamaris 2.45-2
  • links: PTS
  • area: main
  • in suites: woody
  • size: 268 kB
  • ctags: 17
  • sloc: perl: 2,808; sh: 202; makefile: 35
file content (366 lines) | stat: -rw-r--r-- 10,818 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
I want to give the 'audience' some examples for using Calamaris.

So if you build some Scripts, crontabs or else around Calamaris, please
mail and describe them to Calamaris@Cord.de.

I'll probably add them to this file. Thank You.

Philipp Frauenfelder (pfrauenf@debian.org) added this to run Calamaris
automagically in Debian:
-----------------------------------------------------------------------
/etc/cron.daily/calamaris
=========================
#! /bin/sh

set -e

# calamaris: daily cron script.
# This script should be run before the one for squid. According to the
# man page of run-parts this is okay: squid comes after calamaris in the
# alphabet.

# Date: 1998-10-07

CONFFILE=/etc/calamaris.conf
CALAMARIS=/usr/bin/calamaris

if [ ! -x /usr/bin/calamaris ]; then
    exit 0
fi

CALAMARISOPTIONS=-a
ME=/etc/cron.daily/calamaris
WEEKFILES=daily.1:daily.2:daily.3:daily.4:daily.5:daily.6:daily.0

SQUIDLOGDIR=/var/log/squid
cd $SQUIDLOGDIR || exit 1
if [ ! -r access.log ]; then
    exit 0
fi

LOGDIR=/var/log/calamaris
cd $LOGDIR || exit 1

# today
DAYOFWEEK=`date +"%w"`

# read configuration file: /etc/calamaris.conf
# is there a more elegant way to do this?
DAYMAIL=`awk -F: '(!/#/) && ($1 == "daily") { print $2; }' $CONFFILE`
DAYWEB=`awk -F: '(!/#/) && ($1 == "daily") { print $3; }' $CONFFILE`
DAYDO=`awk -F: '(!/#/) && ($1 == "daily") { print $4; }' $CONFFILE`
DAYTITLE=`awk -F: '(!/#/) && ($1 == "daily") { print $5; }' $CONFFILE`

WEEKMAIL=`awk -F: '(!/#/) && ($1 == "weekly") { print $2; }' $CONFFILE`
WEEKWEB=`awk -F: '(!/#/) && ($1 == "weekly") { print $3; }' $CONFFILE`
WEEKDO=`awk -F: '(!/#/) && ($1 == "weekly") { print $4; }' $CONFFILE`
WEEKTITLE=`awk -F: '(!/#/) && ($1 == "weekly") { print $5; }' $CONFFILE`

# perhaps sometimes I will do this, 
# but as weekends and ends of months don't meet always...

# MONTHMAIL=`awk -F: '(!/#/) && ($1 == "monthly") { print $2; }' $CONFFILE`
# MONTHWEB=`awk -F: '(!/#/) && ($1 == "monthly") { print $3; }' $CONFFILE`
# MONTHDO=`awk -F: '(!/#/) && ($1 == "monthly") { print $4; }' $CONFFILE`
# MONTHTITLE=`awk -F: '(!/#/) && ($1 == "monthly") { print $5; }' $CONFFILE`

# if we need monthly or weekly reports save a summary
if [ $WEEKDO != "nothing" ]; then
    CALAMARISOPTIONSOLD="$CALAMARISOPTIONS"
    CALAMARISOPTIONS="$CALAMARISOPTIONS -o daily.$DAYOFWEEK"
fi

# do the daily report
case $DAYDO in
    nothing) if [ $WEEKDO != "nothing" ]; then
	cat $SQUIDLOGDIR/access.log | \
	    nice -39 $CALAMARIS $CALAMARISOPTIONS > /dev/null
	fi
    ;;
    mail) (
	    echo "To: $DAYMAIL"
	    cat $SQUIDLOGDIR/access.log | \
		nice -39 $CALAMARIS $CALAMARISOPTIONS -mH "$DAYTITLE"
	) | /usr/lib/sendmail -t
    ;;
    web) cat $SQUIDLOGDIR/access.log | \
	    nice -39 $CALAMARIS $CALAMARISOPTIONS -wH "$DAYTITLE" > $DAYWEB
    ;;
    both) cat $SQUIDLOGDIR/access.log | \
	    nice -39 $CALAMARIS $CALAMARISOPTIONS -wH "$DAYTITLE" > $DAYWEB
	(
	    echo "To: $DAYMAIL"
	    cat $SQUIDLOGDIR/access.log | \
		nice -39 $CALAMARIS $CALAMARISOPTIONS -mH "$DAYTITLE"
	) | /usr/lib/sendmail -t
    ;;
    *) echo "the 'todo' for the daily Squid report in $CONFFILE"
	echo -n "is '$DAYDO' instead of one out of "
	echo "(nothing, mail, web, both)." >&2
	exit 1
    ;;
esac

# do the weekly report on Sunday <=> $DAYOFWEEK==0
if [ -n "$CALAMARISOPTIONSOLD" ]; then
    CALAMARISOPTIONS="$CALAMARISOPTIONSOLD"
fi


if [ $DAYOFWEEK = "0" ]; then
    case $WEEKDO in
	nothing) 
	;;
	mail) (
		echo "To: $WEEKMAIL"
		nice -39 $CALAMARIS $CALAMARISOPTIONS -i $WEEKFILES \
		    -zmH "$WEEKTITLE"
	    ) | /usr/lib/sendmail -t
	;;
	web) nice -39 $CALAMARIS $CALAMARISOPTIONS -i $WEEKFILES \
		-zwH "$WEEKTITLE" > $WEEKWEB
	;;
	both) nice -39 $CALAMARIS $CALAMARISOPTIONS -i $WEEKFILES \
		-zwH "$WEEKTITLE" > $WEEKWEB
	    (
		echo "To: $WEEKMAIL"
		nice -39 $CALAMARIS $CALAMARISOPTIONS -i $WEEKFILES \
		    -zmH "$WEEKTITLE"
	    ) | /usr/lib/sendmail -t
	;;
	*) echo "the 'todo' for the weekly Squid report in $CONFFILE"
	    echo -n "is '$WEEKDO' instead of one out of "
	    echo "(nothing, mail, web, both)." >&2
	    exit 1
	;;
    esac
#    if [ $MONTHDP != "nothing" ]; then
#	nice -39 $CALAMARIS $CALAMARISOPTIONS -i $WEEKFILES -z -o weekly.$WEEKWHAT > /dev/null
#    fi
fi

# do the monthly report and rotate the monthly logs: nothing to do :-)

exit 0



/etc/calamaris.conf
===================
# configuration file for calamaris
# by Philipp Frauenfelder <pfrauenf@debian.org>
# 1998-10-09

# there are three categories: daily, weekly and monthly. For each of these
# one line is responsible. There must be a line for each category but only 
# one.

# cat: [daily|weekly|monthly]
# mailto: mailaddress, eg. root
# webto: path incl. file name, eg. /var/www/daily.html. The script does
#                       currently not check wether the directory exists and
#                       fail with a rather ugly error.
# todo: [nothing|mail|web|both]
# title: try it :-)

# cat:mailto:webto:todo:title
daily:root:/var/www/calamaris/daily.html:both:'Squid daily'
weekly:root:/var/www/calamaris/weekly.html:both:'Squid weekly'

# monthly does not work right now.
#monthly:root:/var/www/monthly.html:both:'Squid monthly'

# how many months of calamaris logs should be kept: integer
#monthstokeep 2
-----------------------------------------------------------------------


Matthew King (nerd@zip.com.au) squidreport.cron:
-----------------------------------------------------------------------
#!/bin/sh

# SquidReport Script by Matthew King
# Last update: 27-03-99.

# This script will remove the current Squid HTML report, and will replace
# it with a fresh one. The report will include all available squid access
# log files.. Roughly 7 days worth. The report will then be dumped into
# /home/httpd/html/ to be viewed via a web browser.

# Remove the current report!
cd /home/httpd/html/
rm -f squidreport.html
echo > squidreport.html
cd /

# Create the new report and place it into the /home/httpd/html/ dir..
cd /var/log/squid/
cat access.log.7 access.log.6 access.log.5 access.log.4 access.log.3 \
    access.log.2 access.log.1 access.log \
    | /usr/local/bin/calamaris.pl -a -w > /home/httpd/html/squidreport.html

# Phew! It is done :) 60 odd seconds later :)
-----------------------------------------------------------------------


Gottfried Hamm (ghamm@ghks.de) idea of using calamaris for reporting:
-----------------------------------------------------------------------
squid.conf
==========
[...]
logfile_rotate 7
[...]

crontab
=======
[...]
0 0 * * *       /usr/local/squid/bin/squidrep
[...]

/usr/local/squid/bin/squidrep
=============================
#/bin/sh

# SquidReport by Gottfried Hamm <ghamm@ghks.de>
# Created       07.01.2000
# Updated

BINDIR=/usr/local/squid/bin
LOGDIR=/usr/local/squid/logs
DAYOFWEEK=`date +"%w"`
DATE=`date +"%Y%m%d"`

## Rotate the logs
#
BINDIR/squid -k rotate
sleep 5m

## Daily report via mail to webmaster
#
cd $LOGDIR
cat access.log.0 | \
$BINDIR/calamaris -amH 'Daily' | \
mail -s "Daily Proxy-Report `date`" webmaster@ghks.de

## Weekly report will be stored as web page
#
if [ $DAYOFWEEK = "0" ]; then
        cat access.log.? | $BINDIR/calamaris -awl '<A
HREF="http://www.ghks.de/">GHKS</A>' > \
        /data/www/ghks.de/admin/proxy/report-$DATE.html
fi

exit 0
-----------------------------------------------------------------------


Thomas Wahyudi (thomas@home.unpar.ac.id) method:
-----------------------------------------------------------------------
#!/bin/sh
# SquidReport Script by Matthew King
# rewriten by Thomas Wahyudi <thomas@home.unpar.ac.id>
# Last update: 15-05-2000.

# Sample Crontab
# 0  0  *  *  *   /cache/squid/bin/squid -k rotate
# 30 0  *  *  *   /cache/squid/bin/squidreport

##################################################

dailyreport="/www/htdocs/Squid/report/daily/"
weeklyreport="/www/htdocs/Squid/report/weekly/"
programpath="/cache/squid/bin/calamaris"
squidlog="/cache/squid/logs"

hef1=`/bin/date | /usr/bin/awk '{print $2}'`
hef2=`/bin/date | /usr/bin/awk '{print $3}'`
hef3=`/bin/date | /usr/bin/awk '{print $1}'`
hef4=`/bin/date | /usr/bin/awk '{print $6}'`

# Convert date if less then 10
##############################

if [ "$hef2" -lt "10" ]
then
     hef2="0$hef2"
fi

# Create the new report and place it into the report location
# report in file ex. Mar.28.Tue.2000.htm will contain yesterday performance
###########################################################################

cat $squidlog/access.log.0 | nice -39 $programpath -wamH 'Yesterday worf' >
"$dailyreport$hef1.$hef2.$hef3.$hef4.htm"

# This script will remove the outdated Squid HTML report,
# The report will include all available squid access log files..
# Roughly 31 days worth. The report will then be dumped into
# report location to be viewed via a web browser.
################################################################

totalreport=`/bin/ls $dailyreport | /usr/bin/wc | /usr/bin/awk '{print $1}'`

if [ $totalreport -gt 31 ]
then
   get1file=`/bin/ls $dailyreport | /usr/bin/head -n 1`
   /bin/rm $dailyreport$get1file
fi

# Every Monday will create report for weekly report
###################################################

totalreport=`/bin/ls $weeklyreport | /usr/bin/wc | /usr/bin/awk '{print
$1}'`

if [ "$hef3" = "Mon" ]
then

cat $squidlog/access.log.6 $squidlog/access.log.5 $squidlog/access.log.4
$squidlog/access.log.3 \
    $squidlog/access.log.2 $squidlog/access.log.1 $squidlog/access.log.0 \
    | $programpath -wamH 'Weekly worf' >
"$weeklyreport$hef1.$hef2.$hef3.$hef4.htm"

if [ $totalreport -gt 5 ]
then
   get1file=`/bin/ls $weeklyreport | /usr/bin/head -n 1`
   /bin/rm $weeklyreport$get1file
fi

fi
-----------------------------------------------------------------------


My (cord@Wunder-Nett.org) method:
-----------------------------------------------------------------------

squid.conf:
-----------------------------------------------------
[...]
logfile_rotate 7
[...]
-----------------------------------------------------

crontab:
-----------------------------------------------------
0 0 * * *	/usr/local/squid/bin/squid -k rotate
30 0 * * *	cat /var/log/squid/access.log.0 | \
		nice -39 /usr/local/squid/bin/calamaris -amH 'daily worf' | \
		mail Squidmaster@Cord.de
0 3 * * 7	(cd /var/log/squid/; cat access.log.6 access.log.5 \
		access.log.4 access.log.3 access.log.2 access.log.1 \
		access.log.0) | \
		nice -39 /usr/local/squid/bin/calamaris -amH 'weekly worf' | \
		mail Squidmaster@Cord.de
-----------------------------------------------------

Everyone who really uses Squidmaster@Cord.de while testing has to send me a
	postcard!
-----------------------------------------------------------------------



Version of the EXAMPLES
-----------------------

$Id: EXAMPLES,v 2.8 2000/10/27 13:42:57 cord Exp $