1 """Support for sending data to Logentries webhook endpoint."""
7 import voluptuous
as vol
15 _LOGGER = logging.getLogger(__name__)
19 DEFAULT_HOST =
"https://webhook.logentries.com/noformat/logs/"
21 CONFIG_SCHEMA = vol.Schema(
22 {DOMAIN: vol.Schema({vol.Required(CONF_TOKEN): cv.string})}, extra=vol.ALLOW_EXTRA
26 def setup(hass: HomeAssistant, config: ConfigType) -> bool:
27 """Set up the Logentries component."""
29 token = conf.get(CONF_TOKEN)
30 le_wh = f
"{DEFAULT_HOST}{token}"
32 def logentries_event_listener(event):
33 """Listen for new messages on the bus and sends them to Logentries."""
34 if (state := event.data.get(
"new_state"))
is None:
37 _state = state_helper.state_as_number(state)
42 "domain": state.domain,
43 "entity_id": state.object_id,
44 "attributes":
dict(state.attributes),
45 "time":
str(event.time_fired),
50 payload = {
"host": le_wh,
"event": json_body}
51 requests.post(le_wh, data=json.dumps(payload), timeout=10)
52 except requests.exceptions.RequestException:
53 _LOGGER.exception(
"Error sending to Logentries")
55 hass.bus.listen(EVENT_STATE_CHANGED, logentries_event_listener)
bool setup(HomeAssistant hass, ConfigType config)