jason0x43 / hubitatmaker

A Python library for interfacing with a Hubitat hub via its Maker API
MIT License
9 stars 7 forks source link

Listen on 0.0.0.0 #12

Open jason0x43 opened 3 years ago

jason0x43 commented 3 years ago

Currently, the event server attempts to listen on the specific interface used to reach the hubitat hub. In at least some cases, it appears to detect the wrong interface (jason0x43/hacs-hubitat#120).

Consider having the server listen on 0.0.0.0.

rehpa commented 1 year ago

I'm kind of wondering if this is what is causing me problems with my setup. I run HA in docker swarm, but not in Host mode for the network. I run it on an overlay network because it is in a swarm cluster. I want any container I run to be able to run on any of the cluster nodes.

What I have run into is I'm not getting the Hubitat events back into HA. I have the server URL and Port assigned in your integration so it isn't dynamic. That port is then exposed on the container with the docker definition. The problem I see is the traffic isn't being passed into the container correctly and I believe it is because it isn't listening on 0.0.0.0. Listed below is a netstat from inside the HA container. I have your integration set to port 8990 and you can see for this list it is on local address 172.18.0.12 and not 0.0.0.0

tcp 0 0 172.18.0.12:40000 0.0.0.0: LISTEN 63/python3
tcp 0 0 127.0.0.11:35555 0.0.0.0:
LISTEN -
tcp 0 0 172.18.0.12:21064 0.0.0.0: LISTEN 63/python3
tcp 0 0 172.18.0.12:21065 0.0.0.0:
LISTEN 63/python3
tcp 0 0 172.18.0.12:21066 0.0.0.0: LISTEN 63/python3
tcp 0 0 172.18.0.12:21067 0.0.0.0:
LISTEN 63/python3
tcp 0 0 172.18.0.12:21075 0.0.0.0: LISTEN 63/python3
tcp 0 0 172.18.0.12:21076 0.0.0.0:
LISTEN 63/python3
tcp 0 0 172.18.0.12:21077 0.0.0.0: LISTEN 63/python3
tcp 0 0 0.0.0.0:8123 0.0.0.0:
LISTEN 63/python3
tcp 0 0 172.18.0.12:8990 0.0.0.0:* LISTEN 63/python3

I can curl 8990 from inside the container, but I'm unable to curl that same port from the docker host even with the port mapped in the docker definition.

        "Ports": [
            {
                "Protocol": "tcp",
                "TargetPort": 8990,
                "PublishedPort": 8990,
                "PublishMode": "ingress"
            }
        ],

It looks like this is an older issue. Do you have any update on when this might be addressed?

rehpa commented 1 year ago

I tested this today by adjusting the live code in the container and restarting HA from the gui.

Adjusted /usr/local/lib/python3.10/site-packages/hubitatmaker/hub.py line 446 address = '0.0.0.0' #s.getsockname()[0]

Once I restarted the HA service I was able to connect to that service port from the docker hosts. HA was also getting the status updates from my Hubitat hub and all was well.

As a bit of additional information on this. I have two overlay networks connected to the HA container. Unless there is a way to specify which one your service is listening on I think it is going to need to bind to 0.0.0.0. I have it this way because HA is behind my Traefik proxy and that lives on it's own overlay network. Second overlay is for HA and all its components.