Breina / idrac_power_monitor

HomeAssistant integration to monitor the power of a server through its iDrac's Redfish API
17 stars 17 forks source link

Integration crashes when iDRAC is unreachable during HA boot #17

Closed PocketMiner82 closed 2 weeks ago

PocketMiner82 commented 2 months ago

The integration fails setup when the server is fully powered off - I use a smart plug to cut the power to the server when it is unused. When Home Assistant starts when the server is powered down, the integration fails to setup and never displays the server status, even if the server gets powered on afterwards.

Log ``` 2024-05-04 02:03:53.472 ERROR (MainThread) [homeassistant.components.binary_sensor] Error while setting up idrac_power platform for binary_sensor Traceback (most recent call last): File "/usr/local/lib/python3.12/site-packages/urllib3/connection.py", line 174, in _new_conn conn = connection.create_connection( ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.12/site-packages/urllib3/util/connection.py", line 95, in create_connection raise err File "/usr/local/lib/python3.12/site-packages/urllib3/util/connection.py", line 85, in create_connection sock.connect(sa) OSError: [Errno 113] Host is unreachable During handling of the above exception, another exception occurred: Traceback (most recent call last): File "/usr/local/lib/python3.12/site-packages/urllib3/connectionpool.py", line 715, in urlopen httplib_response = self._make_request( ^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.12/site-packages/urllib3/connectionpool.py", line 404, in _make_request self._validate_conn(conn) File "/usr/local/lib/python3.12/site-packages/urllib3/connectionpool.py", line 1058, in _validate_conn conn.connect() File "/usr/local/lib/python3.12/site-packages/urllib3/connection.py", line 363, in connect self.sock = conn = self._new_conn() ^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.12/site-packages/urllib3/connection.py", line 186, in _new_conn raise NewConnectionError( urllib3.exceptions.NewConnectionError: : Failed to establish a new connection: [Errno 113] Host is unreachable During handling of the above exception, another exception occurred: Traceback (most recent call last): File "/usr/local/lib/python3.12/site-packages/requests/adapters.py", line 486, in send resp = conn.urlopen( ^^^^^^^^^^^^^ File "/usr/local/lib/python3.12/site-packages/urllib3/connectionpool.py", line 799, in urlopen retries = retries.increment( ^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.12/site-packages/urllib3/util/retry.py", line 592, in increment raise MaxRetryError(_pool, url, error or ResponseError(cause)) urllib3.exceptions.MaxRetryError: HTTPSConnectionPool(host='dell-idrac.fritz.box', port=443): Max retries exceeded with url: /redfish/v1/Chassis/System.Embedded.1 (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 113] Host is unreachable')) During handling of the above exception, another exception occurred: Traceback (most recent call last): File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 356, in _async_setup_platform await asyncio.shield(awaitable) File "/config/custom_components/idrac_power/binary_sensor.py", line 28, in async_setup_entry info = await hass.async_add_executor_job(rest_client.get_device_info) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.12/concurrent/futures/thread.py", line 58, in run result = self.fn(*self.args, **self.kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/config/custom_components/idrac_power/idrac_rest.py", line 54, in get_device_info result = self.get_path(drac_chassis_path) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/config/custom_components/idrac_power/idrac_rest.py", line 73, in get_path return requests.get(protocol + self.host + path, auth=self.auth, verify=False) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.12/site-packages/requests/api.py", line 73, in get return request("get", url, params=params, **kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.12/site-packages/requests/api.py", line 59, in request return session.request(method=method, url=url, **kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.12/site-packages/requests/sessions.py", line 589, in request resp = self.send(prep, **send_kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.12/site-packages/requests/sessions.py", line 703, in send r = adapter.send(request, **kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.12/site-packages/requests/adapters.py", line 519, in send raise ConnectionError(e, request=request) requests.exceptions.ConnectionError: HTTPSConnectionPool(host='dell-idrac.fritz.box', port=443): Max retries exceeded with url: /redfish/v1/Chassis/System.Embedded.1 (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 113] Host is unreachable')) 2024-05-04 02:03:53.509 ERROR (MainThread) [homeassistant.components.button] Error while setting up idrac_power platform for button Traceback (most recent call last): File "/usr/local/lib/python3.12/site-packages/urllib3/connection.py", line 174, in _new_conn conn = connection.create_connection( ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.12/site-packages/urllib3/util/connection.py", line 95, in create_connection raise err File "/usr/local/lib/python3.12/site-packages/urllib3/util/connection.py", line 85, in create_connection sock.connect(sa) OSError: [Errno 113] Host is unreachable During handling of the above exception, another exception occurred: Traceback (most recent call last): File "/usr/local/lib/python3.12/site-packages/urllib3/connectionpool.py", line 715, in urlopen httplib_response = self._make_request( ^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.12/site-packages/urllib3/connectionpool.py", line 404, in _make_request self._validate_conn(conn) File "/usr/local/lib/python3.12/site-packages/urllib3/connectionpool.py", line 1058, in _validate_conn conn.connect() File "/usr/local/lib/python3.12/site-packages/urllib3/connection.py", line 363, in connect self.sock = conn = self._new_conn() ^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.12/site-packages/urllib3/connection.py", line 186, in _new_conn raise NewConnectionError( urllib3.exceptions.NewConnectionError: : Failed to establish a new connection: [Errno 113] Host is unreachable During handling of the above exception, another exception occurred: Traceback (most recent call last): File "/usr/local/lib/python3.12/site-packages/requests/adapters.py", line 486, in send resp = conn.urlopen( ^^^^^^^^^^^^^ File "/usr/local/lib/python3.12/site-packages/urllib3/connectionpool.py", line 799, in urlopen retries = retries.increment( ^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.12/site-packages/urllib3/util/retry.py", line 592, in increment raise MaxRetryError(_pool, url, error or ResponseError(cause)) urllib3.exceptions.MaxRetryError: HTTPSConnectionPool(host='dell-idrac.fritz.box', port=443): Max retries exceeded with url: /redfish/v1/Chassis/System.Embedded.1 (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 113] Host is unreachable')) During handling of the above exception, another exception occurred: Traceback (most recent call last): File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 356, in _async_setup_platform await asyncio.shield(awaitable) File "/config/custom_components/idrac_power/button.py", line 22, in async_setup_entry info = await hass.async_add_executor_job(target=rest_client.get_device_info) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.12/concurrent/futures/thread.py", line 58, in run result = self.fn(*self.args, **self.kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/config/custom_components/idrac_power/idrac_rest.py", line 54, in get_device_info result = self.get_path(drac_chassis_path) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/config/custom_components/idrac_power/idrac_rest.py", line 73, in get_path return requests.get(protocol + self.host + path, auth=self.auth, verify=False) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.12/site-packages/requests/api.py", line 73, in get return request("get", url, params=params, **kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.12/site-packages/requests/api.py", line 59, in request return session.request(method=method, url=url, **kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.12/site-packages/requests/sessions.py", line 589, in request resp = self.send(prep, **send_kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.12/site-packages/requests/sessions.py", line 703, in send r = adapter.send(request, **kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.12/site-packages/requests/adapters.py", line 519, in send raise ConnectionError(e, request=request) requests.exceptions.ConnectionError: HTTPSConnectionPool(host='dell-idrac.fritz.box', port=443): Max retries exceeded with url: /redfish/v1/Chassis/System.Embedded.1 (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 113] Host is unreachable')) 2024-05-04 02:03:53.536 ERROR (MainThread) [homeassistant.components.sensor] Error while setting up idrac_power platform for sensor Traceback (most recent call last): File "/usr/local/lib/python3.12/site-packages/urllib3/connection.py", line 174, in _new_conn conn = connection.create_connection( ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.12/site-packages/urllib3/util/connection.py", line 95, in create_connection raise err File "/usr/local/lib/python3.12/site-packages/urllib3/util/connection.py", line 85, in create_connection sock.connect(sa) OSError: [Errno 113] Host is unreachable During handling of the above exception, another exception occurred: Traceback (most recent call last): File "/usr/local/lib/python3.12/site-packages/urllib3/connectionpool.py", line 715, in urlopen httplib_response = self._make_request( ^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.12/site-packages/urllib3/connectionpool.py", line 404, in _make_request self._validate_conn(conn) File "/usr/local/lib/python3.12/site-packages/urllib3/connectionpool.py", line 1058, in _validate_conn conn.connect() File "/usr/local/lib/python3.12/site-packages/urllib3/connection.py", line 363, in connect self.sock = conn = self._new_conn() ^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.12/site-packages/urllib3/connection.py", line 186, in _new_conn raise NewConnectionError( urllib3.exceptions.NewConnectionError: : Failed to establish a new connection: [Errno 113] Host is unreachable During handling of the above exception, another exception occurred: Traceback (most recent call last): File "/usr/local/lib/python3.12/site-packages/requests/adapters.py", line 486, in send resp = conn.urlopen( ^^^^^^^^^^^^^ File "/usr/local/lib/python3.12/site-packages/urllib3/connectionpool.py", line 799, in urlopen retries = retries.increment( ^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.12/site-packages/urllib3/util/retry.py", line 592, in increment raise MaxRetryError(_pool, url, error or ResponseError(cause)) urllib3.exceptions.MaxRetryError: HTTPSConnectionPool(host='dell-idrac.fritz.box', port=443): Max retries exceeded with url: /redfish/v1/Chassis/System.Embedded.1 (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 113] Host is unreachable')) During handling of the above exception, another exception occurred: Traceback (most recent call last): File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 356, in _async_setup_platform await asyncio.shield(awaitable) File "/config/custom_components/idrac_power/sensor.py", line 30, in async_setup_entry info = await hass.async_add_executor_job(target=rest_client.get_device_info) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.12/concurrent/futures/thread.py", line 58, in run result = self.fn(*self.args, **self.kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/config/custom_components/idrac_power/idrac_rest.py", line 54, in get_device_info result = self.get_path(drac_chassis_path) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/config/custom_components/idrac_power/idrac_rest.py", line 73, in get_path return requests.get(protocol + self.host + path, auth=self.auth, verify=False) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.12/site-packages/requests/api.py", line 73, in get return request("get", url, params=params, **kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.12/site-packages/requests/api.py", line 59, in request return session.request(method=method, url=url, **kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.12/site-packages/requests/sessions.py", line 589, in request resp = self.send(prep, **send_kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.12/site-packages/requests/sessions.py", line 703, in send r = adapter.send(request, **kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.12/site-packages/requests/adapters.py", line 519, in send raise ConnectionError(e, request=request) requests.exceptions.ConnectionError: HTTPSConnectionPool(host='dell-idrac.fritz.box', port=443): Max retries exceeded with url: /redfish/v1/Chassis/System.Embedded.1 (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 113] Host is unreachable')) ```

