Skip to content

A lightweight PHP script that captures and forwards syslog messages from a FRITZ!Box router to a remote syslog server.

License

Notifications You must be signed in to change notification settings

blancks/syslog-forwarder

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

34 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Syslog Forwarder for FRITZ!Box

A PHP script that forwards FRITZ!Box system logs to a syslog server.

Requirements

  • PHP 8.2 or higher
  • CURL extension
  • Access to a FRITZ!Box device
    • Tested with FRITZ!Box 7530, 7590
    • Tested with FRITZ!OS v.8.02, v.8.03
  • A syslog server (like rsyslog, syslog-ng)

Note: This is a command-line script - no web server is required.

Features

  • Real-time log forwarding from FRITZ!Box to syslog server
  • Supports RFC 3164 syslog format
  • Configurable refresh interval and retry mechanism
  • Secure authentication with FRITZ!Box web interface
  • Support for both legacy MD5 and modern PBKDF2 authentication
  • Graceful connection handling and error recovery

Installation

  1. Clone this repository or download the script
  2. Ensure PHP is installed and available in your PATH
  3. Make the script executable:
    chmod +x syslog-forwarder.php

Configuration

Copy the .env.example file to .env and edit the variables according to your needs. If configuration values are not set, the script will prompt for them at runtime.

Usage

Run the script from command line:

php syslog-forwarder.php

The script will:

  1. Connect to your FRITZ!Box
  2. Authenticate using the provided credentials
  3. Poll for new log entries at the configured interval
  4. Forward logs to your syslog server

To stop the script, press Ctrl+C.

Running as a Docker Container

docker compose up -d

Running as a Service

To run the script as a systemd service on Linux:

  1. Create a service file /etc/systemd/system/syslog-forwarder.service:
[Unit]
Description=Syslog Forwarder for FRITZ!Box
After=network.target

[Service]
Type=simple
User=YOUR_USERNAME
EnvironmentFile=/path/to/your/.env
ExecStart=/usr/bin/php /path/to/syslog-forwarder.php
Restart=always
RestartSec=3

[Install]
WantedBy=multi-user.target
  1. Enable and start the service:
sudo systemctl enable syslog-forwarder
sudo systemctl start syslog-forwarder
  1. Check status with:
sudo systemctl status syslog-forwarder

Syslog Message Format

Messages are sent in RFC 3164 format:

  • Facility: User-level messages (1)
  • Severity: Notice (5)
  • Message format: FRITZ!Box - (id:{ID}; group:{GROUP}) {MESSAGE}

Error Handling

  • Network errors will be retried with exponential backoff
  • Invalid sessions are automatically renewed
  • All errors are logged with timestamps

Background

This project was created to address the lack of native syslog forwarding capabilities in FRITZ!Box routers. It allows centralizing router event logs to a syslog server for better log management and monitoring.

This tool started as a personal utility and was developed in just a few hours. It's being shared for others who might need a simple solution to the same problem.

Why PHP?

PHP was chosen simply because it's a language I'm comfortable with. While there might be better technical choices for this task, PHP is simple enough to get the job done. The performance impact of using PHP with polling is negligible - even with 1-second refresh intervals, the resource usage remains minimal.

Contributing

Feel free to:

  • Request new features
  • Open issues if you need help
  • Submit pull requests to improve the project

Note: Please base your pull request on the dev branch. Pull requests to master may be closed or asked to rebase.

Tip: Before starting to work on a new feature or fix, check the list of opened issues. They are a good starting point for contributing and may help you avoid duplicated work.

All contributions are welcome! This project aims to be a simple solution, but that doesn't mean it can't be improved.

Trademark Notice

FRITZ!Box™ and FRITZ!OS™ are registered trademarks of AVM Computersysteme Vertriebs GmbH. This project is not affiliated with, endorsed by, or connected to AVM in any way.

License

This project is open source and available under the MIT License.

About

A lightweight PHP script that captures and forwards syslog messages from a FRITZ!Box router to a remote syslog server.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors 2

  •  
  •