Improve logging for unregistered webhooks (#34882)

* Improve logging for unregistered webhooks

* Address comment, KEY_REAL_IP

* Address comment, read(64)

* Lint
This commit is contained in:
Daniel Perna 2020-04-30 22:07:07 +02:00 committed by GitHub
parent d4b66717a4
commit 6b16c34fd0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -7,6 +7,7 @@ import voluptuous as vol
from homeassistant.components import websocket_api
from homeassistant.components.http.view import HomeAssistantView
from homeassistant.components.http.const import KEY_REAL_IP
from homeassistant.const import HTTP_OK
from homeassistant.core import callback
from homeassistant.loader import bind_hass
@ -71,7 +72,14 @@ async def async_handle_webhook(hass, webhook_id, request):
# Always respond successfully to not give away if a hook exists or not.
if webhook is None:
_LOGGER.warning("Received message for unregistered webhook %s", webhook_id)
peer_ip = request[KEY_REAL_IP]
_LOGGER.warning(
"Received message for unregistered webhook %s from %s", webhook_id, peer_ip
)
# Look at content to provide some context for received webhook
# Limit to 64 chars to avoid flooding the log
content = await request.content.read(64)
_LOGGER.debug("%s...", content)
return Response(status=HTTP_OK)
try: