Skip to main content

firewatcher

Watch a log stream (journald, syslog, or any file) for incident patterns, then persist a window of surrounding messages to a durable location — including a network filesystem — so the record survives even if the machine later dies.

This is the PyPI name for the internal firewatch tool (in use since 2023). The firewatch command remains as an alias. The PyPI name firewatch is a different, unrelated project.

The watcher prefers journalctl --follow when journalctl is on PATH. On hosts without journald it falls back to /var/log/syslog, then /var/log/messages, or --log-file. Running the daemon does not require systemd; only --install-service / --uninstall-service do.

Install

pip install firewatcher

From a clone of this repository:

pip install .

Requires Python 3.6+. No third-party runtime dependencies.

Quick start

firewatcher /etc/firewatcher/patterns.d
firewatch -t 300 -o /var/log/captured_messages/ /etc/firewatcher/patterns.d

A directory argument loads every non-hidden pattern file inside it. Files ending in .regex are compiled as regular expressions. Any other pattern file is treated as fnmatch (bash-like) substrings, with * added on both ends.

--install-service seeds /etc/firewatcher/patterns.d with example patterns when that directory is empty. The examples/ directory in the source tree is not installed onto PATH by pip install; copy those files from a clone, or let --install-service write them.

On a match, firewatcher writes:

  • a per-incident capture under {output-folder}/{YYYY-MM}/…
  • a line in {output-folder}/journal.log

Live capture is written as lines arrive, so a copy can already be on another filesystem if the host then disappears.

systemd service

sudo firewatcher --install-service
sudo firewatcher --print-unit
sudo firewatcher --uninstall-service

--install-service writes /etc/systemd/system/firewatcher.service, creates the output directory, seeds /etc/firewatcher/patterns.d/ with example patterns only if that directory is empty, then systemctl daemon-reload && systemctl enable --now firewatcher.

If systemd is not available, --install-service and --uninstall-service print a warning and exit. --print-unit still works so you can copy the unit elsewhere.

Useful flags:

Flag Description
--unit-name NAME Unit name (default: firewatcher)
--requires-mounts-for PATH Add RequiresMountsFor= (repeat for NFS/remote output)
--no-enable Write the unit and reload, but do not enable or start it
sudo firewatcher --install-service -o /mnt/logs/captured_messages \
  --requires-mounts-for /mnt/logs/captured_messages \
  /etc/firewatcher/patterns.d

Options

Flag Description
pattern_file … Pattern files or directories
--log-file Log file to follow (default: journalctl / syslog / messages)
-t, --capture-time Seconds of context after a match (default: 300)
-o, --output-folder Where to write captures (default: /var/log/captured_messages/)
--tail_lines Lines to start with (default: 20; +N from line N, not with journalctl)
--filter_only Filter existing logs only (cat instead of tail -F, or journalctl without --follow)
--compress-after-months Tar.xz monthly dirs after N months (default: 3)
--delete-after-months Delete YYYY-MM dirs after N months (default: 0 = never)
--capture_line_count_max Max lines before/after a match (default: 10000)
--install-service Install and enable a systemd unit
--print-unit Print that unit and exit
--uninstall-service Disable and remove the unit
-V, --version Show version and exit

Author

Yufei Pan (pan@zopyr.us)

License

GPL-3.0-or-later

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

firewatcher-1.55.tar.gz (16.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

firewatcher-1.55-py3-none-any.whl (11.0 kB view details)

Uploaded Python 3

File details

Details for the file firewatcher-1.55.tar.gz.

File metadata

  • Download URL: firewatcher-1.55.tar.gz
  • Upload date:
  • Size: 16.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.12.9 {"installer":{"name":"uv","version":"0.12.9","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Debian GNU/Linux","version":"13","id":"trixie","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for firewatcher-1.55.tar.gz
Algorithm Hash digest
SHA256 99472c150a13842defd0c00f83f5dfebc32e97f2fb9ef38ac88d6eb325c29ac5
MD5 615454220f327be8b4a0eada7866d1d4
BLAKE2b-256 98a63a0d3ddacd5d7ffe08eb918fde339b57c6d0fa279b72d71096bfdd4737dd

See more details on using hashes here.

File details

Details for the file firewatcher-1.55-py3-none-any.whl.

File metadata

  • Download URL: firewatcher-1.55-py3-none-any.whl
  • Upload date:
  • Size: 11.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.12.9 {"installer":{"name":"uv","version":"0.12.9","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Debian GNU/Linux","version":"13","id":"trixie","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for firewatcher-1.55-py3-none-any.whl
Algorithm Hash digest
SHA256 92f033ed437f8b2988ff60279a75c87a19de1730bfde85a3ad95d48d46d2c6c7
MD5 5cdd3ec827ce41e16e42764b81dc830b
BLAKE2b-256 81f60b90b99fd474f85f4c84cde13d1c96f480b8c30fa238f701b5e00cbe41a7

See more details on using hashes here.

Release history Release notifications | RSS feed

1.57

2 files

1.56

2 files

This release

1.55 This release

2 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page