From 6ba59fe01138f68b19ad546e64ec2c1eceb29c8d Mon Sep 17 00:00:00 2001 From: Snuffy2 Date: Tue, 24 Sep 2024 22:05:38 -0400 Subject: [PATCH] Turn down Debug logging --- .../opnsense/pyopnsense/__init__.py | 58 +++++++++---------- custom_components/opnsense/services.py | 26 ++++----- 2 files changed, 38 insertions(+), 46 deletions(-) diff --git a/custom_components/opnsense/pyopnsense/__init__.py b/custom_components/opnsense/pyopnsense/__init__.py index 0931b47..a76ef9d 100644 --- a/custom_components/opnsense/pyopnsense/__init__.py +++ b/custom_components/opnsense/pyopnsense/__init__.py @@ -213,9 +213,7 @@ async def _get_from_stream(self, path: str) -> Mapping[str, Any] | list: json.loads(response_str) ) - _LOGGER.debug( - f"[get_from_stream] response_json ({type(response_json).__name__}): {response_json}" - ) + # _LOGGER.debug(f"[get_from_stream] response_json ({type(response_json).__name__}): {response_json}") return response_json # Exit after processing the second message elif response.status == 403: @@ -593,7 +591,7 @@ async def get_arp_table(self, resolve_hostnames=False) -> Mapping[str, Any]: ) if not isinstance(arp_table_info, Mapping): return [] - _LOGGER.debug(f"[get_arp_table] arp_table_info: {arp_table_info}") + # _LOGGER.debug(f"[get_arp_table] arp_table_info: {arp_table_info}") arp_table: list = arp_table_info.get("rows", []) _LOGGER.debug(f"[get_arp_table] arp_table: {arp_table}") return arp_table @@ -828,7 +826,7 @@ async def _get_telemetry_interfaces(self) -> Mapping[str, Any]: interface_info: Mapping[str, Any] | list = await self._post( "/api/interfaces/overview/export" ) - _LOGGER.debug(f"[get_telemetry_interfaces] interface_info: {interface_info}") + # _LOGGER.debug(f"[get_telemetry_interfaces] interface_info: {interface_info}") if not isinstance(interface_info, list) or not len(interface_info) > 0: return {} interfaces: Mapping[str, Any] = {} @@ -877,7 +875,7 @@ async def _get_telemetry_interfaces(self) -> Mapping[str, Any]: interface["ipaddr"] = ifinfo.get("addr4", "") interface["media"] = ifinfo.get("media", "") interfaces[ifinfo.get("identifier", "")] = interface - _LOGGER.debug(f"[get_telemetry_interfaces] interfaces: {interfaces}") + # _LOGGER.debug(f"[get_telemetry_interfaces] interfaces: {interfaces}") return interfaces @_log_errors @@ -885,7 +883,7 @@ async def _get_telemetry_mbuf(self) -> Mapping[str, Any]: mbuf_info: Mapping[str, Any] | list = await self._post( "/api/diagnostics/system/system_mbuf" ) - _LOGGER.debug(f"[get_telemetry_mbuf] mbuf_info: {mbuf_info}") + # _LOGGER.debug(f"[get_telemetry_mbuf] mbuf_info: {mbuf_info}") if not isinstance(mbuf_info, Mapping): return {} mbuf: Mapping[str, Any] = {} @@ -902,7 +900,7 @@ async def _get_telemetry_mbuf(self) -> Mapping[str, Any]: and mbuf["total"] > 0 else None ) - _LOGGER.debug(f"[get_telemetry_mbuf] mbuf: {mbuf}") + # _LOGGER.debug(f"[get_telemetry_mbuf] mbuf: {mbuf}") return mbuf @_log_errors @@ -910,7 +908,7 @@ async def _get_telemetry_pfstate(self) -> Mapping[str, Any]: pfstate_info: Mapping[str, Any] | list = await self._post( "/api/diagnostics/firewall/pf_states" ) - _LOGGER.debug(f"[get_telemetry_pfstate] pfstate_info: {pfstate_info}") + # _LOGGER.debug(f"[get_telemetry_pfstate] pfstate_info: {pfstate_info}") if not isinstance(pfstate_info, Mapping): return {} pfstate: Mapping[str, Any] = {} @@ -923,7 +921,7 @@ async def _get_telemetry_pfstate(self) -> Mapping[str, Any]: and pfstate["total"] > 0 else None ) - _LOGGER.debug(f"[get_telemetry_pfstate] pfstate: {pfstate}") + # _LOGGER.debug(f"[get_telemetry_pfstate] pfstate: {pfstate}") return pfstate @_log_errors @@ -931,7 +929,7 @@ async def _get_telemetry_memory(self) -> Mapping[str, Any]: memory_info: Mapping[str, Any] | list = await self._post( "/api/diagnostics/system/systemResources" ) - _LOGGER.debug(f"[get_telemetry_memory] memory_info: {memory_info}") + # _LOGGER.debug(f"[get_telemetry_memory] memory_info: {memory_info}") if not isinstance(memory_info, Mapping): return {} memory: Mapping[str, Any] = {} @@ -958,7 +956,7 @@ async def _get_telemetry_memory(self) -> Mapping[str, Any]: or not isinstance(swap_info.get("swap", [])[0], Mapping) ): return memory - _LOGGER.debug(f"[get_telemetry_memory] swap_info: {swap_info}") + # _LOGGER.debug(f"[get_telemetry_memory] swap_info: {swap_info}") memory["swap_total"] = self._try_to_int( swap_info.get("swap", [])[0].get("total", None) ) @@ -972,7 +970,7 @@ async def _get_telemetry_memory(self) -> Mapping[str, Any]: and memory["swap_total"] > 0 else 0 ) - _LOGGER.debug(f"[get_telemetry_memory] memory: {memory}") + # _LOGGER.debug(f"[get_telemetry_memory] memory: {memory}") return memory @_log_errors @@ -980,7 +978,7 @@ async def _get_telemetry_system(self) -> Mapping[str, Any]: time_info: Mapping[str, Any] | list = await self._post( "/api/diagnostics/system/systemTime" ) - _LOGGER.debug(f"[get_telemetry_system] time_info: {time_info}") + # _LOGGER.debug(f"[get_telemetry_system] time_info: {time_info}") if not isinstance(time_info, Mapping): return {} system: Mapping[str, Any] = {} @@ -1011,7 +1009,7 @@ async def _get_telemetry_system(self) -> Mapping[str, Any]: "five_minute": None, "fifteen_minute": None, } - _LOGGER.debug(f"[get_telemetry_system] system: {system}") + # _LOGGER.debug(f"[get_telemetry_system] system: {system}") return system @_log_errors @@ -1019,7 +1017,7 @@ async def _get_telemetry_cpu(self) -> Mapping[str, Any]: cputype_info: Mapping[str, Any] | list = await self._post( "/api/diagnostics/cpu_usage/getCPUType" ) - _LOGGER.debug(f"[get_telemetry_cpu] cputype_info: {cputype_info}") + # _LOGGER.debug(f"[get_telemetry_cpu] cputype_info: {cputype_info}") if not isinstance(cputype_info, list) or not len(cputype_info) > 0: return {} cpu: Mapping[str, Any] = {} @@ -1030,7 +1028,7 @@ async def _get_telemetry_cpu(self) -> Mapping[str, Any]: "/api/diagnostics/cpu_usage/stream" ) # {"total":29,"user":2,"nice":0,"sys":27,"intr":0,"idle":70} - _LOGGER.debug(f"[get_telemetry_cpu] cpustream_info: {cpustream_info}") + # _LOGGER.debug(f"[get_telemetry_cpu] cpustream_info: {cpustream_info}") if not isinstance(cpustream_info, Mapping): return cpu cpu["usage_total"] = self._try_to_int(cpustream_info.get("total", None)) @@ -1039,7 +1037,7 @@ async def _get_telemetry_cpu(self) -> Mapping[str, Any]: cpu["usage_system"] = self._try_to_int(cpustream_info.get("sys", None)) cpu["usage_interrupt"] = self._try_to_int(cpustream_info.get("intr", None)) cpu["usage_idle"] = self._try_to_int(cpustream_info.get("idle", None)) - _LOGGER.debug(f"[get_telemetry_cpu] cpu: {cpu}") + # _LOGGER.debug(f"[get_telemetry_cpu] cpu: {cpu}") return cpu @_log_errors @@ -1049,15 +1047,13 @@ async def _get_telemetry_filesystems(self) -> list: ) if not isinstance(filesystems_info, Mapping): return [] - _LOGGER.debug( - f"[get_telemetry_filesystems] filesystems_info: {filesystems_info}" - ) + # _LOGGER.debug(f"[get_telemetry_filesystems] filesystems_info: {filesystems_info}") filesystems: list = filesystems_info.get("devices", []) # To conform to the previous data being returned for filesystem in filesystems: filesystem["size"] = filesystem.pop("blocks", None) filesystem["capacity"] = f"{filesystem.pop('used_pct','')}%" - _LOGGER.debug(f"[get_telemetry_filesystems] filesystems: {filesystems}") + # _LOGGER.debug(f"[get_telemetry_filesystems] filesystems: {filesystems}") return filesystems @_log_errors @@ -1065,7 +1061,7 @@ async def _get_telemetry_openvpn(self) -> Mapping[str, Any]: openvpn_info: Mapping[str, Any] | list = await self._post( "/api/openvpn/export/providers" ) - _LOGGER.debug(f"[get_telemetry_openvpn] openvpn_info: {openvpn_info}") + # _LOGGER.debug(f"[get_telemetry_openvpn] openvpn_info: {openvpn_info}") if not isinstance(openvpn_info, Mapping): return {} openvpn: Mapping[str, Any] = {} @@ -1073,7 +1069,7 @@ async def _get_telemetry_openvpn(self) -> Mapping[str, Any]: connection_info: Mapping[str, Any] = await self._post( "/api/openvpn/service/searchSessions" ) - _LOGGER.debug(f"[get_telemetry_openvpn] connection_info: {connection_info}") + # _LOGGER.debug(f"[get_telemetry_openvpn] connection_info: {connection_info}") if connection_info is None or not isinstance(connection_info, Mapping): return {} for vpnid, vpn_info in openvpn_info.items(): @@ -1097,7 +1093,7 @@ async def _get_telemetry_openvpn(self) -> Mapping[str, Any]: # Missing connected_client_count # vpn["connected_client_count"] = openvpn["servers"][vpnid] = vpn - _LOGGER.debug(f"[get_telemetry_openvpn] openvpn: {openvpn}") + # _LOGGER.debug(f"[get_telemetry_openvpn] openvpn: {openvpn}") return openvpn @_log_errors @@ -1105,7 +1101,7 @@ async def _get_telemetry_gateways(self) -> Mapping[str, Any]: gateways_info: Mapping[str, Any] | list = await self._post( "/api/routes/gateway/status" ) - _LOGGER.debug(f"[get_telemetry_gateways] gateways_info: {gateways_info}") + # _LOGGER.debug(f"[get_telemetry_gateways] gateways_info: {gateways_info}") if not isinstance(gateways_info, Mapping): return {} gateways: Mapping[str, Any] = {} @@ -1116,7 +1112,7 @@ async def _get_telemetry_gateways(self) -> Mapping[str, Any]: gateway["status"] = gateway.pop( "status_translated", gateway.get("status", "") ).lower() - _LOGGER.debug(f"[get_telemetry_gateways] gateways: {gateways}") + # _LOGGER.debug(f"[get_telemetry_gateways] gateways: {gateways}") return gateways @_log_errors @@ -1124,7 +1120,7 @@ async def _get_telemetry_temps(self) -> Mapping[str, Any]: temps_info: Mapping[str, Any] | list = await self._post( "/api/diagnostics/system/systemTemperature" ) - _LOGGER.debug(f"[get_telemetry_temps] temps_info: {temps_info}") + # _LOGGER.debug(f"[get_telemetry_temps] temps_info: {temps_info}") if not isinstance(temps_info, list) or not len(temps_info) > 0: return {} temps: Mapping[str, Any] = {} @@ -1136,7 +1132,7 @@ async def _get_telemetry_temps(self) -> Mapping[str, Any]: ) temp["device_id"] = temp_info.get("device", str(i)) temps[temp_info.get("device", str(i)).replace(".", "_")] = temp - _LOGGER.debug(f"[get_telemetry_temps] temps: {temps}") + # _LOGGER.debug(f"[get_telemetry_temps] temps: {temps}") return temps @_log_errors @@ -1327,7 +1323,7 @@ async def _get_telemetry_legacy(self) -> Mapping[str, Any]: return {} if isinstance(telemetry.get("gateways", []), list): telemetry["gateways"] = {} - _LOGGER.debug(f"[get_telemetry_legacy] telemetry: {telemetry}") + # _LOGGER.debug(f"[get_telemetry_legacy] telemetry: {telemetry}") return telemetry @_log_errors @@ -1335,7 +1331,7 @@ async def get_notices(self) -> list: notices_info: Mapping[str, Any] | list = await self._get( "/api/core/system/status" ) - _LOGGER.debug(f"[get_notices] notices_info: {notices_info}") + # _LOGGER.debug(f"[get_notices] notices_info: {notices_info}") if not isinstance(notices_info, Mapping): return [] diff --git a/custom_components/opnsense/services.py b/custom_components/opnsense/services.py index 9fd9652..6f525cd 100644 --- a/custom_components/opnsense/services.py +++ b/custom_components/opnsense/services.py @@ -51,9 +51,7 @@ async def _get_clients( except Exception: pass else: - _LOGGER.debug( - f"[get_clients] device_id: {opndevice_id}, device_entry: {device_entry}" - ) + # _LOGGER.debug(f"[get_clients] device_id: {opndevice_id}, device_entry: {device_entry}") if device_entry.primary_config_entry not in entry_ids: entry_ids.append(device_entry.primary_config_entry) if opnentity_id: @@ -64,15 +62,13 @@ async def _get_clients( except Exception: pass else: - _LOGGER.debug( - f"[get_clients] entity_id: {opnentity_id}, entity_entry: {entity_entry}" - ) + # _LOGGER.debug(f"[get_clients] entity_id: {opnentity_id}, entity_entry: {entity_entry}") if entity_entry.config_entry_id not in entry_ids: entry_ids.append(entity_entry.config_entry_id) clients: list = [] - _LOGGER.debug(f"[get_clients] entry_ids: {entry_ids}") + # _LOGGER.debug(f"[get_clients] entry_ids: {entry_ids}") for entry_id, entry in hass.data[DOMAIN].items(): - _LOGGER.debug(f"[get_clients] entry_id: {entry_id}") + # _LOGGER.debug(f"[get_clients] entry_id: {entry_id}") if ( len(entry_ids) == 0 or entry_id in entry_ids ) and OPNSENSE_CLIENT in entry: @@ -84,7 +80,7 @@ async def service_close_notice(call: ServiceCall) -> None: clients: list = await _get_clients( call.data.get("device_id", []), call.data.get("entity_id", []) ) - _LOGGER.debug(f"[service_close_notice] clients: {clients}") + # _LOGGER.debug(f"[service_close_notice] clients: {clients}") for client in clients: _LOGGER.debug( f"[service_close_notice] Calling stop_service for {call.data.get('id')}" @@ -95,7 +91,7 @@ async def service_start_service(call: ServiceCall) -> None: clients: list = await _get_clients( call.data.get("device_id", []), call.data.get("entity_id", []) ) - _LOGGER.debug(f"[service_start_service] clients: {clients}") + # _LOGGER.debug(f"[service_start_service] clients: {clients}") success = None for client in clients: _LOGGER.debug( @@ -115,7 +111,7 @@ async def service_stop_service(call: ServiceCall) -> None: clients: list = await _get_clients( call.data.get("device_id", []), call.data.get("entity_id", []) ) - _LOGGER.debug(f"[service_stop_service] clients: {clients}") + # _LOGGER.debug(f"[service_stop_service] clients: {clients}") success = None for client in clients: _LOGGER.debug( @@ -135,7 +131,7 @@ async def service_restart_service(call: ServiceCall) -> None: clients: list = await _get_clients( call.data.get("device_id", []), call.data.get("entity_id", []) ) - _LOGGER.debug(f"[service_restart_service] clients: {clients}") + # _LOGGER.debug(f"[service_restart_service] clients: {clients}") success = None if call.data.get("only_if_running"): for client in clients: @@ -172,7 +168,7 @@ async def service_system_halt(call: ServiceCall) -> None: clients: list = await _get_clients( call.data.get("device_id", []), call.data.get("entity_id", []) ) - _LOGGER.debug(f"[service_system_halt] clients: {clients}") + # _LOGGER.debug(f"[service_system_halt] clients: {clients}") for client in clients: _LOGGER.debug("[service_system_halt] Calling System Halt") await client.system_halt() @@ -181,7 +177,7 @@ async def service_system_reboot(call: ServiceCall) -> None: clients: list = await _get_clients( call.data.get("device_id", []), call.data.get("entity_id", []) ) - _LOGGER.debug(f"[service_system_reboot] clients: {clients}") + # _LOGGER.debug(f"[service_system_reboot] clients: {clients}") for client in clients: _LOGGER.debug("[service_system_reboot] Calling System Reboot") await client.system_reboot() @@ -190,7 +186,7 @@ async def service_send_wol(call: ServiceCall) -> None: clients: list = await _get_clients( call.data.get("device_id", []), call.data.get("entity_id", []) ) - _LOGGER.debug(f"[service_send_wol] clients: {clients}") + # _LOGGER.debug(f"[service_send_wol] clients: {clients}") for client in clients: _LOGGER.debug( f"[service_send_wol] Calling WOL. interface: {call.data.get('interface')}, mac: {call.data.get('mac')}"