Skip to content

Commit

Permalink
Merge pull request #211 from Snuffy2/Turn-down-Debug-logging
Browse files Browse the repository at this point in the history
Turn down Debug logging
  • Loading branch information
alexdelprete authored Sep 27, 2024
2 parents 7dd167c + 6ba59fe commit 71b06a7
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 46 deletions.
58 changes: 27 additions & 31 deletions custom_components/opnsense/pyopnsense/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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] = {}
Expand Down Expand Up @@ -877,15 +875,15 @@ 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
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] = {}
Expand All @@ -902,15 +900,15 @@ 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
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] = {}
Expand All @@ -923,15 +921,15 @@ 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
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] = {}
Expand All @@ -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)
)
Expand All @@ -972,15 +970,15 @@ 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
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] = {}
Expand Down Expand Up @@ -1011,15 +1009,15 @@ 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
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] = {}
Expand All @@ -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))
Expand All @@ -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
Expand All @@ -1049,31 +1047,29 @@ 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
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] = {}
openvpn["servers"] = {}
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():
Expand All @@ -1097,15 +1093,15 @@ 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
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] = {}
Expand All @@ -1116,15 +1112,15 @@ 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
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] = {}
Expand All @@ -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
Expand Down Expand Up @@ -1327,15 +1323,15 @@ 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
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 []
Expand Down
26 changes: 11 additions & 15 deletions custom_components/opnsense/services.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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:
Expand All @@ -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')}"
Expand All @@ -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(
Expand All @@ -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(
Expand All @@ -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:
Expand Down Expand Up @@ -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()
Expand All @@ -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()
Expand All @@ -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')}"
Expand Down

0 comments on commit 71b06a7

Please sign in to comment.