forked from GithubBackups/healthchecks
Email webhook not used any more, removing.
This commit is contained in:
parent
267db8a594
commit
b52edd903d
@ -1,37 +0,0 @@
|
||||
import json
|
||||
|
||||
from django.test import TestCase
|
||||
|
||||
from hc.api.models import Check, Ping
|
||||
|
||||
|
||||
class EmailTestCase(TestCase):
|
||||
|
||||
def test_it_works(self):
|
||||
check = Check()
|
||||
check.save()
|
||||
|
||||
payload = [{
|
||||
"event": "inbound",
|
||||
"msg": {
|
||||
"raw_msg": "This is raw message",
|
||||
"to": [
|
||||
["somewhere@example.com", "Somebody"],
|
||||
["%s@example.com" % check.code, "Healthchecks"]
|
||||
]
|
||||
}
|
||||
}]
|
||||
|
||||
data = {"mandrill_events": json.dumps(payload)}
|
||||
r = self.client.post("/handle_email/", data=data)
|
||||
assert r.status_code == 200
|
||||
|
||||
same_check = Check.objects.get(code=check.code)
|
||||
assert same_check.status == "up"
|
||||
|
||||
pings = list(Ping.objects.all())
|
||||
assert pings[0].scheme == "email"
|
||||
|
||||
def test_it_rejects_get(self):
|
||||
r = self.client.get("/handle_email/")
|
||||
assert r.status_code == 400
|
@ -5,6 +5,5 @@ from hc.api import views
|
||||
urlpatterns = [
|
||||
url(r'^ping/([\w-]+)/$', views.ping, name="hc-ping-slash"),
|
||||
url(r'^ping/([\w-]+)$', views.ping, name="hc-ping"),
|
||||
url(r'^handle_email/$', views.handle_email, name="hc-handle-email"),
|
||||
url(r'^api/v1/checks/$', views.create_check),
|
||||
]
|
||||
|
@ -45,37 +45,6 @@ def ping(request, code):
|
||||
return response
|
||||
|
||||
|
||||
@csrf_exempt
|
||||
def handle_email(request):
|
||||
if request.method != "POST":
|
||||
return HttpResponseBadRequest()
|
||||
|
||||
events = json.loads(request.POST["mandrill_events"])
|
||||
for event in events:
|
||||
for recipient_address, recipient_name in event["msg"]["to"]:
|
||||
code, domain = recipient_address.split("@")
|
||||
try:
|
||||
check = Check.objects.get(code=code)
|
||||
except ValueError:
|
||||
continue
|
||||
except Check.DoesNotExist:
|
||||
continue
|
||||
|
||||
check.n_pings = F("n_pings") + 1
|
||||
check.last_ping = timezone.now()
|
||||
if check.status == "new":
|
||||
check.status = "up"
|
||||
|
||||
check.save()
|
||||
|
||||
ping = Ping(owner=check)
|
||||
ping.scheme = "email"
|
||||
ping.save()
|
||||
|
||||
response = HttpResponse("OK")
|
||||
return response
|
||||
|
||||
|
||||
@csrf_exempt
|
||||
@check_api_key
|
||||
@validate_json(schemas.check)
|
||||
@ -84,11 +53,11 @@ def create_check(request):
|
||||
code = 200
|
||||
response = {
|
||||
"checks": [{
|
||||
"name": check.name,
|
||||
"ping_url" : check.url(),
|
||||
"tags": check.tags,
|
||||
"timeout": int(check.timeout.total_seconds()),
|
||||
"grace": int(check.grace.total_seconds()),
|
||||
"name": check.name,
|
||||
"ping_url": check.url(),
|
||||
"tags": check.tags,
|
||||
"timeout": int(check.timeout.total_seconds()),
|
||||
"grace": int(check.grace.total_seconds()),
|
||||
# "channels": check.channels,
|
||||
} for check in Check.objects.filter(user=request.user)]
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user