firewatcher 1.67__tar.gz → 1.68__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (34) hide show
  1. {firewatcher-1.67 → firewatcher-1.68}/MANIFEST.in +1 -0
  2. {firewatcher-1.67/firewatcher.egg-info → firewatcher-1.68}/PKG-INFO +21 -11
  3. {firewatcher-1.67 → firewatcher-1.68}/README.md +18 -7
  4. {firewatcher-1.67 → firewatcher-1.68}/docs/lessons-full.md +6 -0
  5. {firewatcher-1.67 → firewatcher-1.68}/docs/lessons.md +1 -0
  6. firewatcher-1.68/docs/limitations.md +100 -0
  7. {firewatcher-1.67 → firewatcher-1.68/firewatcher.egg-info}/PKG-INFO +21 -11
  8. {firewatcher-1.67 → firewatcher-1.68}/firewatcher.py +136 -242
  9. firewatcher-1.68/setup.py +38 -0
  10. {firewatcher-1.67 → firewatcher-1.68}/tests/test_capture.py +3 -3
  11. {firewatcher-1.67 → firewatcher-1.68}/tests/test_cli.py +20 -26
  12. {firewatcher-1.67 → firewatcher-1.68}/tests/test_config.py +13 -14
  13. {firewatcher-1.67 → firewatcher-1.68}/tests/test_events.py +1 -1
  14. {firewatcher-1.67 → firewatcher-1.68}/tests/test_notify.py +0 -2
  15. {firewatcher-1.67 → firewatcher-1.68}/tests/test_position.py +20 -14
  16. {firewatcher-1.67 → firewatcher-1.68}/tests/test_slugify.py +3 -6
  17. {firewatcher-1.67 → firewatcher-1.68}/tests/test_systemd.py +151 -16
  18. firewatcher-1.67/docs/limitations.md +0 -40
  19. firewatcher-1.67/setup.py +0 -28
  20. {firewatcher-1.67 → firewatcher-1.68}/LICENSE +0 -0
  21. {firewatcher-1.67 → firewatcher-1.68}/examples/firewatcher.conf +0 -0
  22. {firewatcher-1.67 → firewatcher-1.68}/examples/nvme_failure.regex +0 -0
  23. {firewatcher-1.67 → firewatcher-1.68}/examples/sys_msg.txt +0 -0
  24. {firewatcher-1.67 → firewatcher-1.68}/firewatcher.egg-info/SOURCES.txt +0 -0
  25. {firewatcher-1.67 → firewatcher-1.68}/firewatcher.egg-info/dependency_links.txt +0 -0
  26. {firewatcher-1.67 → firewatcher-1.68}/firewatcher.egg-info/entry_points.txt +0 -0
  27. {firewatcher-1.67 → firewatcher-1.68}/firewatcher.egg-info/top_level.txt +0 -0
  28. {firewatcher-1.67 → firewatcher-1.68}/setup.cfg +0 -0
  29. {firewatcher-1.67 → firewatcher-1.68}/tests/conftest.py +0 -0
  30. {firewatcher-1.67 → firewatcher-1.68}/tests/test_compressor.py +0 -0
  31. {firewatcher-1.67 → firewatcher-1.68}/tests/test_log_source.py +0 -0
  32. {firewatcher-1.67 → firewatcher-1.68}/tests/test_matching.py +0 -0
  33. {firewatcher-1.67 → firewatcher-1.68}/tests/test_patterns.py +0 -0
  34. {firewatcher-1.67 → firewatcher-1.68}/tests/test_redirects.py +0 -0
