mirror of
https://github.com/netbox-community/netbox.git
synced 2025-07-22 12:06:53 -06:00
Adds ip to failed logs (#12725)
* adds ip to failed logs #12562 * added additional logging when client ip cannot be determined
This commit is contained in:
parent
e2f9a3c07a
commit
5869894a48
@ -1,10 +1,18 @@
|
|||||||
import logging
|
import logging
|
||||||
from django.dispatch import receiver
|
from django.dispatch import receiver
|
||||||
from django.contrib.auth.signals import user_login_failed
|
from django.contrib.auth.signals import user_login_failed
|
||||||
|
from utilities.request import get_client_ip
|
||||||
|
|
||||||
|
|
||||||
@receiver(user_login_failed)
|
@receiver(user_login_failed)
|
||||||
def log_user_login_failed(sender, credentials, request, **kwargs):
|
def log_user_login_failed(sender, credentials, request, **kwargs):
|
||||||
logger = logging.getLogger('netbox.auth.login')
|
logger = logging.getLogger('netbox.auth.login')
|
||||||
username = credentials.get("username")
|
username = credentials.get("username")
|
||||||
logger.info(f"Failed login attempt for username: {username}")
|
if client_ip := get_client_ip(request):
|
||||||
|
logger.info(f"Failed login attempt for username: {username} from {client_ip}")
|
||||||
|
else:
|
||||||
|
logger.warning(
|
||||||
|
"Client IP address could not be determined for validation. Check that the HTTP server is properly "
|
||||||
|
"configured to pass the required header(s)."
|
||||||
|
)
|
||||||
|
logger.info(f"Failed login attempt for username: {username}")
|
||||||
|
Loading…
Reference in New Issue
Block a user