GithubHelp home page GithubHelp logo

valentinogagliardi / django-monitus Goto Github PK

View Code? Open in Web Editor NEW
18.0 18.0 0.0 37 KB

HTTP error reporting middleware(s) for Django

Home Page: https://pypi.org/project/django-monitus/

License: MIT License

Python 100.00%
asynchronous asynchronous-django django django-middleware python

django-monitus's Introduction

django-monitus

https://img.shields.io/twitter/follow/gagliardi_vale?style=social

Tiny 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:

python -m pip install django-monitus

Then add it to the list of installed apps:

INSTALLED_APPS = [
...
"monitus"
...
]

Enable the desired middleware:

MIDDLEWARE = [
...
"monitus.middleware.Error403EmailsMiddleware"
...
]

Setup ADMINS in your settings:

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:

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:

CREATE ROLE monitustestuser WITH LOGIN PASSWORD 'monitustestpassword' CREATEDB;

Then run

DATABASE_URL=postgres://monitustestuser:monitustestpassword@localhost/monitustestdb tox

django-monitus's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

django-monitus's Issues

FailedLoginMiddleware sends on GET and HEAD

FailedLoginMiddleware should not send emails on GET and HEAD requests. Found the reason: form.error_messages is always pre-populated. The middleware must send emails only if the auth form has errors.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.