From 6b16c34fd0ba89743ad3caf04fac1a6d62ce121a Mon Sep 17 00:00:00 2001 From: Daniel Perna Date: Thu, 30 Apr 2020 22:07:07 +0200 Subject: [PATCH] Improve logging for unregistered webhooks (#34882) * Improve logging for unregistered webhooks * Address comment, KEY_REAL_IP * Address comment, read(64) * Lint --- homeassistant/components/webhook/__init__.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/homeassistant/components/webhook/__init__.py b/homeassistant/components/webhook/__init__.py index 84ebdaddad0..04332166c60 100644 --- a/homeassistant/components/webhook/__init__.py +++ b/homeassistant/components/webhook/__init__.py @@ -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: