kbr/fritzconnection

GetDeviceLog always returns the same entries

Bluscream opened this issue · 6 comments

I use the following script to add GetDeviceLog entries to a mysql database, but everytime i run the script in cron it returns the same outdated entries from before. Also do i need to specify the filters? ("All", "System", "Internet", ...)

from time import sleep
from fritzconnection import FritzConnection
from pprint import pprint
from db import *
from re import finditer, MULTILINE, Match
from datetime import datetime

from urllib.request import urlopen
from urllib.parse import urlencode, quote_plus
from base64 import b64decode as b64d
def automagic(path = "/", query = {}):
    url = f'http://xxx/{path}?password={b64d("Z2FzdA==").decode("utf-8")}&{urlencode(query, quote_via=quote_plus)}'
    print(url)
    try: urlopen(url, timeout=.5)
    except: pass

fc: FritzConnection = FritzConnection(password="xxxx")
# fc.reconnect()  # get a new external ip from the provider
pprint(fc)  # print router model information
logstr = fc.call_action('DeviceInfo:1','GetDeviceLog')['NewDeviceLog']
regex = r"(\d+\.\d+\.\d+ \d+:\d+:\d+) (.*)"

existing: list[LogEntry] = get()

def checkMatch(match: Match):
    pprint(match.groups())
    msg: str = match.group(2).strip()
    timestamp = datetime.strptime(match.group(1), "%d.%m.%y %H:%M:%S") # 26.10.22 13:53:06
    for item in existing:
        if item.timestamp == timestamp: return
    add(message_de=msg, timestamp=timestamp)
    if msg.startswith("RADAR wurde auf Kanal "):
        automagic("notification/create", {"title": "Fritz!Box WARNING", "message": msg, "icon": "app.icon://de.almisoft.boxtogofulls"})
    if "Bitte FRITZ!Box neu starten" in msg:
        automagic("notification/create", {"title": "Fritz!Box ERROR", "vibrate": True, "message": msg, "icon": "app.icon://de.almisoft.boxtogofull"})
        automagic("popup/show", {"title": "Fritz!Box ERROR", "message": f"{msg}\n\nREBOOTING in 5 seconds..."})
        sleep(5)
        print("REBOOTING ROUTER")
        fc.reboot()
        

for match in finditer(regex, logstr, MULTILINE):  # type: ignore
    checkMatch(match)
kbr commented

The update interval of the log depends on events. It can happen that there are no events for a week or longer.

The update interval of the log depends on events. It can happen that there are no events for a week or longer.

But i can see the new logs just fine in the webinterface, just via fritzconnection they're missing

kbr commented

Seems the TR-064 service just returns a subset. The library does not filter the data.

Where is the use if it doesnt provide the same logs. Is there a lib that gets the same data from the website or do i need to scrape for that. Also would have been nice if the docs mentioned that TR is basically useless

kbr commented

Please contact the vendor in case you like to discuss this.

https://github.com/FlorianWendelborn/fritz-box#boxgetlog seems to do the trick, but requires me to rewrite my whole code to js. Would've been nice if your docs were clear enough to spare this for me