firewatcher 1.68__tar.gz → 1.69__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.68/firewatcher.egg-info → firewatcher-1.69}/PKG-INFO +18 -7
  2. {firewatcher-1.68 → firewatcher-1.69}/README.md +17 -6
  3. {firewatcher-1.68 → firewatcher-1.69}/docs/lessons-full.md +25 -0
  4. {firewatcher-1.68 → firewatcher-1.69}/docs/lessons.md +5 -1
  5. firewatcher-1.69/docs/limitations.md +80 -0
  6. {firewatcher-1.68 → firewatcher-1.69/firewatcher.egg-info}/PKG-INFO +18 -7
  7. {firewatcher-1.68 → firewatcher-1.69}/firewatcher.egg-info/SOURCES.txt +1 -0
  8. {firewatcher-1.68 → firewatcher-1.69}/firewatcher.py +257 -51
  9. {firewatcher-1.68 → firewatcher-1.69}/tests/conftest.py +14 -0
  10. {firewatcher-1.68 → firewatcher-1.69}/tests/test_capture.py +47 -4
  11. {firewatcher-1.68 → firewatcher-1.69}/tests/test_cli.py +9 -1
  12. firewatcher-1.69/tests/test_locale.py +187 -0
  13. {firewatcher-1.68 → firewatcher-1.69}/tests/test_log_source.py +16 -0
  14. {firewatcher-1.68 → firewatcher-1.69}/tests/test_notify.py +29 -0
  15. {firewatcher-1.68 → firewatcher-1.69}/tests/test_patterns.py +11 -0
  16. {firewatcher-1.68 → firewatcher-1.69}/tests/test_position.py +323 -46
  17. {firewatcher-1.68 → firewatcher-1.69}/tests/test_systemd.py +265 -44
  18. firewatcher-1.68/docs/limitations.md +0 -100
  19. {firewatcher-1.68 → firewatcher-1.69}/LICENSE +0 -0
  20. {firewatcher-1.68 → firewatcher-1.69}/MANIFEST.in +0 -0
  21. {firewatcher-1.68 → firewatcher-1.69}/examples/firewatcher.conf +0 -0
  22. {firewatcher-1.68 → firewatcher-1.69}/examples/nvme_failure.regex +0 -0
  23. {firewatcher-1.68 → firewatcher-1.69}/examples/sys_msg.txt +0 -0
  24. {firewatcher-1.68 → firewatcher-1.69}/firewatcher.egg-info/dependency_links.txt +0 -0
  25. {firewatcher-1.68 → firewatcher-1.69}/firewatcher.egg-info/entry_points.txt +0 -0
  26. {firewatcher-1.68 → firewatcher-1.69}/firewatcher.egg-info/top_level.txt +0 -0
  27. {firewatcher-1.68 → firewatcher-1.69}/setup.cfg +0 -0
  28. {firewatcher-1.68 → firewatcher-1.69}/setup.py +0 -0
  29. {firewatcher-1.68 → firewatcher-1.69}/tests/test_compressor.py +0 -0
  30. {firewatcher-1.68 → firewatcher-1.69}/tests/test_config.py +0 -0
  31. {firewatcher-1.68 → firewatcher-1.69}/tests/test_events.py +0 -0
  32. {firewatcher-1.68 → firewatcher-1.69}/tests/test_matching.py +0 -0
  33. {firewatcher-1.68 → firewatcher-1.69}/tests/test_redirects.py +0 -0
  34. {firewatcher-1.68 → firewatcher-1.69}/tests/test_slugify.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: firewatcher
3
- Version: 1.68
3
+ Version: 1.69
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
@@ -57,7 +57,7 @@ A directory argument loads every non-hidden pattern file inside it. Files ending
57
57
 
58
58
  `firewatcher` exits with an error when no pattern loads, for example when a pattern path is mistyped or every regex is invalid, instead of running while matching nothing.
59
59
 
