I am trying to send a notification on a failed login attempt.
I found this forum post but since I moved all automations to AppDaemon and will never go back I wonder if someone managed to do this in AppDaemon?
i think nowaday HA creates an event for login/bad login.
i am not sure, but if thats the case you can use listen_event for it.
And if there is no event, there is the file sensor for tracking log files
i did some seaching and it seems that in automations they use the entity persistent_notification.httplogin as trigger.
so i think you can use
self.listen_state(self.callback,"persistent_notification.httplogin")
edit i did put in that line in a test app.
a failed login gives notifying as new and state as attribute.
so that line can be used
and here a complete app.
import appdaemon.plugins.hass.hassapi as hass
class test(hass.Hass):
def initialize(self):
self.listen_state(self.test,"persistent_notification.httplogin")
def test(self, entity, attribute, old, new, kwargs):
if new=="notifying": #to make sure that the entity exists, otherwise it will create an error when you close the notification
test = self.get_state("persistent_notification.httplogin",attribute="message")
self.log(test)
the testvariable can be used to as message for a notify
result:
INFO: test: Login attempt or request with invalid authentiocation from IP_ADRESS
Thank you.
Works like a charm.
Only thing is that the login request originates from 127.0.0.1 aka my apache2 reverse proxy.
Does anyone know how to get around that?
thats because of a setting in apache, you need to tell it to forward the original ip.
Apache2 is already sending all the information.
In the Homeassistant config one has to add
use_x_forwarded_for: True
to the http component.