@@ -3,3 +3,4 @@ include README.md
3
3
  include examples/*
4
4
  include docs/*.md
5
5
  recursive-include tests *.py
6
+ exclude docs/progress.md
@@ -1,13 +1,12 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: firewatcher
3
- Version: 1.67
3
+ Version: 1.68
4
4
  Summary: Watch logs for incident patterns and persist surrounding context off-box
5
5
  Home-page: https://github.com/yufei-pan/firewatcher
6
6
  Author: Yufei Pan
7
7
  Author-email: pan@zopyr.us
8
- License: GPLv3+
8
+ License-Expression: GPL-3.0-or-later
9
9
  Classifier: Programming Language :: Python :: 3
10
- Classifier: License :: OSI Approved :: GNU General Public License v3 or later (GPLv3+)
11
10
  Classifier: Operating System :: POSIX :: Linux
12
11
  Classifier: Topic :: System :: Logging
13
12
  Classifier: Topic :: System :: Monitoring
@@ -20,8 +19,8 @@ Dynamic: classifier
20
19
  Dynamic: description
21
20
  Dynamic: description-content-type
22
21
  Dynamic: home-page
23
- Dynamic: license
24
22
  Dynamic: license-file
23
+ Dynamic: license-expression
25
24
  Dynamic: requires-python
26
25
  Dynamic: summary
27
26
 
@@ -89,13 +88,13 @@ When firewatcher follows the journal (not a log file), it saves how far it has r
89
88
 
90
89
  To tell where it stopped, firewatcher reads the journal with `journalctl -o short-iso`, so journal lines in captures carry the year and time zone: `2026-10-23T17:52:41+00:00 host sshd[812]: …` instead of `Oct 23 17:52:41 host sshd[812]: …`. Lines logged while firewatcher was stopped arrive all at once. A capture opened by one of them takes its context from the `--capture-time` before that line by the time each line was logged, and holds the lines after it as they are read, up to `--capture-line-count-max`.
91
90
 
92
- The position is the second of the last line read, which line of that second it was, and a digest of that line. When unsure, firewatcher reads a line again rather than skip it. A run that started from `--tail-lines` in the middle of a second numbers that second's lines from where it started, so identical lines logged in that second can be captured again after a restart. A save that fails is logged once, and a restart then reads again from the last position saved. If the clock is set back after a position is saved, for example at a boot with a wrong hardware clock, new lines stamped before that second count as already read. A position more than a minute in the future is ignored.
91
+ The position is the second of the last line read, its place in that second, and a digest of it. When unsure, firewatcher reads a line again rather than skip it, so identical lines logged in one second can be captured again after a restart. A failed save is logged once, and a restart then reads again from the last position saved. If the clock is set back after a save (a boot with a wrong hardware clock), the lines after the saved line are still matched, even when they are stamped before the saved second; a position more than a minute in the future is ignored.
93
92
 
94
93
  Only one firewatcher uses a position file at a time: another one started with the same file, such as a test run in a terminal with the default settings, reads the last `--tail-lines` lines and saves nothing. An empty `--position-file` turns resuming off, and so does a journalctl that does not accept `-o short-iso` and `--since=@`, which firewatcher checks at start.
95
94
 
96
95
  ### Disk and memory limits
97
96
 
98
- firewatcher keeps the filesystems it writes captures to above `--min-free-percent` free (default 1%, counted as `df` does, so the root-reserved blocks are left alone). Only what the filesystem reports authorizes a write. firewatcher checks when a capture opens, about once a second, and again before what it has written since the last check could bring it within 64 KiB of the floor (and at least every 8 MiB), fsyncing first so the filesystem, an NFS server included, counts every byte. A line that would cross that margin is not written there. Another program filling the same disk between two checks can still push it past the floor; firewatcher's own writes do not.
97
+ firewatcher keeps the filesystems it writes captures to above `--min-free-percent` free (default 1%, counted as `df` does, so the root-reserved blocks are left alone). It asks the filesystem when a capture opens, about once a second, and before its own writes could come within 64 KiB of the floor (at least every 8 MiB), fsyncing first so an NFS server counts every byte; a line that would cross that margin is not written there. firewatcher's own writes never take the disk past the floor; another program filling it between two checks can.
99
98
 
100
99
  Near the floor, firewatcher may delete its own oldest months in that folder, so a new incident can be recorded, under these rules:
101
100
 
@@ -106,9 +105,9 @@ Near the floor, firewatcher may delete its own oldest months in that folder, so
106
105
 
107
106
  After deleting, firewatcher syncs and reads the free space again. A filesystem that shows freed space late costs a move to the fallback folder, never the floor. If there is still no room, the capture moves to the fallback folder with a note, or, with no folder left, stops being written, which is logged; the incident is still pushed. Compression keeps to the floor too: a month whose archive could cross it is left uncompressed for now. Purging and compression never wait for each other, so log reading never waits for `tar`. `--delete-after-months 0` means nothing is deleted by age; the floor can still delete the oldest months. Set `--min-free-percent 0` to turn all of this off.
108
107
 
109
- Memory is bounded too. The `--capture-time` seconds before a match are kept in memory compressed (zlib, in blocks of about 64 KiB of text; with its bookkeeping, about 3 times smaller than the text for a busy host's varied lines, more for repetitive ones), within `--buffer-max-mb` (default 16 MiB). Past the limit the oldest block is dropped and the capture says so. The newest lines, up to 256 KiB of them before they are compressed, are always kept, so the buffer can go over the limit by about that much, or by one very long line. Compression costs well under a microsecond per line. A line longer than 1 MiB is read in pieces, and each piece is matched on its own, so a pattern split across the 1 MiB boundary is missed. The LLM excerpt reads at most `max_bytes` of a capture.
108
+ Memory is bounded too. The `--capture-time` seconds before a match are kept compressed (zlib, about 3 times smaller for a busy host's varied lines) within `--buffer-max-mb` (default 16 MiB); past it the oldest lines are dropped, and the capture says so. The newest lines, up to 256 KiB before they are compressed, are always kept, so the buffer can go over the limit by about that much. A line longer than 1 MiB is read and matched in pieces, so a pattern split across a 1 MiB boundary is missed.
110
109
 
111
- Monthly directories are compressed on a background thread, so log reading never waits for `tar`. Each month becomes `YYYY-MM.tar.xz` holding `YYYY-MM/…`. The directory is removed only after `tar` succeeds and the archive is synced to disk. An existing archive is never overwritten: the new one becomes `YYYY-MM.1.tar.xz`, and so on.
110
+ Monthly directories are compressed on a background thread, so log reading never waits for `tar`. Each month becomes `YYYY-MM.tar.xz` holding `YYYY-MM/…`. The directory is removed only after `tar` succeeds and the archive and its folder are synced to disk; if a sync fails, the month stays and is archived again later, nothing lost. An existing archive is never overwritten: the new one becomes `YYYY-MM.1.tar.xz`, and so on.
112
111
 
113
112
  ## systemd service
114
113
 
@@ -118,7 +117,7 @@ sudo firewatcher --print-unit
118
117
  sudo firewatcher --uninstall-service
119
118
  ```
120
119
 
121
- `--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**, writes `/etc/firewatcher/firewatcher.conf` **only if that file is missing**, then `systemctl daemon-reload && systemctl enable --now firewatcher`.
120
+ `--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**, writes `/etc/firewatcher/firewatcher.conf` **only if that file is missing**, then `systemctl daemon-reload && systemctl enable --now firewatcher`. It checks first, and writes nothing (exit 2) for a unit name systemd cannot load (letters, digits and `: _ . @ - \`, at most 255 characters with the `.service` suffix, any `@` between a name and an instance) or a path or value that is not UTF-8.
122
121
 
123
122
  `systemctl reload firewatcher` reloads the pattern files without a restart; see SIGHUP above.
124
123
 
@@ -214,7 +213,7 @@ always_notify =
214
213
 
215
214
  `patterns` and `always_notify` are one path per line, or comma-separated. Positional pattern arguments replace the `patterns` list.
216
215
 
217
- Out-of-range values stop `firewatcher` at startup: a negative time or count, `capture_time` over 7 days or `capture_time_max` over 30 days, `min_free_percent` outside 0–50, `purge_interval` or `resume_max` over 30 days, `buffer_max_mb` below 1, a timeout of 0 or less or over a day, an ntfy priority outside 1–5, or an LLM, ntfy or events URL that does not start with `http://` or `https://` or that contains spaces, or whose server part (after any `user:password@`) is not a host name with no `/`, `?`, `#`, `@`, `[`, `]`, `:` or `%` in it, or an IPv6 address in brackets, then an optional `:port` of up to 5 digits (0–65535); so a `user:password` holding a `/`, `?` or `#` is refused (`[` and `]` are fine there, since the `user:password` is stripped before the request). Also refused is a URL with a `user:password` that has another `@` later in its path, query or fragment (a password holding an `@` before a `/`, `?` or `#`). A password that starts with digits and a `/` still reads as a host and port, and those digits show as the port in logs ([limitations](https://github.com/yufei-pan/firewatcher/blob/master/docs/limitations.md#a-url-whose-password-starts-with-digits-and-a--shows-those-digits-as-the-port)).
216
+ Out-of-range values stop `firewatcher` at startup: a negative time or count, `capture_time` over 7 days or `capture_time_max` over 30 days, `min_free_percent` outside 0–50, `purge_interval` or `resume_max` over 30 days, `buffer_max_mb` outside 1–65536, a timeout of 0 or less or over a day, or an ntfy priority outside 1–5. So does an LLM, ntfy or events URL that is not `http://` or `https://`, has spaces, or whose server part is not a host name or a bracketed IPv6 address with an optional port (0–65535), as firewatcher reads it by its own strict rule. A `user:password` in a URL is never sent; one that would make the URL read two ways is refused, with [one exception](https://github.com/yufei-pan/firewatcher/blob/master/docs/limitations.md#a-url-whose-password-starts-with-digits-and-a--shows-those-digits-as-the-port).
218
217
 
219
218
  `api_key` under `[llm]` and `token` under `[notify]` are not command-line flags. `FIREWATCHER_LLM_API_KEY` and `FIREWATCHER_NTFY_TOKEN` override them when set. `events_token` under `[notify]` is likewise config-only, overridden by `FIREWATCHER_EVENTS_TOKEN`. `--install-service` creates `/etc/firewatcher/firewatcher.conf` with mode `0600` only when it is missing, and the unit runs `firewatcher --config` that path. An existing file is left as it is. Flags passed to a later install are appended on `ExecStart` so they override the file.
220
219
 
@@ -237,7 +236,7 @@ A capture that fits in `max_bytes` (default 48000) is sent whole. A bigger one i
237
236
 
238
237
  Any user or program on the host can write log lines, and those lines reach the model. The request marks the matched line and the excerpt as untrusted data between `BEGIN`/`END` lines that carry a random token, and the system prompt tells the model never to follow instructions inside them. That makes it harder for a log line to talk the model out of notifying, but cannot rule it out. For incidents that must always reach you, list patterns under `[notify] always_notify` (or `--always-notify`): when a line that matched a watch pattern also matches one of them, the capture is pushed even if the model says not to notify. That push uses the generated title and the line that matched, followed by the model's summary, since log text can steer the summary as well. If no always_notify pattern loads, firewatcher logs an error and keeps capturing without it; `--always-notify ''` clears a list set in the config. Only the line that opened the capture and later lines that matched a watch pattern while it was open count. Other lines in the window do not, and neither do matches from an earlier capture that appear as context. The capture's color codes are removed before it is sent to the model.
239
238
 
240
- `[llm] notes` (or `--llm-notes TEXT`; `note` also works as the key; the flag wins over the file, and `--llm-notes ''` clears a note set in the config) is a short free-text note about this host, for example `loop/dm devices from pytest and /tmp/claude-*/scratchpad and OOMs in capped test containers are expected`. It is sent with every capture as a line `Operator notes about this host: ...` before the untrusted log data, outside the `BEGIN`/`END` block, and the system prompt tells the model that notes describe what is normal there. Any run of whitespace in a note, newlines included, becomes one space. Only you can set it, so unlike the log lines it is trusted text; keep it short, since it is sent with every capture. When the config exists, `--install-service --llm-notes ...` puts the note on the unit's `ExecStart` (as one `--llm-notes=...` word, with `%` and `$` doubled for systemd), like any flag given there: local users can read it with `systemctl cat`, and it overrides `notes` in the config until the unit is reinstalled. To keep it private and editable, set it in the config instead.
239
+ `[llm] notes` (or `--llm-notes TEXT`; `note` also works as the key, and `--llm-notes ''` clears a note set in the config) is a short note about this host, for example `loop/dm devices from pytest and /tmp/claude-*/scratchpad and OOMs in capped test containers are expected`. It is sent with every capture as `Operator notes about this host: ...`, outside the untrusted `BEGIN`/`END` block, and the system prompt tells the model that notes describe what is normal there. Any run of whitespace in it, newlines included, becomes one space. Given to `--install-service` while the config exists, the note goes on the unit's `ExecStart`, like any flag given there: local users can read it, and it overrides the config until the unit is reinstalled. Set it in the config to keep it private.
241
240
 
242
241
  The ntfy topic URL is not printed at startup or in error messages, since on a public ntfy server whoever knows the topic can subscribe to it. Only the server is shown. Keep the topic in the config file (mode `0600`) rather than on the command line: `--ntfy-url` shows in the process list, and when the config already exists, `--install-service --ntfy-url` puts it on the unit's `ExecStart`, which any user can read. `--install-service` warns when that happens.
243
242
 
@@ -265,6 +264,17 @@ Captures are posted whatever `push` says, so the service sees them all. Any 2xx
265
264
  Lines firewatcher writes back to the journal are a single physical line containing `firewatcher-self`, so a summary that quotes `panic` or `I/O error` does not start another capture. In journalctl and syslog output, firewatcher recognizes its own lines by the identifier field after the timestamp and host (`firewatcher[PID]:`), not by text elsewhere in the line, so a process or user name chosen to look like firewatcher cannot hide a kernel or daemon message. Lines in other formats are checked for `firewatcher-self` or `firewatcher[PID]:` anywhere. The capture files themselves stay in the log stream's original format.
266
265
 
267
266
 
267
+ ## Upgrading to 1.68 from 1.67
268
+
269
+ Nothing to change. What is different:
270
+
271
+ - `--install-service` refuses a unit name systemd cannot load, and a path or value that is not UTF-8, before it writes anything (exit 2). 1.67 could write the config first and then stop with a traceback, or install a unit under a name systemd skips. A blank `--unit-name` now means `firewatcher`, as an empty one did.
272
+ - `systemctl enable --now` and `disable --now` get `--` before the unit name, so a name starting with `-` works.
273
+ - On Python 3.6 under a C locale, a non-ASCII path or note given on the command line reads as undecodable bytes, and a service started under that locale could not encode it, so `--install-service` refuses it (exit 2, nothing written) and says to run under a UTF-8 locale (one that `locale -a` lists, such as `en_US.UTF-8`; CentOS 7 has no `C.UTF-8`). 1.67 stopped there with a `UnicodeEncodeError`. Under a UTF-8 locale, and on Python 3.7 and later, such a path installs as before.
274
+ - The package declares its license as the SPDX expression `GPL-3.0-or-later` when built with setuptools 77 or later.
275
+ - `--uninstall-service --unit-name` with a path (`a/b`) now prints a message and exits 2; 1.67 stopped with a traceback. It still takes any other name an older firewatcher may have installed.
276
+ - Dead code and duplicated rules are gone (`firewatcher.py` went from 3,227 to 3,084 lines before the install checks were added); nothing else an operator sees changed.
277
+
268
278
  ## Development
269
279
 
270
280
  ```bash
