-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
IDPF-92 Added Logging & Deployment Fixes (#19)
- Loading branch information
1 parent
905da4b
commit ac9af23
Showing
11 changed files
with
118 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
web: python manage.py check --deploy && python manage.py migrate --noinput && python manage.py clearcache && granian --interface wsgi config.wsgi:application --host 0.0.0.0 --port $PORT | ||
web: python manage.py check --deploy && python manage.py migrate --noinput && granian --interface wsgi config.wsgi:application --host 0.0.0.0 --port $PORT |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
from django.apps import AppConfig | ||
|
||
|
||
class PingdomConfig(AppConfig): | ||
name = "pingdom" | ||
verbose_name = "Pingdom config" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
from django.contrib.auth import get_user_model | ||
from django.db import DatabaseError | ||
|
||
|
||
class CheckDatabase: | ||
name = "database" | ||
|
||
def check(self): | ||
try: | ||
user = get_user_model() | ||
user.objects.all().exists() | ||
return True, "" | ||
except DatabaseError as e: | ||
return False, e | ||
|
||
|
||
services_to_check = (CheckDatabase,) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
from django.shortcuts import reverse | ||
from django.test import TestCase | ||
|
||
|
||
class PingdomTest(TestCase): | ||
def test_ping_response(self): | ||
url = reverse("pingdom") | ||
response = self.client.get(url) | ||
|
||
self.assertEqual(response.status_code, 200) | ||
assert "<status>OK</status>" in str(response.content) | ||
assert response.headers["content-type"] == "text/xml" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
from django.urls import path | ||
|
||
from .views import pingdom | ||
|
||
|
||
urlpatterns = [ | ||
path("ping.xml", pingdom, name="pingdom"), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
from django.http import HttpResponse | ||
|
||
from .services import services_to_check | ||
|
||
|
||
PINGDOM_TEMPLATE = """<?xml version="1.0" encoding="UTF-8"?> | ||
<pingdom_http_custom_check> | ||
<status>{status}</status> | ||
</pingdom_http_custom_check>\n""" | ||
|
||
COMMENT_TEMPLATE = "<!--{comment}-->\n" | ||
|
||
|
||
def pingdom(request): | ||
checked = {} | ||
for service in services_to_check: | ||
checked[service.name] = service().check() | ||
|
||
if all(item[0] for item in checked.values()): | ||
return HttpResponse( | ||
PINGDOM_TEMPLATE.format(status="OK"), content_type="text/xml" | ||
) | ||
else: | ||
body = PINGDOM_TEMPLATE.format(status="FALSE") | ||
for service_result in filter(lambda x: x[0] is False, checked.values()): | ||
body += COMMENT_TEMPLATE.format(comment=service_result[1]) | ||
return HttpResponse(body, status=500, content_type="text/xml") |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.