Module: check_mk
Branch: master
Commit: 48fdc66d1af62641229d5adcfa28629ed96d7e46
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=48fdc66d1af626…
Author: Andreas Boesl <ab(a)mathias-kettner.de>
Date: Thu Jan 7 09:47:17 2016 +0100
updated #2818
---
doc/treasures/active_checks/check_mail_loop | 13 +++++++++----
1 file changed, 9 insertions(+), 4 deletions(-)
diff --git a/doc/treasures/active_checks/check_mail_loop
b/doc/treasures/active_checks/check_mail_loop
old mode 100755
new mode 100644
index 8f5217c..97a8587
--- a/doc/treasures/active_checks/check_mail_loop
+++ b/doc/treasures/active_checks/check_mail_loop
@@ -205,6 +205,7 @@ socket.setdefaulttimeout(conn_timeout)
g_expected = {}
g_mails = {}
+g_obsolete = {}
g_M = None
def load_expected_mails():
@@ -241,7 +242,7 @@ def add_starttls_support(self, keyfile = None, certfile = None):
self.capabilities = tuple(self.untagged_responses[cap][-1].upper().split())
def fetch_mails():
- global g_M
+ global g_M, g_obsolete
if not g_expected:
return # not expecting any mail, do not check for mails
@@ -293,8 +294,6 @@ def fetch_mails():
ts = matches.group(1).strip()
key = matches.group(2).strip()
- if "%s-%s" % (ts, key) not in g_expected:
- continue
# extract received time
rx = msg.get('Received')
@@ -304,6 +303,12 @@ def fetch_mails():
# use current time as fallback where no Received header could be
found
rx_ts = int(time.time())
+ if "%s-%s" % (ts, key) not in g_expected:
+ # Delete any "Check_MK-Mail-Loop" messages older than 24
hours, even if they are not in our list
+ if delete_messages and int(time.time()) - rx_ts > 24 * 3600:
+ g_obsolete[ts+'-'+key] = (index, rx_ts)
+ continue
+
g_mails[ts+'-'+key] = (index, rx_ts)
except Exception, e:
@@ -402,7 +407,7 @@ def cleanup_mailbox():
try:
# Do not delete all messages in the inbox. Only the ones which were
# processed before! In the meantime there might be occured new ones.
- for ident, (mail_index, recv_ts) in g_mails.items():
+ for ident, (mail_index, recv_ts) in g_mails.items() + g_obsolete.items():
if fetch_proto == 'POP3':
response = g_M.dele(mail_index + 1)
if not response.startswith("+OK"):