Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/valentinogagliardi/django-monitus
HTTP error reporting middleware(s) for Django
https://github.com/valentinogagliardi/django-monitus
asynchronous asynchronous-django django django-middleware python
Last synced: about 1 month ago
JSON representation
HTTP error reporting middleware(s) for Django
- Host: GitHub
- URL: https://github.com/valentinogagliardi/django-monitus
- Owner: valentinogagliardi
- License: mit
- Created: 2020-12-19T20:14:05.000Z (almost 4 years ago)
- Default Branch: main
- Last Pushed: 2020-12-28T11:05:17.000Z (almost 4 years ago)
- Last Synced: 2024-10-11T07:12:31.734Z (about 1 month ago)
- Topics: asynchronous, asynchronous-django, django, django-middleware, python
- Language: Python
- Homepage: https://pypi.org/project/django-monitus/
- Size: 36.1 KB
- Stars: 18
- Watchers: 3
- Forks: 0
- Open Issues: 6
-
Metadata Files:
- Readme: README.rst
- License: LICENSE
Awesome Lists containing this project
- stars - valentinogagliardi/django-monitus - HTTP error reporting middleware(s) for Django (Python)
- stars - valentinogagliardi/django-monitus - HTTP error reporting middleware(s) for Django (Python)
README
===================
django-monitus
===================.. image:: https://img.shields.io/twitter/follow/gagliardi_vale?style=social
:target: https://twitter.com/gagliardi_vale.. image:: https://github.com/valentinogagliardi/django-monitus/workflows/Tox%20tests/badge.svg
:target: https://github.com/valentinogagliardi/django-monitus/actionsTiny error reporting middleware(s) for Django. Includes the following middlewares:
- ``Error403EmailsMiddleware``: sends an email to ``ADMINS`` on 403.
- ``FailedLoginMiddleware``: sends an email to ``ADMINS`` on failed logins.Requirements
------------Tested on Python 3.8.
Tested on Django 3.0 and 3.1.
Setup
------------
Install from pip:.. code-block:: sh
python -m pip install django-monitus
Then add it to the list of installed apps:
.. code-block:: python
INSTALLED_APPS = [
...
"monitus"
...
]Enable the desired middleware:
.. code-block:: python
MIDDLEWARE = [
...
"monitus.middleware.Error403EmailsMiddleware"
...
]Setup ``ADMINS`` in your settings:
.. code-block:: python
MANAGERS = [("Juliana C.", "[email protected]")]
Usage with asynchronous Django
------------------------------As of now only ``Error403EmailsMiddleware`` can run asynchronously under ASGI. If you plan to use ``FailedLoginMiddleware`` and ``Error403EmailsMiddleware`` together make sure to place ``Error403EmailsMiddleware`` **before** (reading top to bottom) ``FailedLoginMiddleware``:
.. code-block:: python
MIDDLEWARE = [
"monitus.middleware.FailedLoginMiddleware",
"monitus.middleware.Error403EmailsMiddleware" # this should go before FailedLoginMiddleware
...
]This way the async chain doesn't get broken when the response traverses the middleware chain to exit out to the user.
Development and testing
-----------------------To test on your local machine with Postgres, make sure to have a role with enough privileges:
.. code-block:: bash
CREATE ROLE monitustestuser WITH LOGIN PASSWORD 'monitustestpassword' CREATEDB;
Then run
.. code-block:: bash
DATABASE_URL=postgres://monitustestuser:monitustestpassword@localhost/monitustestdb tox