Projet

Général

Profil

Paste
Télécharger au format
Statistiques
| Branche: | Révision:

root / plugins / mail / spamd-tarpit-bsd @ e5ce7492

Historique | Voir | Annoter | Télécharger (2,7 ko)

1 28724197 Net Easy, Inc
#!/usr/bin/env python
2
3
# Copyright (c) 2008, Net Easy, Inc.
4
# All rights reserved.
5
#
6
# Redistribution and use in source and binary forms, with or without
7
# modification, are permitted provided that the following conditions are met:
8
#     * Redistributions of source code must retain the above copyright
9
#       notice, this list of conditions and the following disclaimer.
10
#     * Redistributions in binary form must reproduce the above copyright
11
#       notice, this list of conditions and the following disclaimer in the
12
#       documentation and/or other materials provided with the distribution.
13
#     * Neither the name of Net Easy, Inc. nor the
14
#       names of its contributors may be used to endorse or promote products
15
#       derived from this software without specific prior written permission.
16
#
17
# THIS SOFTWARE IS PROVIDED BY Net Easy, Inc. ''AS IS'' AND ANY
18
# EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20
# DISCLAIMED. IN NO EVENT SHALL Net Easy, Inc. BE LIABLE FOR ANY
21
# DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
22
# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
23
# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
24
# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
26
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27
28
# requires logcheck from ports
29
30
import re, os
31
from sys import argv
32
33
logfile = "/var/log/daemon"
34
35
class checker(object):
36
    def __init__(self):
37
        self.tarpit_count = 0
38
        self.tarpit_total = 0
39
40
    def __repr__(self):
41
        return "tarpit.value %s" % (self.tarpit_average())
42
43
    def tarpit_average(self):
44
        if self.tarpit_count > 0:
45
            return "%.1f" % (self.tarpit_total / self.tarpit_count)
46
        else:
47
            return 0
48
49
    def process_line(self, line):
50
        if re.search(' disconnected after ', line):
51
            self.tarpit_count += 1
52
            tarpit_time = re.sub('^.*after ','',re.sub(' second.*$','',line))
53
            self.tarpit_total += int(tarpit_time)
54
55
    def process_lines(self, file):
56
        for line in os.popen('logtail %s %s.tp.offset' % (file, file)).readlines():
57
            self.process_line(line)
58
59
if __name__ == "__main__":
60
    if len(argv) > 1 and argv[1] == 'config':
61
        print """graph_title spamd delay
62
graph_vlabel Average delay.
63
graph_category Mail
64
graph_info Average time spammers delayed by spamd
65
tarpit.label Average tarpit delay"""
66
67
    else:
68
        processor = checker()
69
        processor.process_lines(logfile)
70
        print processor
71