16 Small log parser class to parse and summarize NiX Spam DNSBL lookup |
16 Small log parser class to parse and summarize NiX Spam DNSBL lookup |
17 based rejects from a mail log file. |
17 based rejects from a mail log file. |
18 """ |
18 """ |
19 __slots__ = ('_doms', '_mxs', '_repo') |
19 __slots__ = ('_doms', '_mxs', '_repo') |
20 |
20 |
|
21 RE_FQDN = '(?:[a-z0-9-]{1,63}\.){1,}[a-z]{2,6}' |
|
22 RE_IPv4 = '(?:[\d]{1,3}\.){3}[\d]{1,3}' |
21 """Regular expression pattern for mail logs from Postfix""" |
23 """Regular expression pattern for mail logs from Postfix""" |
22 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.*$''' |
24 RE_PF = r'''^[\w\s:-]{17,80}\spostfix\/smtpd\[[\d]{1,5}\]:\sNOQUEUE: |
|
25 \sreject:.*blocked\susing\six.dnsbl.manitu.net; |
|
26 \sSpam\ssent\sto\sthe\smailhost\s(%s|%s) |
|
27 \swas\sdetected\sby\sNiX\sSpam.*$''' % (RE_FQDN, RE_IPv4) |
|
28 |
23 |
29 |
24 def __init__(self): |
30 def __init__(self): |
25 self._doms = {} |
31 self._doms = {} |
26 self._mxs = {} |
32 self._mxs = {} |
27 self._repo = None |
33 self._repo = None |
28 |
34 |
29 def setLogFormat(self, format='postfix'): |
35 def setLogFormat(self, format='postfix'): |
30 if format == 'postfix': |
36 if format == 'postfix': |
31 self._repo = re.compile(NiXSapmSum.RE_PF) |
37 self._repo = re.compile(NiXSapmSum.RE_PF, re.VERBOSE) |
32 else: |
38 else: |
33 raise Exception('MTA/Logformat not supported yet.') |
39 raise Exception('MTA/Logformat not supported yet.') |
34 |
40 |
35 def parseLog(self, filehandle): |
41 def parseLog(self, filehandle): |
36 for l in filehandle: |
42 for l in filehandle: |