forked from GithubBackups/healthchecks
Add support for multiple, comma-separated keywords (cc: #396)
This commit is contained in:
parent
5acea4c89d
commit
43e56ce788
@ -14,6 +14,7 @@ All notable changes to this project will be documented in this file.
|
|||||||
- Spike.sh integration (#402)
|
- Spike.sh integration (#402)
|
||||||
- Updated Discord integration to use discord.com instead of discordapp.com
|
- Updated Discord integration to use discord.com instead of discordapp.com
|
||||||
- Add "Failure Keyword" filtering for inbound emails (#396)
|
- Add "Failure Keyword" filtering for inbound emails (#396)
|
||||||
|
- Add support for multiple, comma-separated keywords (#396)
|
||||||
|
|
||||||
### Bug Fixes
|
### Bug Fixes
|
||||||
- Removing Pager Team integration, project appears to be discontinued
|
- Removing Pager Team integration, project appears to be discontinued
|
||||||
|
@ -12,6 +12,15 @@ RE_UUID = re.compile(
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def _match(subject, keywords):
|
||||||
|
for s in keywords.split(","):
|
||||||
|
s = s.strip()
|
||||||
|
if s and s in subject:
|
||||||
|
return True
|
||||||
|
|
||||||
|
return False
|
||||||
|
|
||||||
|
|
||||||
def _process_message(remote_addr, mailfrom, mailto, data):
|
def _process_message(remote_addr, mailfrom, mailto, data):
|
||||||
to_parts = mailto.split("@")
|
to_parts = mailto.split("@")
|
||||||
code = to_parts[0]
|
code = to_parts[0]
|
||||||
@ -33,9 +42,9 @@ def _process_message(remote_addr, mailfrom, mailto, data):
|
|||||||
if check.subject or check.subject_fail:
|
if check.subject or check.subject_fail:
|
||||||
action = "ign"
|
action = "ign"
|
||||||
subject = email.message_from_string(data).get("subject", "")
|
subject = email.message_from_string(data).get("subject", "")
|
||||||
if check.subject and check.subject in subject:
|
if check.subject and _match(subject, check.subject):
|
||||||
action = "success"
|
action = "success"
|
||||||
elif check.subject_fail and check.subject_fail in subject:
|
elif check.subject_fail and _match(subject, check.subject_fail):
|
||||||
action = "fail"
|
action = "fail"
|
||||||
|
|
||||||
ua = "Email from %s" % mailfrom
|
ua = "Email from %s" % mailfrom
|
||||||
|
@ -74,3 +74,27 @@ class SmtpdTestCase(BaseTestCase):
|
|||||||
self.assertEqual(ping.scheme, "email")
|
self.assertEqual(ping.scheme, "email")
|
||||||
self.assertEqual(ping.ua, "Email from foo@example.org")
|
self.assertEqual(ping.ua, "Email from foo@example.org")
|
||||||
self.assertEqual(ping.kind, "ign")
|
self.assertEqual(ping.kind, "ign")
|
||||||
|
|
||||||
|
def test_it_handles_multiple_subject_keywords(self):
|
||||||
|
self.check.subject = "SUCCESS, OK"
|
||||||
|
self.check.save()
|
||||||
|
|
||||||
|
body = PAYLOAD_TMPL % "[OK] Backup completed"
|
||||||
|
_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, None)
|
||||||
|
|
||||||
|
def test_it_handles_multiple_subject_fail_keywords(self):
|
||||||
|
self.check.subject_fail = "FAIL, WARNING"
|
||||||
|
self.check.save()
|
||||||
|
|
||||||
|
body = PAYLOAD_TMPL % "[WARNING] 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")
|
||||||
|
@ -73,12 +73,7 @@
|
|||||||
</p>
|
</p>
|
||||||
<code>{{ check.url }}</code>
|
<code>{{ check.url }}</code>
|
||||||
<p>
|
<p>
|
||||||
{% if check.subject %}
|
|
||||||
Or by sending emails with "{{ check.subject }}"
|
|
||||||
in the subject line to this address:
|
|
||||||
{% else %}
|
|
||||||
Or by sending emails to this address:
|
Or by sending emails to this address:
|
||||||
{% endif %}
|
|
||||||
</p>
|
</p>
|
||||||
<code>{{ check.email }}</code>
|
<code>{{ check.email }}</code>
|
||||||
|
|
||||||
|
@ -61,7 +61,7 @@
|
|||||||
|
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<label for="update-name-input" class="col-sm-4 control-label">
|
<label for="update-name-input" class="col-sm-4 control-label">
|
||||||
Success Keyword
|
Success Keywords
|
||||||
</label>
|
</label>
|
||||||
<div class="col-sm-7">
|
<div class="col-sm-7">
|
||||||
<input
|
<input
|
||||||
@ -71,14 +71,14 @@
|
|||||||
{% if not check.subject and not check.subject_fail %}disabled{% endif %}
|
{% if not check.subject and not check.subject_fail %}disabled{% endif %}
|
||||||
class="input-name form-control filter-by-subject" />
|
class="input-name form-control filter-by-subject" />
|
||||||
<span class="help-block">
|
<span class="help-block">
|
||||||
If Subject contains this keyword,
|
Comma-separated list of keywords. If Subject contains
|
||||||
treat it as "success".
|
any of the keywords, treat it as "success".
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<label for="update-name-input" class="col-sm-4 control-label">
|
<label for="update-name-input" class="col-sm-4 control-label">
|
||||||
Failure Keyword
|
Failure Keywords
|
||||||
</label>
|
</label>
|
||||||
<div class="col-sm-7">
|
<div class="col-sm-7">
|
||||||
<input
|
<input
|
||||||
@ -88,8 +88,8 @@
|
|||||||
{% if not check.subject and not check.subject_fail %}disabled{% endif %}
|
{% if not check.subject and not check.subject_fail %}disabled{% endif %}
|
||||||
class="input-name form-control filter-by-subject" />
|
class="input-name form-control filter-by-subject" />
|
||||||
<span class="help-block">
|
<span class="help-block">
|
||||||
If Subject contains this keyword,
|
Comma-separated list of keywords. If Subject contains
|
||||||
treat it as "failure".
|
any of the keywords, treat it as "failure".
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user