Moreover, if I try to reload the integration when it failed to setup, this error gets thrown:

Log ``` 2024-05-04 14:25:54.684 ERROR (MainThread) [homeassistant.config_entries] Error setting up entry PowerEdge R630 for sensor Traceback (most recent call last): File "/usr/src/homeassistant/homeassistant/config_entries.py", line 551, in async_setup result = await component.async_setup_entry(hass, self) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/src/homeassistant/homeassistant/components/sensor/__init__.py", line 139, in async_setup_entry return await component.async_setup_entry(entry) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/src/homeassistant/homeassistant/helpers/entity_component.py", line 187, in async_setup_entry raise ValueError("Config entry has already been setup!") ValueError: Config entry has already been setup! 2024-05-04 14:25:54.697 ERROR (MainThread) [homeassistant.config_entries] Error setting up entry PowerEdge R630 for binary_sensor Traceback (most recent call last): File "/usr/src/homeassistant/homeassistant/config_entries.py", line 551, in async_setup result = await component.async_setup_entry(hass, self) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/src/homeassistant/homeassistant/components/binary_sensor/__init__.py", line 239, in async_setup_entry return await component.async_setup_entry(entry) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/src/homeassistant/homeassistant/helpers/entity_component.py", line 187, in async_setup_entry raise ValueError("Config entry has already been setup!") ValueError: Config entry has already been setup! 2024-05-04 14:25:54.704 ERROR (MainThread) [homeassistant.config_entries] Error setting up entry PowerEdge R630 for button Traceback (most recent call last): File "/usr/src/homeassistant/homeassistant/config_entries.py", line 551, in async_setup result = await component.async_setup_entry(hass, self) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/src/homeassistant/homeassistant/components/button/__init__.py", line 73, in async_setup_entry return await component.async_setup_entry(entry) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/src/homeassistant/homeassistant/helpers/entity_component.py", line 187, in async_setup_entry raise ValueError("Config entry has already been setup!") ValueError: Config entry has already been setup! ```