@@ -62,13 +62,13 @@ When firewatcher follows the journal (not a log file), it saves how far it has r
62
62
 
63
63
  To tell where it stopped, firewatcher reads the journal with `journalctl -o short-iso`, so journal lines in captures carry the year and time zone: `2026-10-23T17:52:41+00:00 host sshd[812]: …` instead of `Oct 23 17:52:41 host sshd[812]: …`. Lines logged while firewatcher was stopped arrive all at once. A capture opened by one of them takes its context from the `--capture-time` before that line by the time each line was logged, and holds the lines after it as they are read, up to `--capture-line-count-max`.
64
64
 
65
- The position is the second of the last line read, which line of that second it was, and a digest of that line. When unsure, firewatcher reads a line again rather than skip it. A run that started from `--tail-lines` in the middle of a second numbers that second's lines from where it started, so identical lines logged in that second can be captured again after a restart. A save that fails is logged once, and a restart then reads again from the last position saved. If the clock is set back after a position is saved, for example at a boot with a wrong hardware clock, new lines stamped before that second count as already read. A position more than a minute in the future is ignored.
65
+ The position is the second of the last line read, its place in that second, and a digest of it. When unsure, firewatcher reads a line again rather than skip it, so identical lines logged in one second can be captured again after a restart. A failed save is logged once, and a restart then reads again from the last position saved. If the clock is set back after a save (a boot with a wrong hardware clock), the lines after the saved line are still matched, even when they are stamped before the saved second; a position more than a minute in the future is ignored.
66
66
 
67
67
  Only one firewatcher uses a position file at a time: another one started with the same file, such as a test run in a terminal with the default settings, reads the last `--tail-lines` lines and saves nothing. An empty `--position-file` turns resuming off, and so does a journalctl that does not accept `-o short-iso` and `--since=@`, which firewatcher checks at start.
68
68
 
69
69
  ### Disk and memory limits
70
70
 
71
- firewatcher keeps the filesystems it writes captures to above `--min-free-percent` free (default 1%, counted as `df` does, so the root-reserved blocks are left alone). Only what the filesystem reports authorizes a write. firewatcher checks when a capture opens, about once a second, and again before what it has written since the last check could bring it within 64 KiB of the floor (and at least every 8 MiB), fsyncing first so the filesystem, an NFS server included, counts every byte. A line that would cross that margin is not written there. Another program filling the same disk between two checks can still push it past the floor; firewatcher's own writes do not.
71
+ firewatcher keeps the filesystems it writes captures to above `--min-free-percent` free (default 1%, counted as `df` does, so the root-reserved blocks are left alone). It asks the filesystem when a capture opens, about once a second, and before its own writes could come within 64 KiB of the floor (at least every 8 MiB), fsyncing first so an NFS server counts every byte; a line that would cross that margin is not written there. firewatcher's own writes never take the disk past the floor; another program filling it between two checks can.
72
72
 
73
73
  Near the floor, firewatcher may delete its own oldest months in that folder, so a new incident can be recorded, under these rules:
74
74
 
@@ -79,9 +79,9 @@ Near the floor, firewatcher may delete its own oldest months in that folder, so
79
79
 
80
80
  After deleting, firewatcher syncs and reads the free space again. A filesystem that shows freed space late costs a move to the fallback folder, never the floor. If there is still no room, the capture moves to the fallback folder with a note, or, with no folder left, stops being written, which is logged; the incident is still pushed. Compression keeps to the floor too: a month whose archive could cross it is left uncompressed for now. Purging and compression never wait for each other, so log reading never waits for `tar`. `--delete-after-months 0` means nothing is deleted by age; the floor can still delete the oldest months. Set `--min-free-percent 0` to turn all of this off.
81
81
 
