Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add check_elasticsearch test #13

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,16 @@ Verify a static file is reachable

- `filename` (`str`): static file to verify

---

```python
def check_elasticsearch(settings)
```

- `settings` (`dict`): Parameter that will be passed to Elasticsearch()

Ping ElasticSearch to check it is alive. Needs `elasticsearch` package to be installed.

## Management Command

In addition to the view, the configured healthchecks can also be run via a management command with `manage.py healthcheck`. This will exit with an error code if all the healthchecks do not pass.
Expand Down
19 changes: 19 additions & 0 deletions django_alive/checks.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,25 @@ def check_cache(key="django-alive", cache="default"):
raise HealthcheckFailure("cache error")


def check_elasticsearch(settings={}):
# type: (dict) -> None
"""
Ping the Elasticsearch server to verify it's reachable

:param dict settings: Elasticsearch settings
:return None:
"""
try:
from elasticsearch import Elasticsearch
ping = Elasticsearch(settings).ping()
except Exception:
log.exception("elasticsearch connection failed")
raise HealthcheckFailure("elasticsearch exception")
if not ping:
log.error("elasticsearch ping failed")
raise HealthcheckFailure("elasticsearch error")


def check_migrations(alias=None):
# type: (Optional[str]) -> None
"""
Expand Down
Loading