Actually more like fritz-log-saver
, this repo started out as a parsing library.
Contributions are welcome! Just open a pull request and I'll take a look as soon as I see it. Please make sure the following requrements are met:
- If you change the database layout
- Try to do so with a new migration using
cargo sqlx migrate add --source ./data/migrations/ <MIGRATION-NAME>
to not break existing databases. - Run
cargo sqlx prepare
so offline compilation still works.
- Try to do so with a new migration using
- Run
cargo clippy
and fix the warnings. - Make sure the code still compiles and builds as a docker container.
Note: The code in /src/db/connection.rs
, specifically Database::append_new_logs
tries to handle the weird way logs are saved in the FRITZ!Box. If you know a way to access the raw logs, please open an issue.
See Deploy section for an example configuration.
DATABASE_URL
: Seesqlx
, must point to a SQLite database. Also see github.com/launchbadge/sqlx/issues/1114#issuecomment-827815038.FRITZBOX_DOMAIN
: Domain part of the FRITZ!Box URL. (e.g.192.168.178.1
orfritz.box
)FRITZBOX_USERNAME
: Username of the user this service should use.FRITZBOX_PASSWORD
: Password of the user this service should use.FRITZBOX_REFRESH_PAUSE_SECONDS
: How many seconds to wait between fetching logs.FRITZBOX_ROOT_CERT_PATH
: If you're using a custom certificate for the FRITZ!Box, you can set this path to point to the certificate of the CA (Certificate Authority) the certificate has been signed with. Otherwise all certificates will be accepted.FRITZBOX_SAVE_RESPONSE
: Whether to save responses received from the FRITZ!Box to a file, can betrue
orfalse
or omitted.FRITZBOX_SAVE_RESPONSE_PATH
: A path to the folder where the received responses will be saved to, each response will be saved to its own file within this folder.
I run a local registry and use a script similar to this
#!/bin/bash
set -e
IMAGE_NAME=fritz-log-parser
REGISTRY=your.registry.com
docker build -t $IMAGE_NAME .
docker tag $IMAGE_NAME $REGISTRY/$IMAGE_NAME
docker push $REGISTRY/$IMAGE_NAME
I use a docker-compose.yml
similar to this
name: fritz
services:
fritz:
image: your.registry.com/fritz-log-parser
restart: unless-stopped
environment:
TZ: Europe/Berlin
DATABASE_URL: sqlite:///opt/fritz/database/logs.db3
FRITZBOX_USERNAME: fritz6969
FRITZBOX_PASSWORD: pASSword
FRITZBOX_DOMAIN: 192.168.178.1
FRITZBOX_ROOT_CERT_PATH: /opt/fritz/certificates/cert.pem
FRITZBOX_REFRESH_PAUSE_SECONDS: 300
volumes:
- ./container-data/fritz/:/opt/fritz/
You can deploy it with docker compose -f docker-compose.yml up -d
where -f
specifies the compose file to use and -d
starts the container in the
background.
If you used the name from above you can check the logs with
docker logs -f fritz-fritz-1
where -f
specifies to follow the log output.
The logs should be similar to this
23:27:48 [WARN] couldn't load .env file: Io(Custom { kind: NotFound, error: "path not found" })
23:27:54 [INFO] login-challenge request to https://<OMITTED>/login_sid.lua?version=2 (GET - 200) took 5501ms (session-id: None)
23:27:55 [INFO] login-response request to https://<OMITTED>/login_sid.lua?version=2 (POST - 200) took 775ms (session-id: None)
23:27:55 [INFO] check-session-id request to https://<OMITTED>/login_sid.lua?version=2 (POST - 200) took 423ms (session-id: Some(<OMITTED>))
23:27:56 [INFO] logs request to https://<OMITTED>/data.lua (POST - 200) took 1122ms (session-id: Some(<OMITTED>))
23:27:56 [INFO] upserted 9 logs
Fetch the database (see Commands section), open it using DataGrip, DB Browser for SQLite or anything else that works for you and run some queries.
Need to set the TZ
docker container environment variable to the same timezone
as the FRITZ!Box because logs fetched from the FRITZ!Box are assumed to be in
the chrono::Local
Timezone.
For example, if the FRITZ!Box has the timezone Europe/Berlin
set,
TZ=Europe/Berlin
should be passed to the docker container. This can be
confirmed by running docker exec -it <CONTAINER-NAME> date
.
Note: Before inserting logs into the database, they are converted from
chrono::Local
to chrono::Utc
and when fetching logs from the database, they
are assumed to be in chrono::Utc
and will be converted to chrono::Local
.
- Create the database
cargo sqlx database setup --source ./data/migrations/ --sqlite-create-db-wal false
- Reset the database
cargo sqlx database reset --source ./data/migrations/ --sqlite-create-db-wal false
- Fetch the current database
scp <USER>@<HOST>:<PATH-TO-DB> <SAVE-PATH>
- Convert timestamps to readable localtime
DATETIME(FLOOR(<FIELD-NAME> / 1000), 'unixepoch', 'localtime')
- Divide by
1000
because timestamps have millisecond precision
- GitHub
- AVM
- Misc