Added error handling code to regex, do not refresh regex for each parsed line, indicated maintenance steps to remedy regex error, hint on ignored private IPs for proxy debug

This commit is contained in:
Thorbjörn Jörger 2023-04-13 12:15:58 +02:00
parent f681fcf154
commit ed9b239af7
No known key found for this signature in database
GPG Key ID: 82701519391A1DCD
1 changed files with 10 additions and 4 deletions

View File

@ -325,21 +325,27 @@ def watch():
global exit_code global exit_code
while not quit_now: while not quit_now:
refreshF2bregex()
try: try:
for item in pubsub.listen(): for item in pubsub.listen():
refreshF2bregex()
for rule_id, rule_regex in f2bregex.items(): for rule_id, rule_regex in f2bregex.items():
if item['data'] and item['type'] == 'message': if item['data'] and item['type'] == 'message':
try: try:
result = re.search(rule_regex, item['data']) result = re.search(rule_regex, item['data'])
except re.error: except re.error:
result = False continue
if result: if result:
addr = result.group(1) try:
addr = result.group(1)
except IndexError as ex:
logWarn('Error parsing log line from pubsub: %s, rule id: %s, log line %s' % (ex, rule_id, item['data']))
logInfo('Check if your regular expressions are up to date: https://github.com/mailcow/mailcow-dockerized/issues/5125')
continue
ip = ipaddress.ip_address(addr) ip = ipaddress.ip_address(addr)
if ip.is_private or ip.is_loopback: if ip.is_private or ip.is_loopback:
logWarn('%s matched rule id: %s, log line: %s´, but was ignored as it is a private or loopback IP' % (addr, rule_id, item['data']))
continue continue
logWarn('%s matched rule id %s (%s)' % (addr, rule_id, item['data'])) logWarn('%s matched rule id: %s, log line: %s' % (addr, rule_id, item['data']))
ban(addr) ban(addr)
except Exception as ex: except Exception as ex:
logWarn('Error reading log line from pubsub: %s' % ex) logWarn('Error reading log line from pubsub: %s' % ex)