forked from GithubBackups/healthchecks
feat: treat failure before success
This commit is contained in:
parent
8a154cbaf5
commit
b70e2c9a25
@ -45,10 +45,10 @@ def _process_message(remote_addr, mailfrom, mailto, data):
|
|||||||
# Specify policy, the default policy does not decode encoded headers:
|
# Specify policy, the default policy does not decode encoded headers:
|
||||||
parsed = email.message_from_string(data, policy=email.policy.SMTP)
|
parsed = email.message_from_string(data, policy=email.policy.SMTP)
|
||||||
subject = parsed.get("subject", "")
|
subject = parsed.get("subject", "")
|
||||||
if check.subject and _match(subject, check.subject):
|
if check.subject_fail and _match(subject, check.subject_fail):
|
||||||
action = "success"
|
|
||||||
elif check.subject_fail and _match(subject, check.subject_fail):
|
|
||||||
action = "fail"
|
action = "fail"
|
||||||
|
elif check.subject and _match(subject, check.subject):
|
||||||
|
action = "success"
|
||||||
|
|
||||||
ua = "Email from %s" % mailfrom
|
ua = "Email from %s" % mailfrom
|
||||||
check.ping(remote_addr, "email", "", ua, data, action)
|
check.ping(remote_addr, "email", "", ua, data, action)
|
||||||
|
@ -99,6 +99,19 @@ class SmtpdTestCase(BaseTestCase):
|
|||||||
self.assertEqual(ping.ua, "Email from foo@example.org")
|
self.assertEqual(ping.ua, "Email from foo@example.org")
|
||||||
self.assertEqual(ping.kind, "fail")
|
self.assertEqual(ping.kind, "fail")
|
||||||
|
|
||||||
|
def test_it_handles_subject_fail_before_success(self):
|
||||||
|
self.check.subject = "SUCCESS"
|
||||||
|
self.check.subject_fail = "FAIL"
|
||||||
|
self.check.save()
|
||||||
|
|
||||||
|
body = PAYLOAD_TMPL % "[SUCCESS] 1 Backup completed, [FAIL] 1 Backup did not complete"
|
||||||
|
_process_message("1.2.3.4", "foo@example.org", self.email, body.encode("utf8"))
|
||||||
|
|
||||||
|
ping = Ping.objects.latest("id")
|
||||||
|
self.assertEqual(ping.scheme, "email")
|
||||||
|
self.assertEqual(ping.ua, "Email from foo@example.org")
|
||||||
|
self.assertEqual(ping.kind, "fail")
|
||||||
|
|
||||||
def test_it_handles_encoded_subject(self):
|
def test_it_handles_encoded_subject(self):
|
||||||
self.check.subject = "SUCCESS"
|
self.check.subject = "SUCCESS"
|
||||||
self.check.save()
|
self.check.save()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user