82
- Memory is bounded too. The `--capture-time` seconds before a match are kept in memory compressed (zlib, in blocks of about 64 KiB of text; with its bookkeeping, about 3 times smaller than the text for a busy host's varied lines, more for repetitive ones), within `--buffer-max-mb` (default 16 MiB). Past the limit the oldest block is dropped and the capture says so. The newest lines, up to 256 KiB of them before they are compressed, are always kept, so the buffer can go over the limit by about that much, or by one very long line. Compression costs well under a microsecond per line. A line longer than 1 MiB is read in pieces, and each piece is matched on its own, so a pattern split across the 1 MiB boundary is missed. The LLM excerpt reads at most `max_bytes` of a capture.
82
+ Memory is bounded too. The `--capture-time` seconds before a match are kept compressed (zlib, about 3 times smaller for a busy host's varied lines) within `--buffer-max-mb` (default 16 MiB); past it the oldest lines are dropped, and the capture says so. The newest lines, up to 256 KiB before they are compressed, are always kept, so the buffer can go over the limit by about that much. A line longer than 1 MiB is read and matched in pieces, so a pattern split across a 1 MiB boundary is missed.
83
83
 
84
- Monthly directories are compressed on a background thread, so log reading never waits for `tar`. Each month becomes `YYYY-MM.tar.xz` holding `YYYY-MM/…`. The directory is removed only after `tar` succeeds and the archive is synced to disk. An existing archive is never overwritten: the new one becomes `YYYY-MM.1.tar.xz`, and so on.
84
+ Monthly directories are compressed on a background thread, so log reading never waits for `tar`. Each month becomes `YYYY-MM.tar.xz` holding `YYYY-MM/…`. The directory is removed only after `tar` succeeds and the archive and its folder are synced to disk; if a sync fails, the month stays and is archived again later, nothing lost. An existing archive is never overwritten: the new one becomes `YYYY-MM.1.tar.xz`, and so on.
85
85
 
86
86
  ## systemd service
87
87
 
@@ -91,7 +91,7 @@ sudo firewatcher --print-unit
91
91
  sudo firewatcher --uninstall-service
92
92
  ```
93
93
 
94
- `--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**, writes `/etc/firewatcher/firewatcher.conf` **only if that file is missing**, then `systemctl daemon-reload && systemctl enable --now firewatcher`.
94
+ `--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**, writes `/etc/firewatcher/firewatcher.conf` **only if that file is missing**, then `systemctl daemon-reload && systemctl enable --now firewatcher`. It checks first, and writes nothing (exit 2) for a unit name systemd cannot load (letters, digits and `: _ . @ - \`, at most 255 characters with the `.service` suffix, any `@` between a name and an instance) or a path or value that is not UTF-8.
95
95
 
96
96
  `systemctl reload firewatcher` reloads the pattern files without a restart; see SIGHUP above.
97
97
 
@@ -187,7 +187,7 @@ always_notify =
187
187
 
188
188
  `patterns` and `always_notify` are one path per line, or comma-separated. Positional pattern arguments replace the `patterns` list.
189
189
 
190
- Out-of-range values stop `firewatcher` at startup: a negative time or count, `capture_time` over 7 days or `capture_time_max` over 30 days, `min_free_percent` outside 0–50, `purge_interval` or `resume_max` over 30 days, `buffer_max_mb` below 1, a timeout of 0 or less or over a day, an ntfy priority outside 1–5, or an LLM, ntfy or events URL that does not start with `http://` or `https://` or that contains spaces, or whose server part (after any `user:password@`) is not a host name with no `/`, `?`, `#`, `@`, `[`, `]`, `:` or `%` in it, or an IPv6 address in brackets, then an optional `:port` of up to 5 digits (0–65535); so a `user:password` holding a `/`, `?` or `#` is refused (`[` and `]` are fine there, since the `user:password` is stripped before the request). Also refused is a URL with a `user:password` that has another `@` later in its path, query or fragment (a password holding an `@` before a `/`, `?` or `#`). A password that starts with digits and a `/` still reads as a host and port, and those digits show as the port in logs ([limitations](https://github.com/yufei-pan/firewatcher/blob/master/docs/limitations.md#a-url-whose-password-starts-with-digits-and-a--shows-those-digits-as-the-port)).
190
+ Out-of-range values stop `firewatcher` at startup: a negative time or count, `capture_time` over 7 days or `capture_time_max` over 30 days, `min_free_percent` outside 0–50, `purge_interval` or `resume_max` over 30 days, `buffer_max_mb` outside 1–65536, a timeout of 0 or less or over a day, or an ntfy priority outside 1–5. So does an LLM, ntfy or events URL that is not `http://` or `https://`, has spaces, or whose server part is not a host name or a bracketed IPv6 address with an optional port (0–65535), as firewatcher reads it by its own strict rule. A `user:password` in a URL is never sent; one that would make the URL read two ways is refused, with [one exception](https://github.com/yufei-pan/firewatcher/blob/master/docs/limitations.md#a-url-whose-password-starts-with-digits-and-a--shows-those-digits-as-the-port).
191
191
 
192
192
  `api_key` under `[llm]` and `token` under `[notify]` are not command-line flags. `FIREWATCHER_LLM_API_KEY` and `FIREWATCHER_NTFY_TOKEN` override them when set. `events_token` under `[notify]` is likewise config-only, overridden by `FIREWATCHER_EVENTS_TOKEN`. `--install-service` creates `/etc/firewatcher/firewatcher.conf` with mode `0600` only when it is missing, and the unit runs `firewatcher --config` that path. An existing file is left as it is. Flags passed to a later install are appended on `ExecStart` so they override the file.
193
193
 
@@ -210,7 +210,7 @@ A capture that fits in `max_bytes` (default 48000) is sent whole. A bigger one i
210
210
 
211
211
  Any user or program on the host can write log lines, and those lines reach the model. The request marks the matched line and the excerpt as untrusted data between `BEGIN`/`END` lines that carry a random token, and the system prompt tells the model never to follow instructions inside them. That makes it harder for a log line to talk the model out of notifying, but cannot rule it out. For incidents that must always reach you, list patterns under `[notify] always_notify` (or `--always-notify`): when a line that matched a watch pattern also matches one of them, the capture is pushed even if the model says not to notify. That push uses the generated title and the line that matched, followed by the model's summary, since log text can steer the summary as well. If no always_notify pattern loads, firewatcher logs an error and keeps capturing without it; `--always-notify ''` clears a list set in the config. Only the line that opened the capture and later lines that matched a watch pattern while it was open count. Other lines in the window do not, and neither do matches from an earlier capture that appear as context. The capture's color codes are removed before it is sent to the model.
212
212
 
213
- `[llm] notes` (or `--llm-notes TEXT`; `note` also works as the key; the flag wins over the file, and `--llm-notes ''` clears a note set in the config) is a short free-text note about this host, for example `loop/dm devices from pytest and /tmp/claude-*/scratchpad and OOMs in capped test containers are expected`. It is sent with every capture as a line `Operator notes about this host: ...` before the untrusted log data, outside the `BEGIN`/`END` block, and the system prompt tells the model that notes describe what is normal there. Any run of whitespace in a note, newlines included, becomes one space. Only you can set it, so unlike the log lines it is trusted text; keep it short, since it is sent with every capture. When the config exists, `--install-service --llm-notes ...` puts the note on the unit's `ExecStart` (as one `--llm-notes=...` word, with `%` and `$` doubled for systemd), like any flag given there: local users can read it with `systemctl cat`, and it overrides `notes` in the config until the unit is reinstalled. To keep it private and editable, set it in the config instead.
213
+ `[llm] notes` (or `--llm-notes TEXT`; `note` also works as the key, and `--llm-notes ''` clears a note set in the config) is a short note about this host, for example `loop/dm devices from pytest and /tmp/claude-*/scratchpad and OOMs in capped test containers are expected`. It is sent with every capture as `Operator notes about this host: ...`, outside the untrusted `BEGIN`/`END` block, and the system prompt tells the model that notes describe what is normal there. Any run of whitespace in it, newlines included, becomes one space. Given to `--install-service` while the config exists, the note goes on the unit's `ExecStart`, like any flag given there: local users can read it, and it overrides the config until the unit is reinstalled. Set it in the config to keep it private.
214
214
 
215
215
  The ntfy topic URL is not printed at startup or in error messages, since on a public ntfy server whoever knows the topic can subscribe to it. Only the server is shown. Keep the topic in the config file (mode `0600`) rather than on the command line: `--ntfy-url` shows in the process list, and when the config already exists, `--install-service --ntfy-url` puts it on the unit's `ExecStart`, which any user can read. `--install-service` warns when that happens.
216
216
 
@@ -238,6 +238,17 @@ Captures are posted whatever `push` says, so the service sees them all. Any 2xx
238
238
  Lines firewatcher writes back to the journal are a single physical line containing `firewatcher-self`, so a summary that quotes `panic` or `I/O error` does not start another capture. In journalctl and syslog output, firewatcher recognizes its own lines by the identifier field after the timestamp and host (`firewatcher[PID]:`), not by text elsewhere in the line, so a process or user name chosen to look like firewatcher cannot hide a kernel or daemon message. Lines in other formats are checked for `firewatcher-self` or `firewatcher[PID]:` anywhere. The capture files themselves stay in the log stream's original format.
239
239
 
240
240
 
241
+ ## Upgrading to 1.68 from 1.67
242
+
243
+ Nothing to change. What is different:
244
+
245
+ - `--install-service` refuses a unit name systemd cannot load, and a path or value that is not UTF-8, before it writes anything (exit 2). 1.67 could write the config first and then stop with a traceback, or install a unit under a name systemd skips. A blank `--unit-name` now means `firewatcher`, as an empty one did.
246
+ - `systemctl enable --now` and `disable --now` get `--` before the unit name, so a name starting with `-` works.
247
+ - On Python 3.6 under a C locale, a non-ASCII path or note given on the command line reads as undecodable bytes, and a service started under that locale could not encode it, so `--install-service` refuses it (exit 2, nothing written) and says to run under a UTF-8 locale (one that `locale -a` lists, such as `en_US.UTF-8`; CentOS 7 has no `C.UTF-8`). 1.67 stopped there with a `UnicodeEncodeError`. Under a UTF-8 locale, and on Python 3.7 and later, such a path installs as before.
248
+ - The package declares its license as the SPDX expression `GPL-3.0-or-later` when built with setuptools 77 or later.
249
+ - `--uninstall-service --unit-name` with a path (`a/b`) now prints a message and exits 2; 1.67 stopped with a traceback. It still takes any other name an older firewatcher may have installed.
250
+ - Dead code and duplicated rules are gone (`firewatcher.py` went from 3,227 to 3,084 lines before the install checks were added); nothing else an operator sees changed.
251
+
241
252
  ## Development
242
253
 
243
254
  ```bash
@@ -35,3 +35,9 @@ entries go last, in the same commit as the change:
35
35
  - Why we had to change: a password holding an `@` before a `/`, `?` or `#` left the text between them as the host, and the host is logged. Review took five fix rounds on this check (credentials in requests and logs, unparseable URLs echoed, a password holding an `@`), and the last one replaced the library's view of the authority with our own check that gives the same answer on every Python.
36
36
  - Original design was wrong because: it used a lenient library parser for a value that is both sent in requests and written to logs, and the old check accepted nearly anything with an http prefix.
37
37
  - Lesson: when a value is both used for requests and written to logs, parse it once with our own strict rule that behaves the same on every runtime, not a lenient library parser. Record what that refuses that used to be accepted, as the entry above does.
38
+
39
+ ## 2026-11-14 firewatcher 1.68: --install-service checks and renders everything before it writes
40
+ - Changed: `--install-service` refuses a unit name systemd cannot load or enable (characters other than letters, digits and `: _ . @ - \`, more than 255 with the `.service` suffix, an `@` without a name before it or an instance after it) and a path or value that is not UTF-8 (on Python 3.6 under a C locale that is every non-ASCII one: it is refused, not restored, because the service under the same locale could not encode it either), with exit 2, before it creates the output folder, seeds patterns or writes the config or the unit. It renders the unit and the new config first and writes the text it rendered. A blank `--unit-name` means the default. 1.67 took any name as a file name and wrote the config before it had rendered the unit.
41
+ - Why we had to change: a name such as `a/b` stopped the install with a traceback after the config was written, and that left-over config made the next install render a different unit (flags on `ExecStart` instead of in the config). A name such as `fwé` was written as a file systemd skips, so `enable` failed, and with `--no-enable` the install reported success. A non-UTF-8 value stopped it with `UnicodeEncodeError`, again after the output folder and patterns were made.
42
+ - Original design was wrong because: it treated an install as a series of independent writes, so a step that failed late left the earlier ones behind as state the next run read (1.68 closes that for the checks and the rendering; a failed `daemon-reload` or `enable --now` after the writes still leaves the config and the unit, which a rerun reads: deferred to 1.69); and it checked the unit name only as a file name, not by the rules of systemd, which is what loads it.
43
+ - Lesson: an install that writes several files checks and renders all of them, by the rules of the program that will read each one, before it writes any, so a refusal leaves nothing behind. A step that fails after the writes (a systemctl call) still leaves them: a half-done install is state that changes what the next install does.
@@ -11,3 +11,4 @@ same commit as the change. Keep this file under 20 KB: at the cap, merge lines b
11
11
  - **2026-10-27 firewatcher: --requires-mounts-for paths are normalized as text, never resolved on disk**: when you write a value into another program's file format, test what that program reads back for each odd input, against the real program. Transform the value only as the reading program would (here as text, like systemd), never by consulting state that may be absent or hung at the time you write.
12
12
  - **2026-11-03 firewatcher 1.65: the verdict moved to the receiver**: when a pipeline gains a smarter stage downstream, move the judgment there whole, and keep only the rule-based floor (`always_notify`) at the source.
13
13
  - **2026-11-03 firewatcher 1.65: a URL is parsed once, by our own strict rule**: when a value is both used for requests and written to logs, parse it once with our own strict rule that behaves the same on every runtime, not a lenient library parser. Record what that refuses that used to be accepted, as the entry above does.
14
+ - **2026-11-14 firewatcher 1.68: --install-service checks and renders everything before it writes**: an install that writes several files checks and renders all of them, by the rules of the program that will read each one, before writing any, so a refusal leaves nothing behind; a step that fails after the writes (a systemctl call) still leaves them, and a half-done install is state that changes what the next install does.
@@ -0,0 +1,100 @@
1
+ # Limitations
2
+
3
+ Approved known limitations and deferrals. Reviewers: read this first, and don't raise these again.
4
+
5
+ ### On systemd 229 and older, some mount paths are written wrong
6
+ - Kind: known limitation
7
+ - What the operator sees: on systemd 229 and older (CentOS/RHEL 7's 219, Ubuntu 16.04's 229), a
8
+ `--requires-mounts-for` path holding `%`, `"` or `\` is written into `RequiresMountsFor=` in a form those
9
+ versions read as a different path: they keep 1.64's `%%` and its backslash escapes as they are. The unit then
10
+ does not wait for that mount. 1.63 wrote such a path unchanged, which those versions read correctly. Paths
11
+ with spaces work there too.
12
+ - Why: those versions neither expand `%` specifiers nor unescape in `RequiresMountsFor=` (systemd 219's
13
+ `config_parse_unit_requires_mounts_for` splits on whitespace and quotes, nothing more); newer ones (239 and
14
+ later) do both, and 1.64 writes for them. Writing per systemd version would mean detecting the version, for
15
+ an end-of-life systemd and a mount path that holds one of these three characters.
16
+ - Revisit when: someone runs firewatcher on such a systemd with such a mount path.
17
+ - Approved: 2026-11-01, the user chose "Known limitation (Recommended)".
18
+
19
+ ### While the events receiver is down, each alert waits one timeout before ntfy
20
+ - Kind: known limitation
21
+ - What the operator sees: with `events_url` set and its receiver not answering (the host down, its packets
22
+ dropped), each alert (only `always_notify` captures fall back to ntfy) is pushed one `ntfy_timeout` late (10 s by default; twice that for a capture that
23
+ overflows), because firewatcher tries the POST first and pushes to ntfy only when it fails. No alert is lost.
24
+ - Why: the POST and the push run one after the other. A separate short timeout, or skipping the POST for a while
25
+ after a failure, would shorten the wait at the cost of a second setting or of state; a few seconds' delay while
26
+ the receiver is down was judged acceptable.
27
+ - Revisit when: the delay matters in practice (a burst of alerts while the receiver is down).
28
+ - Approved: 2026-11-01, the user chose "Known limitation".
29
+
30
+ ### A URL whose password starts with digits and a `/` shows those digits as the port
31
+ - Kind: known limitation
32
+ - What the operator sees: in a URL such as `http://u:2024/<rest>@h/e` (a `user:password` whose password starts
33
+ with digits followed by `/`), the text up to the `/` is a valid host and port (`u`, port 2024), so firewatcher
34
+ accepts it and its log lines show `http://u:2024`: the leading digits of the password appear as the port, and the
35
+ request goes to host `u`. The same holds for a password that starts with `/`, `?` or `#` (`http://usr:/…@h/e`
36
+ goes to host `usr`). Because such a URL reads as a host and port, firewatcher gives it no user:password warning.
37
+ - Why: such a URL is valid as written; refusing it would mean refusing an `@` in a URL's path, which valid LLM URLs
38
+ use. Credentials in a URL are never sent anyway (README: use `events_token`, `token` or `api_key`).
39
+ - Revisit when: a way to tell such a URL from a real host and path appears, or someone hits it.
40
+ - Approved: 2026-11-01, the user ticked "fw: digits shown as port". The no-warning sentence added 2026-11-04, the user: "Add it to the wording".
41
+
42
+ ### A purge for free space syncs every filesystem, so a hung NFS share can stall reading
43
+ - Kind: deferred
44
+ - What the operator sees: right after firewatcher deletes old months to stay above `--min-free-percent`, it calls
45
+ `sync`, which writes every filesystem on the host. If some hard-mounted NFS share is not answering and holds unwritten
46
+ data, that `sync` waits until its server comes back, and firewatcher reads no log lines meanwhile. It happens only
47
+ after such a purge, on a host with such a share.
48
+ - Why: found during the 1.68 simplify pass (2026-11-14), after the 1.68 scope was set; present since 1.61.
49
+ - Revisit when: 1.69. Plan: sync only the filesystem the folder is on, with syncfs(2) through ctypes as hpcp's
50
+ `_syncfs` does, and skip the sync where syncfs is missing (a filesystem that then shows freed space late costs a move
51
+ to the fallback folder when one is set, or dropped writes for the rest of that capture when not, never the floor, as
52
+ today).
53
+
54
+ ### A failed `systemctl` step after the install's writes leaves the config and the unit, and a rerun puts the flags on ExecStart
55
+ - Kind: deferred
56
+ - What the operator sees: `--install-service` checks and renders everything before it writes, but `daemon-reload` and
57
+ `enable --now` run after the writes. When one of them fails, the install prints "systemctl ... failed (exit N)", returns
58
+ that code, and leaves `firewatcher.conf` (mode 0600) and the unit in place. The same command run again finds the config,
59
+ so it renders the command-line flags onto the unit's `ExecStart` instead of into the config. The ntfy URL, a secret like
60
+ a password, is then in the world-readable unit (the run prints a warning for it). A clean install keeps `ExecStart` to
61
+ `--config <path>`. 1.67 does the same.
62
+ - Why: found by the 1.68 final review (2026-11-15); the 1.68 change moved only the checks and the rendering before the
63
+ first write. Not worse than 1.67.
64
+ - Revisit when: 1.69. Plan: when `daemon-reload` or `enable --now` fails after this run created the config, remove the
65
+ config and the unit this run wrote (it created the config with `O_EXCL`, so it is sure the file is its own), so the
66
+ rerun is a clean install. A config that existed before the run stays, and so does a unit this run replaced rather than created.
67
+
68
+ ### The journal replay treats a whole second as context when the saved line is no longer in the journal
69
+ - Kind: deferred
70
+ - What the operator sees: at a restart, firewatcher reads the journal back from the saved position. When the journal holds
71
+ fewer lines of the saved second than the saved line number says (the journal file that held the start of that second
72
+ was rotated away while firewatcher was stopped), the saved line is never found. Every line that follows it in that
73
+ second is replayed as context only and never matched, so a line in it that matches a pattern opens no capture. The
74
+ next second's lines are matched as usual. The README says that when unsure, firewatcher reads a line again rather than
75
+ skip it; this case skips. Rare: it needs that second's lines split over a rotation. 1.67 does the same.
76
+ - Why: found by the 1.68 final review (2026-11-15). The replay ends at the saved line, found by its number in the second
77
+ and its digest; it has no rule for a line number that cannot be reached.
78
+ - Revisit when: 1.69. Plan: end the replay at the first line of the saved second whose digest matches when the count
79
+ cannot reach the saved number (a line read again is the safe mistake), and test it with a journal that lost the start of
80
+ the second.
81
+
82
+ ### On Python 3.6 under a C locale, a service given a non-ASCII path dies when it writes there
83
+ - Kind: deferred
84
+ - What the operator sees: firewatcher run by hand, or from a hand-written config, on Python 3.6 under a C locale with a
85
+ non-ASCII output folder, log file or note stops with `UnicodeEncodeError` at the first capture or at start. An install
86
+ no longer writes such a path from a C locale (1.68 refuses it, exit 2), but one installed under a UTF-8 locale still
87
+ stops when systemd starts the service under a C locale. Python 3.7 and later are not affected. 1.67 does the same.
88
+ - Why: Python 3.6 reads non-ASCII bytes under a C locale as undecodable text, which its file calls then cannot encode.
89
+ Found by the 1.68 final review (2026-11-15, F2).
90
+ - Revisit when: 1.69. Plan: give such values to the file calls as their bytes, as the local branch `superseded-local-1.61`
91
+ did with `_as_utf8` (kept as the tag `archive/superseded-local-1.61`), or stop and say to run under a UTF-8 locale.
92
+
93
+ ### A command-line `--tail-lines ''` reaches `tail -n ''`, which the config file's empty value does not
94
+ - Kind: deferred
95
+ - What the operator sees: `firewatcher --tail-lines '' ...` (also `--tail_lines ''`, and a unit that carries it) starts
96
+ `tail -n ''`, which exits with "invalid number of lines"; firewatcher then ends ("Processed 0 lines") and, under
97
+ systemd, restarts in a loop. Following the journal with no saved position fails the same way (`journalctl` answers "Failed to parse --lines=''"). An empty `tail_lines =` in the config file is ignored, as an unset value. 1.67 does the same.
98
+ - Why: found by the 1.68 final review (2026-11-15). The command-line value is used as given, while the config loader skips
99
+ an empty one.
100
+ - Revisit when: 1.69. Plan: treat an empty `--tail-lines` as unset in the argument parser, the way the config file does.
@@ -1,13 +1,12 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: firewatcher
3
- Version: 1.67
3
+ Version: 1.68
4
4
  Summary: Watch logs for incident patterns and persist surrounding context off-box
5
5
  Home-page: https://github.com/yufei-pan/firewatcher
6
6
  Author: Yufei Pan
7
7
  Author-email: pan@zopyr.us
8
- License: GPLv3+
8
+ License-Expression: GPL-3.0-or-later
9
9
  Classifier: Programming Language :: Python :: 3
10
- Classifier: License :: OSI Approved :: GNU General Public License v3 or later (GPLv3+)
11
10
  Classifier: Operating System :: POSIX :: Linux
12
11
  Classifier: Topic :: System :: Logging
13
12
  Classifier: Topic :: System :: Monitoring
@@ -20,8 +19,8 @@ Dynamic: classifier
20
19
  Dynamic: description
21
20
  Dynamic: description-content-type
22
21
  Dynamic: home-page
23
- Dynamic: license
24
22
  Dynamic: license-file
23
+ Dynamic: license-expression
25
24
  Dynamic: requires-python
26
25
  Dynamic: summary
27
26
 
@@ -89,13 +88,13 @@ When firewatcher follows the journal (not a log file), it saves how far it has r
89
88
 
90
89
  To tell where it stopped, firewatcher reads the journal with `journalctl -o short-iso`, so journal lines in captures carry the year and time zone: `2026-10-23T17:52:41+00:00 host sshd[812]: …` instead of `Oct 23 17:52:41 host sshd[812]: …`. Lines logged while firewatcher was stopped arrive all at once. A capture opened by one of them takes its context from the `--capture-time` before that line by the time each line was logged, and holds the lines after it as they are read, up to `--capture-line-count-max`.
91
90
 
92
- The position is the second of the last line read, which line of that second it was, and a digest of that line. When unsure, firewatcher reads a line again rather than skip it. A run that started from `--tail-lines` in the middle of a second numbers that second's lines from where it started, so identical lines logged in that second can be captured again after a restart. A save that fails is logged once, and a restart then reads again from the last position saved. If the clock is set back after a position is saved, for example at a boot with a wrong hardware clock, new lines stamped before that second count as already read. A position more than a minute in the future is ignored.
91
+ The position is the second of the last line read, its place in that second, and a digest of it. When unsure, firewatcher reads a line again rather than skip it, so identical lines logged in one second can be captured again after a restart. A failed save is logged once, and a restart then reads again from the last position saved. If the clock is set back after a save (a boot with a wrong hardware clock), the lines after the saved line are still matched, even when they are stamped before the saved second; a position more than a minute in the future is ignored.
93
92
 
94
93
  Only one firewatcher uses a position file at a time: another one started with the same file, such as a test run in a terminal with the default settings, reads the last `--tail-lines` lines and saves nothing. An empty `--position-file` turns resuming off, and so does a journalctl that does not accept `-o short-iso` and `--since=@`, which firewatcher checks at start.
95
94
 
96
95
  ### Disk and memory limits
97
96
 
98
- firewatcher keeps the filesystems it writes captures to above `--min-free-percent` free (default 1%, counted as `df` does, so the root-reserved blocks are left alone). Only what the filesystem reports authorizes a write. firewatcher checks when a capture opens, about once a second, and again before what it has written since the last check could bring it within 64 KiB of the floor (and at least every 8 MiB), fsyncing first so the filesystem, an NFS server included, counts every byte. A line that would cross that margin is not written there. Another program filling the same disk between two checks can still push it past the floor; firewatcher's own writes do not.
97
+ firewatcher keeps the filesystems it writes captures to above `--min-free-percent` free (default 1%, counted as `df` does, so the root-reserved blocks are left alone). It asks the filesystem when a capture opens, about once a second, and before its own writes could come within 64 KiB of the floor (at least every 8 MiB), fsyncing first so an NFS server counts every byte; a line that would cross that margin is not written there. firewatcher's own writes never take the disk past the floor; another program filling it between two checks can.
99
98
 
100
99
  Near the floor, firewatcher may delete its own oldest months in that folder, so a new incident can be recorded, under these rules:
101
100
 
@@ -106,9 +105,9 @@ Near the floor, firewatcher may delete its own oldest months in that folder, so
106
105
 
107
106
  After deleting, firewatcher syncs and reads the free space again. A filesystem that shows freed space late costs a move to the fallback folder, never the floor. If there is still no room, the capture moves to the fallback folder with a note, or, with no folder left, stops being written, which is logged; the incident is still pushed. Compression keeps to the floor too: a month whose archive could cross it is left uncompressed for now. Purging and compression never wait for each other, so log reading never waits for `tar`. `--delete-after-months 0` means nothing is deleted by age; the floor can still delete the oldest months. Set `--min-free-percent 0` to turn all of this off.
108
107
 
109
- Memory is bounded too. The `--capture-time` seconds before a match are kept in memory compressed (zlib, in blocks of about 64 KiB of text; with its bookkeeping, about 3 times smaller than the text for a busy host's varied lines, more for repetitive ones), within `--buffer-max-mb` (default 16 MiB). Past the limit the oldest block is dropped and the capture says so. The newest lines, up to 256 KiB of them before they are compressed, are always kept, so the buffer can go over the limit by about that much, or by one very long line. Compression costs well under a microsecond per line. A line longer than 1 MiB is read in pieces, and each piece is matched on its own, so a pattern split across the 1 MiB boundary is missed. The LLM excerpt reads at most `max_bytes` of a capture.
108
+ Memory is bounded too. The `--capture-time` seconds before a match are kept compressed (zlib, about 3 times smaller for a busy host's varied lines) within `--buffer-max-mb` (default 16 MiB); past it the oldest lines are dropped, and the capture says so. The newest lines, up to 256 KiB before they are compressed, are always kept, so the buffer can go over the limit by about that much. A line longer than 1 MiB is read and matched in pieces, so a pattern split across a 1 MiB boundary is missed.
110
109
 
111
- Monthly directories are compressed on a background thread, so log reading never waits for `tar`. Each month becomes `YYYY-MM.tar.xz` holding `YYYY-MM/…`. The directory is removed only after `tar` succeeds and the archive is synced to disk. An existing archive is never overwritten: the new one becomes `YYYY-MM.1.tar.xz`, and so on.
110
+ Monthly directories are compressed on a background thread, so log reading never waits for `tar`. Each month becomes `YYYY-MM.tar.xz` holding `YYYY-MM/…`. The directory is removed only after `tar` succeeds and the archive and its folder are synced to disk; if a sync fails, the month stays and is archived again later, nothing lost. An existing archive is never overwritten: the new one becomes `YYYY-MM.1.tar.xz`, and so on.
112
111
 
113
112
  ## systemd service
114
113
 
@@ -118,7 +117,7 @@ sudo firewatcher --print-unit
118
117
  sudo firewatcher --uninstall-service
119
118
  ```
120
119
 
121
- `--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**, writes `/etc/firewatcher/firewatcher.conf` **only if that file is missing**, then `systemctl daemon-reload && systemctl enable --now firewatcher`.
120
+ `--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**, writes `/etc/firewatcher/firewatcher.conf` **only if that file is missing**, then `systemctl daemon-reload && systemctl enable --now firewatcher`. It checks first, and writes nothing (exit 2) for a unit name systemd cannot load (letters, digits and `: _ . @ - \`, at most 255 characters with the `.service` suffix, any `@` between a name and an instance) or a path or value that is not UTF-8.
122
121
 
123
122
  `systemctl reload firewatcher` reloads the pattern files without a restart; see SIGHUP above.
124
123
 
@@ -214,7 +213,7 @@ always_notify =
214
213
 
215
214
  `patterns` and `always_notify` are one path per line, or comma-separated. Positional pattern arguments replace the `patterns` list.
216
215
 
217
- Out-of-range values stop `firewatcher` at startup: a negative time or count, `capture_time` over 7 days or `capture_time_max` over 30 days, `min_free_percent` outside 0–50, `purge_interval` or `resume_max` over 30 days, `buffer_max_mb` below 1, a timeout of 0 or less or over a day, an ntfy priority outside 1–5, or an LLM, ntfy or events URL that does not start with `http://` or `https://` or that contains spaces, or whose server part (after any `user:password@`) is not a host name with no `/`, `?`, `#`, `@`, `[`, `]`, `:` or `%` in it, or an IPv6 address in brackets, then an optional `:port` of up to 5 digits (0–65535); so a `user:password` holding a `/`, `?` or `#` is refused (`[` and `]` are fine there, since the `user:password` is stripped before the request). Also refused is a URL with a `user:password` that has another `@` later in its path, query or fragment (a password holding an `@` before a `/`, `?` or `#`). A password that starts with digits and a `/` still reads as a host and port, and those digits show as the port in logs ([limitations](https://github.com/yufei-pan/firewatcher/blob/master/docs/limitations.md#a-url-whose-password-starts-with-digits-and-a--shows-those-digits-as-the-port)).
216
+ Out-of-range values stop `firewatcher` at startup: a negative time or count, `capture_time` over 7 days or `capture_time_max` over 30 days, `min_free_percent` outside 0–50, `purge_interval` or `resume_max` over 30 days, `buffer_max_mb` outside 1–65536, a timeout of 0 or less or over a day, or an ntfy priority outside 1–5. So does an LLM, ntfy or events URL that is not `http://` or `https://`, has spaces, or whose server part is not a host name or a bracketed IPv6 address with an optional port (0–65535), as firewatcher reads it by its own strict rule. A `user:password` in a URL is never sent; one that would make the URL read two ways is refused, with [one exception](https://github.com/yufei-pan/firewatcher/blob/master/docs/limitations.md#a-url-whose-password-starts-with-digits-and-a--shows-those-digits-as-the-port).
218
217
 
219
218
  `api_key` under `[llm]` and `token` under `[notify]` are not command-line flags. `FIREWATCHER_LLM_API_KEY` and `FIREWATCHER_NTFY_TOKEN` override them when set. `events_token` under `[notify]` is likewise config-only, overridden by `FIREWATCHER_EVENTS_TOKEN`. `--install-service` creates `/etc/firewatcher/firewatcher.conf` with mode `0600` only when it is missing, and the unit runs `firewatcher --config` that path. An existing file is left as it is. Flags passed to a later install are appended on `ExecStart` so they override the file.
220
219
 
@@ -237,7 +236,7 @@ A capture that fits in `max_bytes` (default 48000) is sent whole. A bigger one i
237
236
 
238
237
  Any user or program on the host can write log lines, and those lines reach the model. The request marks the matched line and the excerpt as untrusted data between `BEGIN`/`END` lines that carry a random token, and the system prompt tells the model never to follow instructions inside them. That makes it harder for a log line to talk the model out of notifying, but cannot rule it out. For incidents that must always reach you, list patterns under `[notify] always_notify` (or `--always-notify`): when a line that matched a watch pattern also matches one of them, the capture is pushed even if the model says not to notify. That push uses the generated title and the line that matched, followed by the model's summary, since log text can steer the summary as well. If no always_notify pattern loads, firewatcher logs an error and keeps capturing without it; `--always-notify ''` clears a list set in the config. Only the line that opened the capture and later lines that matched a watch pattern while it was open count. Other lines in the window do not, and neither do matches from an earlier capture that appear as context. The capture's color codes are removed before it is sent to the model.
239
238
 
240
- `[llm] notes` (or `--llm-notes TEXT`; `note` also works as the key; the flag wins over the file, and `--llm-notes ''` clears a note set in the config) is a short free-text note about this host, for example `loop/dm devices from pytest and /tmp/claude-*/scratchpad and OOMs in capped test containers are expected`. It is sent with every capture as a line `Operator notes about this host: ...` before the untrusted log data, outside the `BEGIN`/`END` block, and the system prompt tells the model that notes describe what is normal there. Any run of whitespace in a note, newlines included, becomes one space. Only you can set it, so unlike the log lines it is trusted text; keep it short, since it is sent with every capture. When the config exists, `--install-service --llm-notes ...` puts the note on the unit's `ExecStart` (as one `--llm-notes=...` word, with `%` and `$` doubled for systemd), like any flag given there: local users can read it with `systemctl cat`, and it overrides `notes` in the config until the unit is reinstalled. To keep it private and editable, set it in the config instead.
239
+ `[llm] notes` (or `--llm-notes TEXT`; `note` also works as the key, and `--llm-notes ''` clears a note set in the config) is a short note about this host, for example `loop/dm devices from pytest and /tmp/claude-*/scratchpad and OOMs in capped test containers are expected`. It is sent with every capture as `Operator notes about this host: ...`, outside the untrusted `BEGIN`/`END` block, and the system prompt tells the model that notes describe what is normal there. Any run of whitespace in it, newlines included, becomes one space. Given to `--install-service` while the config exists, the note goes on the unit's `ExecStart`, like any flag given there: local users can read it, and it overrides the config until the unit is reinstalled. Set it in the config to keep it private.
241
240
 
242
241
  The ntfy topic URL is not printed at startup or in error messages, since on a public ntfy server whoever knows the topic can subscribe to it. Only the server is shown. Keep the topic in the config file (mode `0600`) rather than on the command line: `--ntfy-url` shows in the process list, and when the config already exists, `--install-service --ntfy-url` puts it on the unit's `ExecStart`, which any user can read. `--install-service` warns when that happens.
243
242
 
@@ -265,6 +264,17 @@ Captures are posted whatever `push` says, so the service sees them all. Any 2xx
265
264
  Lines firewatcher writes back to the journal are a single physical line containing `firewatcher-self`, so a summary that quotes `panic` or `I/O error` does not start another capture. In journalctl and syslog output, firewatcher recognizes its own lines by the identifier field after the timestamp and host (`firewatcher[PID]:`), not by text elsewhere in the line, so a process or user name chosen to look like firewatcher cannot hide a kernel or daemon message. Lines in other formats are checked for `firewatcher-self` or `firewatcher[PID]:` anywhere. The capture files themselves stay in the log stream's original format.
266
265
 
267
266
 
267
+ ## Upgrading to 1.68 from 1.67
268
+
269
+ Nothing to change. What is different:
270
+
271
+ - `--install-service` refuses a unit name systemd cannot load, and a path or value that is not UTF-8, before it writes anything (exit 2). 1.67 could write the config first and then stop with a traceback, or install a unit under a name systemd skips. A blank `--unit-name` now means `firewatcher`, as an empty one did.
272
+ - `systemctl enable --now` and `disable --now` get `--` before the unit name, so a name starting with `-` works.
273
+ - On Python 3.6 under a C locale, a non-ASCII path or note given on the command line reads as undecodable bytes, and a service started under that locale could not encode it, so `--install-service` refuses it (exit 2, nothing written) and says to run under a UTF-8 locale (one that `locale -a` lists, such as `en_US.UTF-8`; CentOS 7 has no `C.UTF-8`). 1.67 stopped there with a `UnicodeEncodeError`. Under a UTF-8 locale, and on Python 3.7 and later, such a path installs as before.
274
+ - The package declares its license as the SPDX expression `GPL-3.0-or-later` when built with setuptools 77 or later.
275
+ - `--uninstall-service --unit-name` with a path (`a/b`) now prints a message and exits 2; 1.67 stopped with a traceback. It still takes any other name an older firewatcher may have installed.
276
+ - Dead code and duplicated rules are gone (`firewatcher.py` went from 3,227 to 3,084 lines before the install checks were added); nothing else an operator sees changed.
277
+
268
278
  ## Development
269
279
 
270
280
  ```bash