equal
deleted
inserted
replaced
8 __date__ = '2009-07-03' |
8 __date__ = '2009-07-03' |
9 |
9 |
10 import os |
10 import os |
11 import re |
11 import re |
12 |
12 |
13 class NiXSapmSum: |
13 class NiXSapmSum(object): |
14 """Do sth ...""" |
14 """ |
|
15 Small log parser class to parse and summarize NiX Spam DNSBL lookup |
|
16 based rejects from a mail log file. |
|
17 """ |
|
18 __slots__ = ('_doms', '_mxs', '_repo') |
15 |
19 |
16 """Regular expression pattern for mail logs from Postfix""" |
20 """Regular expression pattern for mail logs from Postfix""" |
17 RE_PF = '''^[\w\s:-]{17,80}\spostfix\/smtpd\[[\d]{3,5}\]: NOQUEUE: reject:.*blocked using ix.dnsbl.manitu.net; Spam sent to the mailhost ((?:[a-z0-9-]{1,63}\.){1,}[a-z]{2,6}) was detected by NiX Spam.*$''' |
21 RE_PF = '''^[\w\s:-]{17,80}\spostfix\/smtpd\[[\d]{3,5}\]: NOQUEUE: reject:.*blocked using ix.dnsbl.manitu.net; Spam sent to the mailhost ((?:[a-z0-9-]{1,63}\.){1,}[a-z]{2,6}) was detected by NiX Spam.*$''' |
18 |
22 |
19 def __init__(self): |
23 def __init__(self): |
51 def getMXs(self): |
55 def getMXs(self): |
52 return self._mxs |
56 return self._mxs |
53 |
57 |
54 def getOptionParser(): |
58 def getOptionParser(): |
55 from optparse import OptionParser |
59 from optparse import OptionParser |
56 description = 'do something ...' |
60 description = 'NiX Spam DNSBL lookup based rejects summarizer' |
57 usage = 'usage: %prog [options] maillog [maillog [...]]' |
61 usage = 'usage: %prog [options] maillog [maillog [...]]' |
58 version = '%prog '+__version__ |
62 version = '%prog '+__version__ |
59 parser = OptionParser(description=description,usage=usage,version=version) |
63 parser = OptionParser(description=description,usage=usage,version=version) |
60 parser.add_option('-d', action='store_true', dest='countByDom', |
64 parser.add_option('-d', action='store_true', dest='countByDom', |
61 default=False, help='summarize all MX by domain') |
65 default=False, help='summarize all MX by domain') |
112 nixspamsum.countByDom() |
116 nixspamsum.countByDom() |
113 domains = nixspamsum.getDomains() |
117 domains = nixspamsum.getDomains() |
114 else: |
118 else: |
115 domains = nixspamsum.getMXs() |
119 domains = nixspamsum.getMXs() |
116 if not len(domains): |
120 if not len(domains): |
117 print "No Nix Spam RBL rejects found" |
121 print "No NiX Spam DNSBL rejects found" |
118 return |
122 return |
119 |
123 |
120 from cStringIO import StringIO |
124 from cStringIO import StringIO |
121 output = StringIO() |
125 output = StringIO() |
122 # build the table |
126 # build the table |
138 parser = getOptionParser() |
142 parser = getOptionParser() |
139 opts, args = parser.parse_args() |
143 opts, args = parser.parse_args() |
140 if opts.oFormat not in ('csv', 'table'): |
144 if opts.oFormat not in ('csv', 'table'): |
141 parser.error("Output format '%s' is not supported" % opts.oFormat) |
145 parser.error("Output format '%s' is not supported" % opts.oFormat) |
142 if len(args) < 1: |
146 if len(args) < 1: |
143 parser.error('No logfiles specified') |
147 parser.error('No log file specified') |
144 nixss = NiXSapmSum() |
148 nixss = NiXSapmSum() |
145 nixss.setLogFormat(opts.format) |
149 nixss.setLogFormat(opts.format) |
146 for fn in args: |
150 for fn in args: |
147 fh = openLogFile(fn) |
151 fh = openLogFile(fn) |
148 if fh is not None: |
152 if fh is not None: |