Skip to content

Commit f6ca7aa

Browse files
authored
Connect Box event log support (#26)
* Add support for fetching and parsing Connect Box event logs My UPC/Magenta Austria Connect Box (Rev 5.01, Firmware release "CH7465LG-NCIP-6.12.18.26-3p7-1-NOSH") operates in "modem" aka bridge mode, and exposes an event log in its web interface, available under 'Advanced settings' > 'Tools' > 'Network status'. It contains events such as login( attempt)s to the web interface, as well as the modem having trouble getting its DOCSIS connection established. This patch makes this data available as a timestamp-sorted list. * Display Connect Box event log data
1 parent 2d26923 commit f6ca7aa

File tree

3 files changed

+39
-0
lines changed

3 files changed

+39
-0
lines changed

connect_box/__init__.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
FilterState,
2323
FilterStatesList,
2424
FiltersTimeMode,
25+
LogEvent,
2526
)
2627

2728
from . import exceptions
@@ -40,6 +41,7 @@
4041
CMD_SET_IPV6_FILTER_RULE = 112
4142
CMD_TEMPERATURE = 136
4243
CMD_CMSTATUS = 144
44+
CMD_EVENTLOG = 13
4345

4446

4547
class ConnectBox:
@@ -360,6 +362,30 @@ async def async_get_temperature(self):
360362
self.token = None
361363
raise exceptions.ConnectBoxNoDataAvailable() from None
362364

365+
async def async_get_eventlog(self):
366+
"""Get network-related eventlog data."""
367+
if self.token is None:
368+
await self.async_initialize_token()
369+
370+
self.eventlog = []
371+
raw = await self._async_ws_get_function(CMD_EVENTLOG)
372+
373+
try:
374+
xml_root = element_tree.fromstring(raw)
375+
for elmt_log_event in xml_root.iter("eventlog"):
376+
log_event = LogEvent(
377+
elmt_log_event.find("prior").text,
378+
elmt_log_event.find("text").text,
379+
elmt_log_event.find("time").text,
380+
int(elmt_log_event.find("t").text),
381+
)
382+
self.eventlog.append(log_event)
383+
except (element_tree.ParseError, TypeError):
384+
_LOGGER.warning("Can't read eventlog from %s", self.host)
385+
self.token = None
386+
raise exceptions.ConnectBoxNoDataAvailable() from None
387+
self.eventlog.sort(key=(lambda e: e.evEpoch))
388+
363389
async def async_close_session(self) -> None:
364390
"""Logout and close session."""
365391
if not self.token:

connect_box/data.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,3 +130,12 @@ class Temperature:
130130
# several other stats remain untapped here:
131131
# wan_ipv4_addr
132132
# wan_ipv6_addr, wan_ipv6_addr_entry
133+
134+
135+
@attr.s
136+
class LogEvent:
137+
"""An entry in the eventlog_table"""
138+
evPrio: str = attr.ib()
139+
evMsg: str = attr.ib()
140+
evTime: str = attr.ib()
141+
evEpoch: int = attr.ib()

example.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,10 @@ async def main():
4646
await client.async_get_temperature()
4747
pprint(client.temperature)
4848

49+
# Print event log entries
50+
await client.async_get_eventlog()
51+
pprint(client.eventlog)
52+
4953
await client.async_close_session()
5054

5155

0 commit comments

Comments
 (0)