~ubuntu-branches/ubuntu/natty/opendkim/natty

« back to all changes in this revision

Viewing changes to stats/opendkim-gengraphs

  • Committer: Bazaar Package Importer
  • Author(s): Scott Kitterman
  • Date: 2011-04-14 15:10:05 UTC
  • mfrom: (1.2.7 upstream)
  • Revision ID: james.westby@ubuntu.com-20110414151005-i942gicr31mynx09
Tags: 2.3.2+dfsg-0ubuntu1
* New upstream bugfix release
  - Repacked tarball to remove non-free IETF drafts and RFCs
  - Updated docs/Makefile.in/am, and README to remove references removed
    non-free documentation

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/bin/sh
 
2
#
 
3
# Copyright (c) 2010, 2011, The OpenDKIM Project.  All rights reserved.
 
4
#
 
5
# Script to generate some HTML-ized statistics for OpenDKIM
 
6
 
 
7
###
 
8
### Setup
 
9
###
 
10
 
 
11
# Command to perform a MySQL query and output HTML
 
12
MYSQL_CMD="mysql -s -N"
 
13
 
 
14
# Database name
 
15
DB=${OPENDKIM_DB:-opendkim}
 
16
 
 
17
# Database user
 
18
USER=${OPENDKIM_USER:-opendkim}
 
19
 
 
20
# Database user's password
 
21
PASSWORD=${OPENDKIM_PASSWORD:-password}
 
22
 
 
23
# Where to write the report
 
24
REALOUTPUT=${OPENDKIM_OUTPUT:-/var/www/docs/opendkim/graphs.html}
 
25
OUTPUT=${REALOUTPUT}.$$
 
26
GRAPHDIR=`dirname $REALOUTPUT`
 
27
 
 
28
# Domains of interest
 
29
DOMAINS=${OPENDKIM_DOMAINS:-"gmail.com,yahoo.com,paypal.com"}
 
30
 
 
31
###
 
32
### NO user-serviceable parts beyond this point
 
33
###
 
34
 
 
35
MYSQL="$MYSQL_CMD --user=$USER --password=$PASSWORD --database=$DB"
 
36
 
 
37
# output a header
 
38
cat > $OUTPUT << EOF
 
39
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd">
 
40
<html>
 
41
  <head>
 
42
   <title>
 
43
    OpenDKIM Statistics Report (Part II)
 
44
   </title>
 
45
  </head>
 
46
 
 
47
  <body>
 
48
EOF
 
49
 
 
50
echo "<h1>OpenDKIM Statistics Report (Part II) generated at `date` </h1>" >> $OUTPUT
 
51
echo "<hr>" >> $OUTPUT
 
52
echo "<ul>" >> $OUTPUT
 
53
for i in $(echo $DOMAINS | awk -F, '{for (c = 1; c <= NF; c++) print $c;}')
 
54
do
 
55
        echo '<li> <a href="'#$i'">'$i'</a>' >> $OUTPUT
 
56
done
 
57
echo '<li> <a href="#unsigned">unsigned</a>' >> $OUTPUT
 
58
echo "</ul>" >> $OUTPUT
 
59
echo "<hr>" >> $OUTPUT
 
60
 
 
61
for i in $(echo $DOMAINS | awk -F, '{for (c = 1; c <= NF; c++) print $c;}')
 
62
do
 
63
        echo '<a name="'$i'"></a>' >> $OUTPUT
 
64
        echo "<p> $i: </p>" >> $OUTPUT
 
65
        $MYSQL --execute="SELECT t1.x, t1.y, COUNT(*)/10 FROM (SELECT COUNT(*) AS x, SUM(spam) AS y FROM messages JOIN reporters ON reporters.id = messages.reporter JOIN signatures ON signatures.message = messages.id JOIN domains ON domains.id = signatures.domain WHERE enabled = 1 AND NOT spam = -1 AND domains.name = '"$i"' GROUP BY DATE(msgtime)) AS t1 GROUP BY t1.x, t1.y" > /tmp/ogg.data.$$
 
66
        cat > /tmp/ogg.script.$$ << EOF
 
67
set xrange [0:*]
 
68
set yrange [0:*]
 
69
unset log
 
70
unset label
 
71
set xtic auto
 
72
set ytic auto
 
73
set xlabel "received"
 
74
set ylabel "spam"
 
75
set terminal png size 800,600
 
76
EOF
 
77
        echo set title \"$i received-spam scatter plot\" >> /tmp/ogg.script.$$
 
78
        echo set output '"'/tmp/ogg.png.$$'"' >> /tmp/ogg.script.$$
 
79
        echo plot '"'/tmp/ogg.data.$$'"' using 1:2:3 notitle with circles >> /tmp/ogg.script.$$
 
80
        gnuplot /tmp/ogg.script.$$ | fgrep -v "empty y"
 
81
        rm -f /tmp/ogg.script.$$ -f /tmp/ogg.data.$$
 
82
        mv /tmp/ogg.png.$$ $GRAPHDIR/$i.png
 
83
        echo '<img src="'$i.png'">' >> $OUTPUT
 
84
        echo "" >> $OUTPUT
 
85
done
 
86
 
 
87
echo '<a name="unsigned"></a>' >> $OUTPUT
 
88
echo "<p> unsigned mail: </p>" >> $OUTPUT
 
89
$MYSQL --execute="SELECT t1.msgs, t1.spam, COUNT(*) FROM (SELECT COUNT(*) AS msgs, SUM(spam) AS spam FROM messages JOIN reporters ON reporters.id = messages.reporter WHERE enabled = 1 AND NOT EXISTS (SELECT * FROM signatures WHERE signatures.message = messages.id AND signatures.pass = 1) AND NOT spam = -1 GROUP BY DATE(msgtime)) AS t1 GROUP BY t1.msgs, t1.spam" > /tmp/ogg.data.$$
 
90
cat > /tmp/ogg.script.$$ << EOF
 
91
set xrange [0:*]
 
92
set yrange [0:*]
 
93
unset log
 
94
unset label
 
95
set xtic auto
 
96
set ytic auto
 
97
set xlabel "received"
 
98
set ylabel "spam"
 
99
set terminal png size 800,600
 
100
EOF
 
101
echo set title \"unsigned mail received-spam scatter plot\" >> /tmp/ogg.script.$$
 
102
echo set output '"'/tmp/ogg.png.$$'"' >> /tmp/ogg.script.$$
 
103
echo plot '"'/tmp/ogg.data.$$'"' using 1:2:3 notitle with circles >> /tmp/ogg.script.$$
 
104
gnuplot /tmp/ogg.script.$$ | fgrep -v "empty y"
 
105
rm -f /tmp/ogg.script.$$ -f /tmp/ogg.data.$$
 
106
mv /tmp/ogg.png.$$ $GRAPHDIR/unsigned.png
 
107
echo '<img src="unsigned.png">' >> $OUTPUT
 
108
echo "" >> $OUTPUT
 
109
 
 
110
# output a footer
 
111
echo "<hr>" >> $OUTPUT
 
112
echo '<font size="-1"> <i> $Id: opendkim-gengraphs,v 1.26 2010/10/27 06:18:45 cm-msk Exp $ </i> </font>' >> $OUTPUT
 
113
cat >> $OUTPUT << EOF
 
114
  </body>
 
115
</html>
 
116
EOF
 
117
 
 
118
# all done!
 
119
mv $OUTPUT $REALOUTPUT
 
120
exit 0