Browse Source

Email webhook not used any more, removing.

pull/60/head
Pēteris Caune 9 years ago
parent
commit
b52edd903d
3 changed files with 5 additions and 74 deletions
  1. +0
    -37
      hc/api/tests/test_email_webhook.py
  2. +0
    -1
      hc/api/urls.py
  3. +5
    -36
      hc/api/views.py

+ 0
- 37
hc/api/tests/test_email_webhook.py View File

@ -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": [
["[email protected]", "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

+ 0
- 1
hc/api/urls.py View File

@ -5,6 +5,5 @@ from hc.api import views
urlpatterns = [ urlpatterns = [
url(r'^ping/([\w-]+)/$', views.ping, name="hc-ping-slash"), url(r'^ping/([\w-]+)/$', views.ping, name="hc-ping-slash"),
url(r'^ping/([\w-]+)$', views.ping, name="hc-ping"), 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), url(r'^api/v1/checks/$', views.create_check),
] ]

+ 5
- 36
hc/api/views.py View File

@ -45,37 +45,6 @@ def ping(request, code):
return response 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 @csrf_exempt
@check_api_key @check_api_key
@validate_json(schemas.check) @validate_json(schemas.check)
@ -84,11 +53,11 @@ def create_check(request):
code = 200 code = 200
response = { response = {
"checks": [{ "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, # "channels": check.channels,
} for check in Check.objects.filter(user=request.user)] } for check in Check.objects.filter(user=request.user)]
} }


Loading…
Cancel
Save