60
- `--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 the pattern files from a clone, or let `--install-service` write them.
60
+ `--install-service` seeds `/etc/firewatcher/patterns.d` with example patterns when it holds no pattern file. The `examples/` directory in the source tree is not installed onto `PATH` by `pip install`; copy the pattern files from a clone, or let `--install-service` write them.
61
61
 
62
62
  On a match, `firewatcher` writes:
63
63
 
@@ -88,7 +88,7 @@ When firewatcher follows the journal (not a log file), it saves how far it has r
88
88
 
89
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`.
90
90
 
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.
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: identical lines logged in one second, and lines that journald stored in another order than the one they show, can be captured again after a restart, and when the journal no longer holds the saved line (its file was rotated away while firewatcher was stopped, or a crash or reboot lost it), every line from `--capture-time` before it is matched, and no further back than `--resume-max`. One case can skip lines: if the journal lost the saved line, or lines before it in its second, and holds a later one of that second with the same text, the replay can end there and the lines between are not matched ([limitations](https://github.com/yufei-pan/firewatcher/blob/master/docs/limitations.md#a-restart-after-the-journal-lost-the-saved-line-can-skip-lines-that-follow-it)). 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 by up to a minute (a boot with a wrong hardware clock) and the journal still holds the saved line, the lines after it are still matched, even when they are stamped before the saved second. A position more than a minute ahead of the clock is ignored, and the last `--tail-lines` lines are read.
92
92
 
93
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.
94
94
 
@@ -103,7 +103,7 @@ Near the floor, firewatcher may delete its own oldest months in that folder, so
103
103
  - **How much:** only as many months as it takes, counted by their size on disk, and nothing at all if deleting every one of them still could not make room. That happens when something else filled the disk, and then the history is kept.
104
104
  - **How often:** at most once per `--purge-interval` per folder (default an hour), so a disk that something else keeps filling drains firewatcher's history slowly. A purge that could not help is not tried again for five minutes (or the interval, if shorter). Each deletion is logged.
105
105
 
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.
106
+ After deleting, firewatcher syncs that filesystem alone (syncfs; none on macOS, where APFS shows freed space at once) 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.
107
107
 
108
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.
109
109
 
@@ -117,7 +117,7 @@ sudo firewatcher --print-unit
117
117
  sudo firewatcher --uninstall-service
118
118
  ```
119
119
 
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.
120
+ `--install-service` writes `/etc/systemd/system/firewatcher.service`, creates the output directory, seeds `/etc/firewatcher/patterns.d/` with example patterns **only if it holds no pattern file**, 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 or a path or value that is not UTF-8. If writing the unit or a `systemctl` step fails (or `systemctl` cannot be run), it removes the config and the unit it created, puts back a unit it replaced as it was, and disables a unit it enabled, so the same command can run again. The output folder and the example patterns stay.
121
121
 
122
122
  `systemctl reload firewatcher` reloads the pattern files without a restart; see SIGHUP above.
123
123
 
@@ -264,16 +264,27 @@ Captures are posted whatever `push` says, so the service sees them all. Any 2xx
264
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.
265
265
 
266
266
 
267
+ ## Upgrading to 1.69 from 1.68
268
+
269
+ Nothing to change under a UTF-8 or C locale. What is different:
270
+
271
+ - After deleting old months to keep the free-space floor, firewatcher syncs only that filesystem (none on macOS), so a hard-mounted NFS share that is not answering, other than the one the captures are on, no longer stalls log reading. 1.68 synced every filesystem.
272
+ - When writing the unit, `daemon-reload` or `enable --now` fails, `--install-service` removes the config and the unit it created, puts back a unit it replaced as it was, and disables a unit it enabled, so the same command can run again. 1.68 left them, and the rerun put the command-line flags, the ntfy URL among them, on the unit's `ExecStart`. A config that does not fit on the disk is the same kind of failure; 1.68 wrote part of it and went on.
273
+ - At a restart, firewatcher first finds the saved line in the journal as it is now. When the journal lost the start of that second, the lines after the saved one are still matched; when it lost the line itself, every line from `--capture-time` before it is matched (no further back than `--resume-max`). 1.68 replayed them as context only, and with the clock set back by up to a minute, every line stamped before the saved second.
274
+ - `--tail-lines ''` is as if the flag were not given (the config's `tail_lines`, else 20), as an empty `tail_lines` in the config is. 1.68 passed it on, and `tail` or `journalctl` exited at once.
275
+ - Under a locale that is neither UTF-8 nor C (such as `en_US.ISO-8859-1`), a non-ASCII path in the config now names the file by its UTF-8 bytes, and a pattern file is read as UTF-8, where 1.68 used the locale's encoding for both: rename such a folder or file to its UTF-8 name, and save a pattern file as UTF-8 (one that is not is skipped, with a message). `--install-service` refuses a path or note typed there in the locale's own encoding (exit 2); 1.68 wrote it.
276
+ - On Python 3.6 under a C locale, non-ASCII paths (from the config, the command line or the unit), matched log lines and pattern files no longer stop firewatcher with `UnicodeEncodeError` or go unread, and `--install-service` writes a non-ASCII path or note given there as UTF-8, where 1.68 refused it. `--print-unit` writes the unit as UTF-8 in every locale (1.68 stopped on a non-ASCII `--requires-mounts-for` path) and refuses a value that is not UTF-8 (exit 2), which 1.68 printed or stopped on. On any Python, a path that is not UTF-8 no longer stops it at the first capture.
277
+
267
278
  ## Upgrading to 1.68 from 1.67
268
279
 
269
280
  Nothing to change. What is different:
270
281
 
271
282
  - `--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
283
  - `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.
284
+ - On Python 3.6 under a C locale, `--install-service` refuses a non-ASCII path or note given on the command line (exit 2, nothing written) and says to run under a UTF-8 locale; 1.67 stopped there with `UnicodeEncodeError`. 1.69 installs it.
274
285
  - The package declares its license as the SPDX expression `GPL-3.0-or-later` when built with setuptools 77 or later.
275
286
  - `--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.
287
+ - Dead code and duplicated rules are gone; nothing else an operator sees changed.
277
288
 
278
289
  ## Development
279
290
 
@@ -31,7 +31,7 @@ A directory argument loads every non-hidden pattern file inside it. Files ending
31
31
 
32
32
  `firewatcher` exits with an error when no pattern loads, for example when a pattern path is mistyped or every regex is invalid, instead of running while matching nothing.
33
33
 
34
- `--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 the pattern files from a clone, or let `--install-service` write them.
34
+ `--install-service` seeds `/etc/firewatcher/patterns.d` with example patterns when it holds no pattern file. The `examples/` directory in the source tree is not installed onto `PATH` by `pip install`; copy the pattern files from a clone, or let `--install-service` write them.
35
35
 
36
36
  On a match, `firewatcher` writes:
37
37
 
@@ -62,7 +62,7 @@ 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, 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.
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: identical lines logged in one second, and lines that journald stored in another order than the one they show, can be captured again after a restart, and when the journal no longer holds the saved line (its file was rotated away while firewatcher was stopped, or a crash or reboot lost it), every line from `--capture-time` before it is matched, and no further back than `--resume-max`. One case can skip lines: if the journal lost the saved line, or lines before it in its second, and holds a later one of that second with the same text, the replay can end there and the lines between are not matched ([limitations](https://github.com/yufei-pan/firewatcher/blob/master/docs/limitations.md#a-restart-after-the-journal-lost-the-saved-line-can-skip-lines-that-follow-it)). 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 by up to a minute (a boot with a wrong hardware clock) and the journal still holds the saved line, the lines after it are still matched, even when they are stamped before the saved second. A position more than a minute ahead of the clock is ignored, and the last `--tail-lines` lines are read.
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
 
@@ -77,7 +77,7 @@ Near the floor, firewatcher may delete its own oldest months in that folder, so
77
77
  - **How much:** only as many months as it takes, counted by their size on disk, and nothing at all if deleting every one of them still could not make room. That happens when something else filled the disk, and then the history is kept.
78
78
  - **How often:** at most once per `--purge-interval` per folder (default an hour), so a disk that something else keeps filling drains firewatcher's history slowly. A purge that could not help is not tried again for five minutes (or the interval, if shorter). Each deletion is logged.
79
79
 
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.
80
+ After deleting, firewatcher syncs that filesystem alone (syncfs; none on macOS, where APFS shows freed space at once) 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
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
 
@@ -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`. 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.
94
+ `--install-service` writes `/etc/systemd/system/firewatcher.service`, creates the output directory, seeds `/etc/firewatcher/patterns.d/` with example patterns **only if it holds no pattern file**, 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 or a path or value that is not UTF-8. If writing the unit or a `systemctl` step fails (or `systemctl` cannot be run), it removes the config and the unit it created, puts back a unit it replaced as it was, and disables a unit it enabled, so the same command can run again. The output folder and the example patterns stay.
95
95
 
96
96
  `systemctl reload firewatcher` reloads the pattern files without a restart; see SIGHUP above.
97
97
 
@@ -238,16 +238,27 @@ 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.69 from 1.68
242
+
243
+ Nothing to change under a UTF-8 or C locale. What is different:
244
+
245
+ - After deleting old months to keep the free-space floor, firewatcher syncs only that filesystem (none on macOS), so a hard-mounted NFS share that is not answering, other than the one the captures are on, no longer stalls log reading. 1.68 synced every filesystem.
246
+ - When writing the unit, `daemon-reload` or `enable --now` fails, `--install-service` removes the config and the unit it created, puts back a unit it replaced as it was, and disables a unit it enabled, so the same command can run again. 1.68 left them, and the rerun put the command-line flags, the ntfy URL among them, on the unit's `ExecStart`. A config that does not fit on the disk is the same kind of failure; 1.68 wrote part of it and went on.
247
+ - At a restart, firewatcher first finds the saved line in the journal as it is now. When the journal lost the start of that second, the lines after the saved one are still matched; when it lost the line itself, every line from `--capture-time` before it is matched (no further back than `--resume-max`). 1.68 replayed them as context only, and with the clock set back by up to a minute, every line stamped before the saved second.
248
+ - `--tail-lines ''` is as if the flag were not given (the config's `tail_lines`, else 20), as an empty `tail_lines` in the config is. 1.68 passed it on, and `tail` or `journalctl` exited at once.
249
+ - Under a locale that is neither UTF-8 nor C (such as `en_US.ISO-8859-1`), a non-ASCII path in the config now names the file by its UTF-8 bytes, and a pattern file is read as UTF-8, where 1.68 used the locale's encoding for both: rename such a folder or file to its UTF-8 name, and save a pattern file as UTF-8 (one that is not is skipped, with a message). `--install-service` refuses a path or note typed there in the locale's own encoding (exit 2); 1.68 wrote it.
250
+ - On Python 3.6 under a C locale, non-ASCII paths (from the config, the command line or the unit), matched log lines and pattern files no longer stop firewatcher with `UnicodeEncodeError` or go unread, and `--install-service` writes a non-ASCII path or note given there as UTF-8, where 1.68 refused it. `--print-unit` writes the unit as UTF-8 in every locale (1.68 stopped on a non-ASCII `--requires-mounts-for` path) and refuses a value that is not UTF-8 (exit 2), which 1.68 printed or stopped on. On any Python, a path that is not UTF-8 no longer stops it at the first capture.
251
+
241
252
  ## Upgrading to 1.68 from 1.67
242
253
 
243
254
  Nothing to change. What is different:
244
255
 
245
256
  - `--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
257
  - `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.
258
+ - On Python 3.6 under a C locale, `--install-service` refuses a non-ASCII path or note given on the command line (exit 2, nothing written) and says to run under a UTF-8 locale; 1.67 stopped there with `UnicodeEncodeError`. 1.69 installs it.
248
259
  - The package declares its license as the SPDX expression `GPL-3.0-or-later` when built with setuptools 77 or later.
249
260
  - `--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.
261
+ - Dead code and duplicated rules are gone; nothing else an operator sees changed.
251
262
 
252
263
  ## Development
253
264
 
@@ -41,3 +41,28 @@ entries go last, in the same commit as the change:
41
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
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
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.
44
+
45
+ ## 2026-11-23 firewatcher 1.69: the service reads UTF-8 paths in any locale, so the install no longer refuses a non-ASCII one
46
+ - Changed: on Python 3.6 under a C locale, `--install-service` writes a non-ASCII path or note given on the command line (which Python hands over as escaped bytes) into the config or unit as the UTF-8 text its bytes spell; 1.68 refused it with exit 2. Bytes that are not UTF-8 are still refused. The service in turn takes each path from the config as the string Python's file calls take for its UTF-8 bytes, logs and sends escaped bytes as UTF-8 text, writes paths into captures and `journal.log` as their own bytes, prints what stdout cannot encode with backslash escapes, and reads pattern files as UTF-8 in every locale.
47
+ - Why we had to change: 1.68's refusal stopped one writer, an install from a C locale, but the service still died with `UnicodeEncodeError` on a config written under a UTF-8 locale and started under a C one, on a hand-written config, on a path given by hand, and on any matched log line that was not ASCII.
48
+ - Original design was wrong because: it refused the value where it was written because one reader, the service under that locale, could not use it, instead of fixing that reader. The refusal covered one path into the reader and left the others.
49
+ - Lesson: when a value is refused only because a later reader cannot handle it, fix the reader and drop the refusal: the refusal closes one way in and leaves every other way the value reaches that reader failing. A value that is not UTF-8 is still refused.
50
+
51
+ ## 2026-11-23 firewatcher 1.69: the replay finds the saved line in the journal as it is now
52
+ - Changed: before resuming, firewatcher reads the saved second of the journal once. The replay ends at the saved line by its number in that second when the journal still has it there, else, while the journal holds a line with its digest after that number, at that line, as in 1.68; else at the first line of that second with its digest; with no such line nothing is replayed and every line from `--capture-time` before it (no further back than `--resume-max`) is matched. 1.68 needed the number and the digest together, counted from the first line of that second it was shown, so a lost start of the second never reached the number.
53
+ - Why we had to change: when the journal lost the start of the saved second while firewatcher was stopped (a journal file rotated away), the number was never reached and the rest of that second was context only, never matched. When it lost the line itself and the clock came back behind it by up to a minute (a reboot with a volatile journal and a wrong hardware clock; beyond a minute the position is ignored and the last lines are read), every line stamped before the saved second was context, until the clock passed it.
54
+ - Original design was wrong because: it took a position counted from the start of a group (the lines of one second) as stable, in a log another program rotates while firewatcher is stopped, and its only way out of the replay was a later timestamp.
55
+ - Lesson: a position counted within a log that another program trims is checked against the log as it is now before it is trusted; when it cannot be found, read again rather than skip.
56
+
57
+ ## 2026-11-23 firewatcher 1.69: the saved second ends at a distance from it, not at the first line of another second
58
+ - Changed: reading the saved second of the journal (`locate`), firewatcher collects the lines shown as that second and stops at the first line shown more than `JOURNAL_STAMP_SKEW` (30) seconds after it. A line shown before it, however far, is passed over, because a stall of journald stores the lines that waited for it among the lines of the second: an earlier version of this rule stopped at any far line, and on the real journal's stalls 312 of 7,597 saved lines then ended the read before the saved line, the note said the journal no longer held it, and the whole window was matched again where 1.68 resumed exactly. 1.69 as built stopped at the first line of any other second. The replay itself (`replay_time`) still ends at the first line shown later than the saved second, as in 1.68: a line stored before the saved one and shown a second later ends it early, and lines read before the stop match again (a second capture, never a skip). Its stop rule is the 1.70 plan of the deferral in `limitations.md`, designed with the numbering that entry plans.
59
+ - Why we had to change: journalctl shows a line with the time it was sent but seeks and orders by the time journald stored it, a little later. So `--since=@S` can start with a line shown as the second before, and a line shown as S can follow one shown as S+1. Reading stopped at the first of them, the saved line was not found, and an ordinary restart matched the whole `--capture-time` again (a second capture and push of the last incident). On the journal of the host it was built on, 90 of 187,902 seconds that held lines were read that way, and 1,303 of 1,819 lines in them would have matched the whole window again. In 34.7 days of that journal 4.5 million entries carry a sent time: 99.995% were stored within a second of it, the largest gap outside two stalls of the host (370 and 458 s) was 15.7 s, and 30 covers that about twice.
60
+ - Original design was wrong because: it read the time a line shows as the order the lines come in, which is the stored time. The tests' fake journalctl sought by the time a line shows, so it could not tell the two apart.
61
+ - Lesson: a reader that stops on a timestamp it reads from the lines must know which time the program that orders the lines uses; stop on a distance from it on the later side only (a stall stores lines shown far earlier among the ones you want), and test against a source that keeps the two apart and against the real journal's stalls. Apply it to every reader of the same lines: the replay still stops at the first later line (1.70).
62
+
63
+ ## 2026-11-23 firewatcher 1.69: a failed install undoes what it did, in the order the tools need
64
+ - Changed: when a step of `--install-service` fails after the writes, it disables the unit if this run enabled it (it asks `systemctl is-enabled` before `enable --now`), then removes the config and the unit it created, puts back the old text of a unit it replaced, and reloads systemd. A `systemctl` that cannot be run, a file that cannot be removed and a config that does not fit on the disk are the same kind of failure, with a message. The config is written to its end or removed: 1.68 and 1.69 as built took a short write as done.
65
+ - Why we had to change: removing only what was created left a replaced unit pointing at the config that was removed (a restart loop on `config file not found`); `disable` came after the unit file was removed, which systemd 219 refuses (the wants link stayed); a unit this run replaced and its failed `enable --now` had enabled stayed enabled (the disable ran only for a unit the run created), and a disable after every failure would have disabled a unit that was enabled before the install; and systemd kept the removed unit's new text loaded until the next reload.
66
+ - Original design was wrong because: it undid the files, not the steps, and took a unit the install overwrote for something it had not touched.
67
+ - Lesson: an install that can fail part-way records what each step changes before it runs it (the old text, whether the unit was enabled), and undoes only that, in the order the program that reads the files needs.
68
+
@@ -5,10 +5,14 @@ agreed behaviour here. For the full story of a line, find the entry with the sam
5
5
  `lessons-full.md`.
6
6
 
7
7
  When one has to change, add the full entry to `lessons-full.md` and one line here, newest last, in the
8
- same commit as the change. Keep this file under 20 KB: at the cap, merge lines before adding.
8
+ same commit as the change. Never merge lines to save space; before this file passes 80 KB (what one Claude Code read returns, measured 2026-11-15), ask the user.
9
9
 
10
10
  - **2026-10-27 firewatcher: the model's excerpt is built from where the events are, not from the file's ends**: when a record must be cut to a budget, record where its important parts are while writing it, cut around those, and keep the end where outcomes show. A budget split must never shrink a piece when the budget grows (a superseded attempt that did kept producing new edge cases).
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
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.
15
+ - **2026-11-23 firewatcher 1.69: the service reads UTF-8 paths in any locale, so the install no longer refuses a non-ASCII one**: when a value is refused only because a later reader cannot handle it, fix the reader and drop the refusal: the refusal closes one way in and leaves every other way the value reaches that reader failing. A value that is not UTF-8 is still refused.
16
+ - **2026-11-23 firewatcher 1.69: the replay finds the saved line in the journal as it is now**: a position counted within a log that another program trims is checked against the log as it is now before it is trusted; when it cannot be found, read again rather than skip.
17
+ - **2026-11-23 firewatcher 1.69: the saved second ends at a distance from it, not at the first line of another second**: a reader that stops on a timestamp it reads from the lines must know which time the program that orders the lines uses; stop on a distance from it on the later side only (a stall stores lines shown far earlier among the ones you want), and test against a source that keeps the two apart and against the real journal's stalls. Apply it to every reader of the same lines: the replay still stops at the first later line (1.70).
18
+ - **2026-11-23 firewatcher 1.69: a failed install undoes what it did, in the order the tools need**: an install that can fail part-way records what each step changes before it runs it (the old text, whether the unit was enabled), and undoes only that, in the order the program that reads the files needs.
@@ -0,0 +1,80 @@
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 restart after the journal lost the saved line can skip lines that follow it
43
+ - Kind: deferred
44
+ - What the operator sees: when the journal lost the saved line, or lines before it in its second (a rotated file, a crash or a reboot), but still holds a later line of that second with the same text, the replay can end at that twin. The lines between the lost line and the twin were not read before the stop, and on the restart they are read as context only, not matched. 1.68 did the same. A message logged several times in one second is the usual twin.
45
+ - Also the replay's own stop: it ends at the first line shown later than the saved second, as in 1.68 (the 30 s distance rule collects the saved second for `locate` only). journalctl orders lines by the time journald stored them, so a line stored before the saved one and shown a second later ends the replay there, and the lines stored from it up to the saved one, read before the stop, match again: a second capture and push of an incident, never a skip.
46
+ - Where `locate` cannot tell which of identical lines is the saved one it takes the first, so 1.69 reads a line again where 1.68 was exact, in two rare views: the journal lost the start of the saved second, holds an identical line before the saved one and nothing of that second after it (1.69 reads the lines after that earlier line again, 1.68 resumed exactly; with a line after the saved one 1.68 skipped it, and 1.69 reads it as new); and a line shown as the saved second but stored a second before it, with an identical line before the saved one (`locate` reads the second from its start and does not see that line, so the saved line is read again). 1.69 takes a duplicate over a skip, and the 1.70 design below settles all three.
47
+ - Why: the position holds the second of the saved line, its number in that second and a digest of its text, and a twin has the same digest and can have the same number. The replay stops on a time shown in the lines, which is not the order the lines come in.
48
+ - Plan (1.70), one change to `locate` and `replay_time` together, tested against a journalctl that orders lines by the time they were stored:
49
+ - Save the digest of the line before the saved one as well, number lines within a run of lines with the same stamp (as `saw()` does), and take a line as the saved one only where its number and the digest of its line before agree; otherwise treat the saved line as lost and read the window again. A burst of identical lines has identical lines before it, so the number tells them apart where the digest cannot.
50
+ - Where `locate` found the saved line, end the replay at that line (counted among all lines of its second, as `replay_time` counts) and not at the first line shown later, up to JOURNAL_STAMP_SKEW seconds past the saved second; where it could not tell, end as now, at the first line shown later (a later end there would skip lines).
51
+ - Design check first (1.70): weigh resuming by journal cursor before adding any of this saved state. journalctl 219 (CentOS 7) has `--after-cursor` and `--cursor`; a cursor for every line needs `-o json` or `-o export`, so firewatcher would format each line itself, which is a real cost. A cursor names the line itself, so the saved number and digest, and with them the twin, would go. Say why not if not.
52
+ - Revisit when: 1.70.
53
+
54
+ ### A restart where a line shown far later was stored first says the journal no longer holds the last line
55
+ - Kind: deferred
56
+ - What the operator sees: when journald stored a line shown more than 30 seconds (JOURNAL_STAMP_SKEW) after the saved second before one of that second's lines (a source whose clock runs ahead; none in 34.7 days of the journal this was measured on), `locate` stops reading there, may not reach the saved line, and the note says "The journal no longer holds the last line read", though it does. Every line from `--capture-time` before the saved second is matched again: a second capture and push of every incident in that window, never a skip. 1.68 ended its replay at that line, and read the lines from it again. A stall of journald does not do it: it stores lines shown far earlier (370 and 458 s on that journal) among the lines of the second, `locate` reads past them, and the restart resumes exactly, as in 1.68.
57
+ - Why: `_journal_second` returns only the lines it collected, so `locate` cannot tell a stop at a far later line from the end of the journal.
58
+ - Plan (1.70): `_journal_second` says that it stopped at a far line, and `locate` writes a note of its own ("stopped reading at a line N seconds after the saved second; matching every line from ..."). The cursor design of the entry above would take `locate` away.
59
+ - Revisit when: 1.70.
60
+
61
+ ### `--print-unit` does not run the install's checks of the unit name and the config text
62
+ - Kind: deferred
63
+ - What the operator sees: `--print-unit --unit-name 'a b'` prints a unit and exits 0, where `--install-service` refuses the name (exit 2); a config text the install would refuse (not UTF-8) is never rendered by `--print-unit`. It refuses a value that is not UTF-8 in the unit itself, as the install does. 1.68 did the same.
64
+ - Why: the install runs its checks in `install_service`; the print path calls `render_unit_file` only.
65
+ - Plan (1.70): one function runs the checks and renders the unit and the config text, and both commands call it.
66
+ - Revisit when: 1.70.
67
+
68
+ ### A dangling symlink at the unit path is written through, and its target is kept when the install fails
69
+ - Kind: deferred
70
+ - What the operator sees: with a dangling symlink at `/etc/systemd/system/firewatcher.service`, `--install-service` writes the unit at the link's target (the open follows the link), and a step that fails afterwards leaves that file, naming the config the clean-up removed. Older than 1.69.
71
+ - Why: the clean-up counts a path that exists as a link as a unit that was there before, and keeps nothing of it to put back.
72
+ - Plan (1.70): a path that is a link (`os.path.lexists`) but no file (`os.path.isfile`) counts as created, and a failure removes what the install wrote through it.
73
+ - Revisit when: 1.70.
74
+
75
+ ### A byte-order mark at the start of a pattern file stays in its first pattern
76
+ - Kind: deferred
77
+ - What the operator sees: a pattern file saved with a UTF-8 byte-order mark (some Windows editors do) has U+FEFF at the start of its first pattern, which then never matches, with no message. Older than 1.69.
78
+ - Why: pattern files are read as `utf-8`, which keeps the mark.
79
+ - Plan (1.70): read them as `utf-8-sig`.
80
+ - Revisit when: 1.70.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: firewatcher
3
- Version: 1.68
3
+ Version: 1.69
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
@@ -57,7 +57,7 @@ A directory argument loads every non-hidden pattern file inside it. Files ending
57
57
 
58
58
  `firewatcher` exits with an error when no pattern loads, for example when a pattern path is mistyped or every regex is invalid, instead of running while matching nothing.
59
59
 
60
- `--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 the pattern files from a clone, or let `--install-service` write them.
60
+ `--install-service` seeds `/etc/firewatcher/patterns.d` with example patterns when it holds no pattern file. The `examples/` directory in the source tree is not installed onto `PATH` by `pip install`; copy the pattern files from a clone, or let `--install-service` write them.
61
61
 
62
62
  On a match, `firewatcher` writes:
63
63
 
@@ -88,7 +88,7 @@ When firewatcher follows the journal (not a log file), it saves how far it has r
88
88
 
89
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`.
90
90
 
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.
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: identical lines logged in one second, and lines that journald stored in another order than the one they show, can be captured again after a restart, and when the journal no longer holds the saved line (its file was rotated away while firewatcher was stopped, or a crash or reboot lost it), every line from `--capture-time` before it is matched, and no further back than `--resume-max`. One case can skip lines: if the journal lost the saved line, or lines before it in its second, and holds a later one of that second with the same text, the replay can end there and the lines between are not matched ([limitations](https://github.com/yufei-pan/firewatcher/blob/master/docs/limitations.md#a-restart-after-the-journal-lost-the-saved-line-can-skip-lines-that-follow-it)). 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 by up to a minute (a boot with a wrong hardware clock) and the journal still holds the saved line, the lines after it are still matched, even when they are stamped before the saved second. A position more than a minute ahead of the clock is ignored, and the last `--tail-lines` lines are read.
92
92
 
93
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.
94
94
 
@@ -103,7 +103,7 @@ Near the floor, firewatcher may delete its own oldest months in that folder, so
103
103
  - **How much:** only as many months as it takes, counted by their size on disk, and nothing at all if deleting every one of them still could not make room. That happens when something else filled the disk, and then the history is kept.
104
104
  - **How often:** at most once per `--purge-interval` per folder (default an hour), so a disk that something else keeps filling drains firewatcher's history slowly. A purge that could not help is not tried again for five minutes (or the interval, if shorter). Each deletion is logged.
105
105
 
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.
106
+ After deleting, firewatcher syncs that filesystem alone (syncfs; none on macOS, where APFS shows freed space at once) 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.
107
107
 
108
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.
109
109
 
@@ -117,7 +117,7 @@ sudo firewatcher --print-unit
117
117
  sudo firewatcher --uninstall-service
118
118
  ```
119
119
 
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.
120
+ `--install-service` writes `/etc/systemd/system/firewatcher.service`, creates the output directory, seeds `/etc/firewatcher/patterns.d/` with example patterns **only if it holds no pattern file**, 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 or a path or value that is not UTF-8. If writing the unit or a `systemctl` step fails (or `systemctl` cannot be run), it removes the config and the unit it created, puts back a unit it replaced as it was, and disables a unit it enabled, so the same command can run again. The output folder and the example patterns stay.
121
121
 
122
122
  `systemctl reload firewatcher` reloads the pattern files without a restart; see SIGHUP above.
123
123
 
@@ -264,16 +264,27 @@ Captures are posted whatever `push` says, so the service sees them all. Any 2xx
264
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.
265
265
 
266
266
 
267
+ ## Upgrading to 1.69 from 1.68
268
+
269
+ Nothing to change under a UTF-8 or C locale. What is different:
270
+
271
+ - After deleting old months to keep the free-space floor, firewatcher syncs only that filesystem (none on macOS), so a hard-mounted NFS share that is not answering, other than the one the captures are on, no longer stalls log reading. 1.68 synced every filesystem.
272
+ - When writing the unit, `daemon-reload` or `enable --now` fails, `--install-service` removes the config and the unit it created, puts back a unit it replaced as it was, and disables a unit it enabled, so the same command can run again. 1.68 left them, and the rerun put the command-line flags, the ntfy URL among them, on the unit's `ExecStart`. A config that does not fit on the disk is the same kind of failure; 1.68 wrote part of it and went on.
273
+ - At a restart, firewatcher first finds the saved line in the journal as it is now. When the journal lost the start of that second, the lines after the saved one are still matched; when it lost the line itself, every line from `--capture-time` before it is matched (no further back than `--resume-max`). 1.68 replayed them as context only, and with the clock set back by up to a minute, every line stamped before the saved second.
274
+ - `--tail-lines ''` is as if the flag were not given (the config's `tail_lines`, else 20), as an empty `tail_lines` in the config is. 1.68 passed it on, and `tail` or `journalctl` exited at once.
275
+ - Under a locale that is neither UTF-8 nor C (such as `en_US.ISO-8859-1`), a non-ASCII path in the config now names the file by its UTF-8 bytes, and a pattern file is read as UTF-8, where 1.68 used the locale's encoding for both: rename such a folder or file to its UTF-8 name, and save a pattern file as UTF-8 (one that is not is skipped, with a message). `--install-service` refuses a path or note typed there in the locale's own encoding (exit 2); 1.68 wrote it.
276
+ - On Python 3.6 under a C locale, non-ASCII paths (from the config, the command line or the unit), matched log lines and pattern files no longer stop firewatcher with `UnicodeEncodeError` or go unread, and `--install-service` writes a non-ASCII path or note given there as UTF-8, where 1.68 refused it. `--print-unit` writes the unit as UTF-8 in every locale (1.68 stopped on a non-ASCII `--requires-mounts-for` path) and refuses a value that is not UTF-8 (exit 2), which 1.68 printed or stopped on. On any Python, a path that is not UTF-8 no longer stops it at the first capture.
277
+
267
278
  ## Upgrading to 1.68 from 1.67
268
279
 
269
280
  Nothing to change. What is different:
270
281
 
271
282
  - `--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
283
  - `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.
284
+ - On Python 3.6 under a C locale, `--install-service` refuses a non-ASCII path or note given on the command line (exit 2, nothing written) and says to run under a UTF-8 locale; 1.67 stopped there with `UnicodeEncodeError`. 1.69 installs it.
274
285
  - The package declares its license as the SPDX expression `GPL-3.0-or-later` when built with setuptools 77 or later.
275
286
  - `--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.
287
+ - Dead code and duplicated rules are gone; nothing else an operator sees changed.
277
288
 
278
289
  ## Development
279
290
 
@@ -20,6 +20,7 @@ tests/test_cli.py
20
20
  tests/test_compressor.py
21
21
  tests/test_config.py
22
22
  tests/test_events.py
23
+ tests/test_locale.py
23
24
  tests/test_log_source.py
24
25
  tests/test_matching.py
25
26
  tests/test_notify.py