django-health-check 4.0rc2__tar.gz → 4.0rc3__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {django_health_check-4.0rc2 → django_health_check-4.0rc3}/PKG-INFO +1 -1
- {django_health_check-4.0rc2 → django_health_check-4.0rc3}/health_check/_version.py +3 -3
- django_health_check-4.0rc3/health_check/management/commands/health_check.py +124 -0
- django_health_check-4.0rc2/health_check/management/commands/health_check.py +0 -46
- {django_health_check-4.0rc2 → django_health_check-4.0rc3}/LICENSE +0 -0
- {django_health_check-4.0rc2 → django_health_check-4.0rc3}/README.md +0 -0
- {django_health_check-4.0rc2 → django_health_check-4.0rc3}/health_check/__init__.py +0 -0
- {django_health_check-4.0rc2 → django_health_check-4.0rc3}/health_check/base.py +0 -0
- {django_health_check-4.0rc2 → django_health_check-4.0rc3}/health_check/checks.py +0 -0
- {django_health_check-4.0rc2 → django_health_check-4.0rc3}/health_check/contrib/__init__.py +0 -0
- {django_health_check-4.0rc2 → django_health_check-4.0rc3}/health_check/contrib/celery.py +0 -0
- {django_health_check-4.0rc2 → django_health_check-4.0rc3}/health_check/contrib/kafka.py +0 -0
- {django_health_check-4.0rc2 → django_health_check-4.0rc3}/health_check/contrib/rabbitmq.py +0 -0
- {django_health_check-4.0rc2 → django_health_check-4.0rc3}/health_check/contrib/redis.py +0 -0
- {django_health_check-4.0rc2 → django_health_check-4.0rc3}/health_check/contrib/rss.py +0 -0
- {django_health_check-4.0rc2 → django_health_check-4.0rc3}/health_check/exceptions.py +0 -0
- {django_health_check-4.0rc2 → django_health_check-4.0rc3}/health_check/management/__init__.py +0 -0
- {django_health_check-4.0rc2 → django_health_check-4.0rc3}/health_check/management/commands/__init__.py +0 -0
- {django_health_check-4.0rc2 → django_health_check-4.0rc3}/health_check/templates/health_check/index.html +0 -0
- {django_health_check-4.0rc2 → django_health_check-4.0rc3}/health_check/views.py +0 -0
- {django_health_check-4.0rc2 → django_health_check-4.0rc3}/pyproject.toml +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: django-health-check
|
|
3
|
-
Version: 4.
|
|
3
|
+
Version: 4.0rc3
|
|
4
4
|
Summary: Monitor the health of your Django app and its connected services.
|
|
5
5
|
Keywords: django,postgresql
|
|
6
6
|
Author-email: Kristian Ollegaard <kristian@oellegaard.com>, Johannes Maron <johannes@maron.family>
|
|
@@ -28,7 +28,7 @@ version_tuple: VERSION_TUPLE
|
|
|
28
28
|
commit_id: COMMIT_ID
|
|
29
29
|
__commit_id__: COMMIT_ID
|
|
30
30
|
|
|
31
|
-
__version__ = version = '4.
|
|
32
|
-
__version_tuple__ = version_tuple = (4, 0, '
|
|
31
|
+
__version__ = version = '4.0rc3'
|
|
32
|
+
__version_tuple__ = version_tuple = (4, 0, 'rc3')
|
|
33
33
|
|
|
34
|
-
__commit_id__ = commit_id = '
|
|
34
|
+
__commit_id__ = commit_id = 'g1e96d3f90'
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
import os
|
|
2
|
+
import sys
|
|
3
|
+
import urllib.error
|
|
4
|
+
import urllib.request
|
|
5
|
+
|
|
6
|
+
from django.conf import settings
|
|
7
|
+
from django.core.management.base import BaseCommand
|
|
8
|
+
from django.urls import NoReverseMatch, reverse
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
class Command(BaseCommand):
|
|
12
|
+
help = "Run health checks and exit 0 if everything went well."
|
|
13
|
+
|
|
14
|
+
@property
|
|
15
|
+
def default_forwarded_host(self):
|
|
16
|
+
return (
|
|
17
|
+
settings.ALLOWED_HOSTS[0].strip(".")
|
|
18
|
+
if settings.ALLOWED_HOSTS and settings.ALLOWED_HOSTS[0] != "*"
|
|
19
|
+
else None
|
|
20
|
+
)
|
|
21
|
+
|
|
22
|
+
@property
|
|
23
|
+
def default_addrport(self):
|
|
24
|
+
return ":".join([os.getenv("HOST", "127.0.0.1"), os.getenv("PORT", "8000")])
|
|
25
|
+
|
|
26
|
+
def add_arguments(self, parser):
|
|
27
|
+
parser.add_argument(
|
|
28
|
+
"endpoint",
|
|
29
|
+
type=str,
|
|
30
|
+
help="URL-pattern name of health check endpoint to test",
|
|
31
|
+
)
|
|
32
|
+
parser.add_argument(
|
|
33
|
+
"addrport",
|
|
34
|
+
nargs="?",
|
|
35
|
+
type=str,
|
|
36
|
+
default=self.default_addrport,
|
|
37
|
+
help=f"Optional port number, or ipaddr:port (default: {self.default_addrport})",
|
|
38
|
+
)
|
|
39
|
+
parser.add_argument(
|
|
40
|
+
"--forwarded-host",
|
|
41
|
+
type=str,
|
|
42
|
+
default=self.default_forwarded_host,
|
|
43
|
+
help=f"Value for X-Forwarded-Host header (default: {self.default_forwarded_host})",
|
|
44
|
+
)
|
|
45
|
+
parser.add_argument(
|
|
46
|
+
"--forwarded-proto",
|
|
47
|
+
type=str,
|
|
48
|
+
choices=["http", "https"],
|
|
49
|
+
default="https",
|
|
50
|
+
help="Value for X-Forwarded-Proto header (default: https)",
|
|
51
|
+
)
|
|
52
|
+
parser.add_argument(
|
|
53
|
+
"--timeout",
|
|
54
|
+
type=int,
|
|
55
|
+
default=5,
|
|
56
|
+
help="Timeout in seconds for the health check request (default: 5 seconds)",
|
|
57
|
+
)
|
|
58
|
+
|
|
59
|
+
def handle(self, *args, **options):
|
|
60
|
+
endpoint = options.get("endpoint")
|
|
61
|
+
try:
|
|
62
|
+
path = reverse(endpoint)
|
|
63
|
+
except NoReverseMatch as e:
|
|
64
|
+
self.stderr.write(
|
|
65
|
+
f"Could not resolve endpoint {endpoint!r}: {e}\n"
|
|
66
|
+
"Please provide a valid URL pattern name for the health check endpoint."
|
|
67
|
+
)
|
|
68
|
+
sys.exit(2)
|
|
69
|
+
addrport = options.get("addrport")
|
|
70
|
+
# Use HTTPS only when SSL redirect is enabled without forwarded headers (direct HTTPS required).
|
|
71
|
+
# Otherwise use HTTP (typical for containers with X-Forwarded-Proto header support).
|
|
72
|
+
proto = (
|
|
73
|
+
"https"
|
|
74
|
+
if settings.SECURE_SSL_REDIRECT and not settings.USE_X_FORWARDED_HOST
|
|
75
|
+
else "http"
|
|
76
|
+
)
|
|
77
|
+
url = f"{proto}://{addrport}{path}"
|
|
78
|
+
|
|
79
|
+
headers = {"Accept": "text/plain"}
|
|
80
|
+
|
|
81
|
+
# Add X-Forwarded-Host header
|
|
82
|
+
if forwarded_host := options.get("forwarded_host"):
|
|
83
|
+
headers["X-Forwarded-Host"] = forwarded_host
|
|
84
|
+
|
|
85
|
+
# Add X-Forwarded-Proto header
|
|
86
|
+
if forwarded_proto := options.get("forwarded_proto"):
|
|
87
|
+
headers["X-Forwarded-Proto"] = forwarded_proto
|
|
88
|
+
|
|
89
|
+
if options.get("verbosity", 1) >= 2:
|
|
90
|
+
self.stdout.write(
|
|
91
|
+
f"Checking health endpoint at {url!r} with headers: {headers}"
|
|
92
|
+
)
|
|
93
|
+
|
|
94
|
+
request = urllib.request.Request(url, headers=headers) # noqa: S310
|
|
95
|
+
try:
|
|
96
|
+
response = urllib.request.urlopen(request, timeout=options["timeout"]) # noqa: S310
|
|
97
|
+
except urllib.error.HTTPError as e:
|
|
98
|
+
match e.code:
|
|
99
|
+
case 500: # Health check failed
|
|
100
|
+
self.stdout.write(e.read().decode("utf-8"))
|
|
101
|
+
sys.exit(1)
|
|
102
|
+
case 400:
|
|
103
|
+
self.stderr.write(
|
|
104
|
+
f"{url!r} is not reachable: {e.reason}\nPlease check your ALLOWED_HOSTS setting or use the --forwarded-host option."
|
|
105
|
+
)
|
|
106
|
+
sys.exit(2)
|
|
107
|
+
case _:
|
|
108
|
+
self.stderr.write(
|
|
109
|
+
"Unexpected HTTP error "
|
|
110
|
+
f"when trying to reach {url!r}: {e}\n"
|
|
111
|
+
f"You may have selected an invalid endpoint {endpoint!r}"
|
|
112
|
+
f" or another application is running on {addrport!r}."
|
|
113
|
+
)
|
|
114
|
+
sys.exit(2)
|
|
115
|
+
except urllib.error.URLError as e:
|
|
116
|
+
self.stderr.write(
|
|
117
|
+
f"{url!r} is not reachable: {e.reason}\nPlease check your server is running and reachable."
|
|
118
|
+
)
|
|
119
|
+
sys.exit(2)
|
|
120
|
+
except TimeoutError as e:
|
|
121
|
+
self.stderr.write(f"Timeout when trying to reach {url!r}: {e}")
|
|
122
|
+
sys.exit(2)
|
|
123
|
+
else:
|
|
124
|
+
self.stdout.write(response.read().decode("utf-8"))
|
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
import sys
|
|
2
|
-
import urllib.error
|
|
3
|
-
import urllib.request
|
|
4
|
-
|
|
5
|
-
from django.core.management.base import BaseCommand
|
|
6
|
-
from django.urls import reverse
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
class Command(BaseCommand):
|
|
10
|
-
help = "Run health checks and exit 0 if everything went well."
|
|
11
|
-
|
|
12
|
-
def add_arguments(self, parser):
|
|
13
|
-
parser.add_argument(
|
|
14
|
-
"endpoint",
|
|
15
|
-
type=str,
|
|
16
|
-
help="URL-pattern name of health check endpoint to test",
|
|
17
|
-
)
|
|
18
|
-
parser.add_argument(
|
|
19
|
-
"addrport",
|
|
20
|
-
nargs="?",
|
|
21
|
-
type=str,
|
|
22
|
-
help="Optional port number, or ipaddr:port (default: localhost:8000)",
|
|
23
|
-
default="localhost:8000",
|
|
24
|
-
)
|
|
25
|
-
|
|
26
|
-
def handle(self, *args, **options):
|
|
27
|
-
endpoint = options.get("endpoint")
|
|
28
|
-
path = reverse(endpoint)
|
|
29
|
-
host, sep, port = options.get("addrport").partition(":")
|
|
30
|
-
url = f"http://{host}:{port}{path}" if sep else f"http://{host}{path}"
|
|
31
|
-
request = urllib.request.Request( # noqa: S310
|
|
32
|
-
url, headers={"Accept": "text/plain"}
|
|
33
|
-
)
|
|
34
|
-
try:
|
|
35
|
-
response = urllib.request.urlopen(request) # noqa: S310
|
|
36
|
-
except urllib.error.HTTPError as e:
|
|
37
|
-
# 500 status codes will raise HTTPError
|
|
38
|
-
self.stdout.write(e.read().decode("utf-8"))
|
|
39
|
-
sys.exit(1)
|
|
40
|
-
except urllib.error.URLError as e:
|
|
41
|
-
self.stderr.write(
|
|
42
|
-
f'"{url}" is not reachable: {e.reason}\nPlease check your ALLOWED_HOSTS setting.'
|
|
43
|
-
)
|
|
44
|
-
sys.exit(2)
|
|
45
|
-
else:
|
|
46
|
-
self.stdout.write(response.read().decode("utf-8"))
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{django_health_check-4.0rc2 → django_health_check-4.0rc3}/health_check/management/__init__.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|