So it is impossible to get the server iDRAC status when powering on the server after home assistant without completely restarting home assistant.

cbrherms commented 2 months ago

Just to add, i've noticed as well that if a device becomes unreachable at some point, the particular device errors and then no longer updates.

Breina commented 1 month ago

Alright lads, please check out v1.3.0. :)

Tested by writing code to manually raise a ConnectionError, couldn't test it on hardware directly.

image

PocketMiner82 commented 1 month ago

Hi @Breina,

I installed your updated version and at least for me it seems like the error unfortunately is not fixed. When Home Assistant is started and the server is not reachable, the integration errors out:

Log ``` 2024-06-05 13:06:04.131 ERROR (MainThread) [homeassistant.components.button] Error while setting up idrac_power platform for button Traceback (most recent call last): File "/usr/local/lib/python3.12/site-packages/urllib3/connection.py", line 174, in _new_conn conn = connection.create_connection( ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.12/site-packages/urllib3/util/connection.py", line 95, in create_connection raise err File "/usr/local/lib/python3.12/site-packages/urllib3/util/connection.py", line 85, in create_connection sock.connect(sa) OSError: [Errno 113] Host is unreachable During handling of the above exception, another exception occurred: Traceback (most recent call last): File "/usr/local/lib/python3.12/site-packages/urllib3/connectionpool.py", line 715, in urlopen httplib_response = self._make_request( ^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.12/site-packages/urllib3/connectionpool.py", line 404, in _make_request self._validate_conn(conn) File "/usr/local/lib/python3.12/site-packages/urllib3/connectionpool.py", line 1058, in _validate_conn conn.connect() File "/usr/local/lib/python3.12/site-packages/urllib3/connection.py", line 363, in connect self.sock = conn = self._new_conn() ^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.12/site-packages/urllib3/connection.py", line 186, in _new_conn raise NewConnectionError( urllib3.exceptions.NewConnectionError: : Failed to establish a new connection: [Errno 113] Host is unreachable During handling of the above exception, another exception occurred: Traceback (most recent call last): File "/usr/local/lib/python3.12/site-packages/requests/adapters.py", line 486, in send resp = conn.urlopen( ^^^^^^^^^^^^^ File "/usr/local/lib/python3.12/site-packages/urllib3/connectionpool.py", line 799, in urlopen retries = retries.increment( ^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.12/site-packages/urllib3/util/retry.py", line 592, in increment raise MaxRetryError(_pool, url, error or ResponseError(cause)) urllib3.exceptions.MaxRetryError: HTTPSConnectionPool(host='dell-idrac.fritz.box', port=443): Max retries exceeded with url: /redfish/v1/Chassis/System.Embedded.1 (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 113] Host is unreachable')) During handling of the above exception, another exception occurred: Traceback (most recent call last): File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 356, in _async_setup_platform await asyncio.shield(awaitable) File "/config/custom_components/idrac_power/button.py", line 23, in async_setup_entry info = await hass.async_add_executor_job(target=rest_client.get_device_info) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.12/concurrent/futures/thread.py", line 58, in run result = self.fn(*self.args, **self.kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/config/custom_components/idrac_power/idrac_rest.py", line 56, in get_device_info result = self.get_path(drac_chassis_path) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/config/custom_components/idrac_power/idrac_rest.py", line 84, in get_path return requests.get(protocol + self.host + path, auth=self.auth, verify=False) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.12/site-packages/requests/api.py", line 73, in get return request("get", url, params=params, **kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.12/site-packages/requests/api.py", line 59, in request return session.request(method=method, url=url, **kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.12/site-packages/requests/sessions.py", line 589, in request resp = self.send(prep, **send_kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.12/site-packages/requests/sessions.py", line 703, in send r = adapter.send(request, **kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.12/site-packages/requests/adapters.py", line 519, in send raise ConnectionError(e, request=request) requests.exceptions.ConnectionError: HTTPSConnectionPool(host='dell-idrac.fritz.box', port=443): Max retries exceeded with url: /redfish/v1/Chassis/System.Embedded.1 (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 113] Host is unreachable')) 2024-06-05 13:06:04.271 ERROR (MainThread) [homeassistant.components.sensor] Error while setting up idrac_power platform for sensor Traceback (most recent call last): File "/usr/local/lib/python3.12/site-packages/urllib3/connection.py", line 174, in _new_conn conn = connection.create_connection( ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.12/site-packages/urllib3/util/connection.py", line 95, in create_connection raise err File "/usr/local/lib/python3.12/site-packages/urllib3/util/connection.py", line 85, in create_connection sock.connect(sa) OSError: [Errno 113] Host is unreachable During handling of the above exception, another exception occurred: Traceback (most recent call last): File "/usr/local/lib/python3.12/site-packages/urllib3/connectionpool.py", line 715, in urlopen httplib_response = self._make_request( ^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.12/site-packages/urllib3/connectionpool.py", line 404, in _make_request self._validate_conn(conn) File "/usr/local/lib/python3.12/site-packages/urllib3/connectionpool.py", line 1058, in _validate_conn conn.connect() File "/usr/local/lib/python3.12/site-packages/urllib3/connection.py", line 363, in connect self.sock = conn = self._new_conn() ^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.12/site-packages/urllib3/connection.py", line 186, in _new_conn raise NewConnectionError( urllib3.exceptions.NewConnectionError: : Failed to establish a new connection: [Errno 113] Host is unreachable During handling of the above exception, another exception occurred: Traceback (most recent call last): File "/usr/local/lib/python3.12/site-packages/requests/adapters.py", line 486, in send resp = conn.urlopen( ^^^^^^^^^^^^^ File "/usr/local/lib/python3.12/site-packages/urllib3/connectionpool.py", line 799, in urlopen retries = retries.increment( ^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.12/site-packages/urllib3/util/retry.py", line 592, in increment raise MaxRetryError(_pool, url, error or ResponseError(cause)) urllib3.exceptions.MaxRetryError: HTTPSConnectionPool(host='dell-idrac.fritz.box', port=443): Max retries exceeded with url: /redfish/v1/Chassis/System.Embedded.1 (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 113] Host is unreachable')) During handling of the above exception, another exception occurred: Traceback (most recent call last): File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 356, in _async_setup_platform await asyncio.shield(awaitable) File "/config/custom_components/idrac_power/sensor.py", line 31, in async_setup_entry info = await hass.async_add_executor_job(target=rest_client.get_device_info) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.12/concurrent/futures/thread.py", line 58, in run result = self.fn(*self.args, **self.kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/config/custom_components/idrac_power/idrac_rest.py", line 56, in get_device_info result = self.get_path(drac_chassis_path) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/config/custom_components/idrac_power/idrac_rest.py", line 84, in get_path return requests.get(protocol + self.host + path, auth=self.auth, verify=False) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.12/site-packages/requests/api.py", line 73, in get return request("get", url, params=params, **kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.12/site-packages/requests/api.py", line 59, in request return session.request(method=method, url=url, **kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.12/site-packages/requests/sessions.py", line 589, in request resp = self.send(prep, **send_kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.12/site-packages/requests/sessions.py", line 703, in send r = adapter.send(request, **kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.12/site-packages/requests/adapters.py", line 519, in send raise ConnectionError(e, request=request) requests.exceptions.ConnectionError: HTTPSConnectionPool(host='dell-idrac.fritz.box', port=443): Max retries exceeded with url: /redfish/v1/Chassis/System.Embedded.1 (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 113] Host is unreachable')) 2024-06-05 13:06:04.342 ERROR (MainThread) [homeassistant.components.binary_sensor] Error while setting up idrac_power platform for binary_sensor Traceback (most recent call last): File "/usr/local/lib/python3.12/site-packages/urllib3/connection.py", line 174, in _new_conn conn = connection.create_connection( ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.12/site-packages/urllib3/util/connection.py", line 95, in create_connection raise err File "/usr/local/lib/python3.12/site-packages/urllib3/util/connection.py", line 85, in create_connection sock.connect(sa) OSError: [Errno 113] Host is unreachable During handling of the above exception, another exception occurred: Traceback (most recent call last): File "/usr/local/lib/python3.12/site-packages/urllib3/connectionpool.py", line 715, in urlopen httplib_response = self._make_request( ^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.12/site-packages/urllib3/connectionpool.py", line 404, in _make_request self._validate_conn(conn) File "/usr/local/lib/python3.12/site-packages/urllib3/connectionpool.py", line 1058, in _validate_conn conn.connect() File "/usr/local/lib/python3.12/site-packages/urllib3/connection.py", line 363, in connect self.sock = conn = self._new_conn() ^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.12/site-packages/urllib3/connection.py", line 186, in _new_conn raise NewConnectionError( urllib3.exceptions.NewConnectionError: : Failed to establish a new connection: [Errno 113] Host is unreachable During handling of the above exception, another exception occurred: Traceback (most recent call last): File "/usr/local/lib/python3.12/site-packages/requests/adapters.py", line 486, in send resp = conn.urlopen( ^^^^^^^^^^^^^ File "/usr/local/lib/python3.12/site-packages/urllib3/connectionpool.py", line 799, in urlopen retries = retries.increment( ^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.12/site-packages/urllib3/util/retry.py", line 592, in increment raise MaxRetryError(_pool, url, error or ResponseError(cause)) urllib3.exceptions.MaxRetryError: HTTPSConnectionPool(host='dell-idrac.fritz.box', port=443): Max retries exceeded with url: /redfish/v1/Chassis/System.Embedded.1 (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 113] Host is unreachable')) During handling of the above exception, another exception occurred: Traceback (most recent call last): File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 356, in _async_setup_platform await asyncio.shield(awaitable) File "/config/custom_components/idrac_power/binary_sensor.py", line 29, in async_setup_entry info = await hass.async_add_executor_job(target=rest_client.get_device_info) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.12/concurrent/futures/thread.py", line 58, in run result = self.fn(*self.args, **self.kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/config/custom_components/idrac_power/idrac_rest.py", line 56, in get_device_info result = self.get_path(drac_chassis_path) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/config/custom_components/idrac_power/idrac_rest.py", line 84, in get_path return requests.get(protocol + self.host + path, auth=self.auth, verify=False) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.12/site-packages/requests/api.py", line 73, in get return request("get", url, params=params, **kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.12/site-packages/requests/api.py", line 59, in request return session.request(method=method, url=url, **kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.12/site-packages/requests/sessions.py", line 589, in request resp = self.send(prep, **send_kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.12/site-packages/requests/sessions.py", line 703, in send r = adapter.send(request, **kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.12/site-packages/requests/adapters.py", line 519, in send raise ConnectionError(e, request=request) requests.exceptions.ConnectionError: HTTPSConnectionPool(host='dell-idrac.fritz.box', port=443): Max retries exceeded with url: /redfish/v1/Chassis/System.Embedded.1 (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 113] Host is unreachable')) ```

