This repository contains a script to monitor Klipper logs for specific events (such as print pauses, completions, and errors) and send email notifications. The script is triggered at the start of each print using Klipper's gcode_shell_command.
- Monitors
klippy.logfor key events like pauses, completions, shutdowns, and custom alerts - Sends email notifications with hostname, IP address, and timestamp
- Writes local event history to
monitor_events.log - Automatically avoids duplicate instances of the monitor
- Configurable via a TOML config file
Before installing, ensure the following are available on your Klipper system:
| Tool | Purpose |
|---|---|
python3 |
Runs the monitor script |
pip |
Installs Python libraries |
python3-dotenv |
Loads environment variables from .env |
toml |
Parses the TOML configuration file |
Update package list and install Python:
sudo apt update
sudo apt install -y python3 python3-pip
pip3 install python-dotenv tomlThis repository contains the following files:
printer_monitor.py: Main scriptprinter_monitor_config.toml: Keyword configprinter_monitor.env: Email credentials (you must fill this in)start_monitor.sh: Wrapper to safely launch the scriptemail_notify/: Git submodule (PythonEmailNotify) for reusable email logic
git clone --recurse-submodules https://github.com/killermelon1458/printer_monitor.git
cd printer_monitorCopy printer_monitor.env and edit it to include your email info:
SMTP_EMAIL=your_email@gmail.com
SMTP_PASS=your_app_password
SMTP_TO=recipient@example.com
⚠️ For Gmail, you must use an App Password, not your main password.
chmod +x start_monitor.shTo launch the script with every print, configure printer.cfg:
[gcode_shell_command start_printer_monitor]
command: /home/your_username/printer_monitor/start_monitor.sh
timeout: 5.0
verbose: False💡
timeoutmust be greater than 0.0 to avoid Klipper errors.
RUN_SHELL_COMMAND CMD=start_printer_monitorThis ensures the monitor starts at the beginning of every print.
The monitor watches klippy.log in real-time. It detects and logs:
- Pauses (
pause print,runout) - Resumes
- Completed prints (
finished sd card print, etc.) - Errors (
shutdown) - Custom keywords (e.g.,
thermal runaway,start)
It sends emails (if enabled in config) and writes local logs to monitor_events.log.
pgrep -af printer_monitor.pypgrep -fc printer_monitor.pytail -n 50 /home/your_username/printer_monitor/monitor_events.logtail -n 50 /home/your_username/printer_monitor/debug_output.logPython shell command integration with Klipper is made possible thanks to guidance from the KIAUH project:
MIT License – Use, fork, and modify freely.