When I then plug in the server, the sensors remain unavailable (I did wait for over an hour). If I restart Home Assistant, the integration is able to connect to iDRAC and the sensors show the data.

I do not know (didn't test) if @cbrherms issue was fixed.

I also removed and re-added the integration to see if it makes any difference, but the behavior did not change.

Breina commented 1 month ago

Just to make sure we're on the same page, the integration needs to be set up when the server is active. It will then store stuff so that it can survive a restart if a server is unreachable. Subsequent restarts should be fine from then.

On my phone right now, will check your logs when I get home.

cbrherms commented 1 month ago

Hi @Breina,

I installed your updated version and at least for me it seems like the error unfortunately is not fixed. When Home Assistant is started and the server is not reachable, the integration errors out:

Log When I then plug in the server, the sensors remain unavailable (I did wait for over an hour). If I restart Home Assistant, the integration is able to connect to iDRAC and the sensors show the data.

I do not know (didn't test) if @cbrherms issue was fixed.

I also removed and re-added the integration to see if it makes any difference, but the behavior did not change.

Been a while since I looked at this but I branched and made a few janky changes that fixed my issue with the dropouts. I'd have to go back through what I changed locally though and whether I pushed that all up to the dev branch I was storing it on.

@Breina Admittedly can't remember how much testing i'd done with an idrac port being fully unreachable during homeasisstant startup (which i think is what @PocketMiner82 is saying), but i think this just needed the connection error catching and raising with ConfigEntryNotReady so that it'd try setting the platform up again once it became available https://github.com/cbrherms/idrac_power_monitor/commit/d65bc3bbcbb3f29507b2009d96f259c5d3119564 ?

While playing around with it I also added in a bunch of exception catching and also made use of setting the entity availability attribute when errors were raised which may be something to look in to? As i said though, janky, and mostly just picking a few things from the dev site and a few others from examples šŸ˜‚ I'm still trying to familiarise myself with python. lol.

Breina commented 1 month ago

Those are some good clues, thanks for the info!

PocketMiner82 commented 1 month ago

Just to make sure we're on the same page, the integration needs to be set up when the server is active. It will then store stuff so that it can survive a restart if a server is unreachable. Subsequent restarts should be fine from then.

On my phone right now, will check your logs when I get home.

I set up the integration when the server was reachable, yes. My problem is exactly what cbrherms described: The iDRAC is unreachable when I start Home Assistant (I automatically restart Home Assistant, which I run on a Pi 4, every night - at this time the server is powered off and power is cut by the zigbee plug - that's how I discovered the issue). When Home Assistant starts, the integration only throws one error for each platform (that it can't set it up due to connection error) and then it doesn't retry to connect.

Edit: I just noticed that I wrote "setup" in the title, will update it šŸ˜…

PocketMiner82 commented 3 weeks ago

@Breina I managed to fix the issue in #21

Breina commented 2 weeks ago

Released this as 1.4.0.

Thanks a lot PocketMiner! :)