firewatcher 1.64__tar.gz → 1.66__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 (30) hide show
  1. {firewatcher-1.64 → firewatcher-1.66}/MANIFEST.in +1 -0
  2. {firewatcher-1.64/firewatcher.egg-info → firewatcher-1.66}/PKG-INFO +30 -5
  3. {firewatcher-1.64 → firewatcher-1.66}/README.md +29 -4
  4. firewatcher-1.66/docs/limitations.md +40 -0
  5. {firewatcher-1.64 → firewatcher-1.66}/examples/firewatcher.conf +1 -1
  6. {firewatcher-1.64 → firewatcher-1.66/firewatcher.egg-info}/PKG-INFO +30 -5
  7. {firewatcher-1.64 → firewatcher-1.66}/firewatcher.egg-info/SOURCES.txt +3 -0
  8. {firewatcher-1.64 → firewatcher-1.66}/firewatcher.py +258 -40
  9. {firewatcher-1.64 → firewatcher-1.66}/tests/conftest.py +1 -0
  10. {firewatcher-1.64 → firewatcher-1.66}/tests/test_cli.py +1 -1
  11. {firewatcher-1.64 → firewatcher-1.66}/tests/test_config.py +17 -0
  12. firewatcher-1.66/tests/test_events.py +610 -0
  13. {firewatcher-1.64 → firewatcher-1.66}/tests/test_notify.py +19 -19
  14. {firewatcher-1.64 → firewatcher-1.66}/tests/test_position.py +10 -4
  15. firewatcher-1.66/tests/test_redirects.py +163 -0
  16. {firewatcher-1.64 → firewatcher-1.66}/LICENSE +0 -0
  17. {firewatcher-1.64 → firewatcher-1.66}/examples/nvme_failure.regex +0 -0
  18. {firewatcher-1.64 → firewatcher-1.66}/examples/sys_msg.txt +0 -0
  19. {firewatcher-1.64 → firewatcher-1.66}/firewatcher.egg-info/dependency_links.txt +0 -0
  20. {firewatcher-1.64 → firewatcher-1.66}/firewatcher.egg-info/entry_points.txt +0 -0
  21. {firewatcher-1.64 → firewatcher-1.66}/firewatcher.egg-info/top_level.txt +0 -0
  22. {firewatcher-1.64 → firewatcher-1.66}/setup.cfg +0 -0
  23. {firewatcher-1.64 → firewatcher-1.66}/setup.py +0 -0
  24. {firewatcher-1.64 → firewatcher-1.66}/tests/test_capture.py +0 -0
  25. {firewatcher-1.64 → firewatcher-1.66}/tests/test_compressor.py +0 -0
  26. {firewatcher-1.64 → firewatcher-1.66}/tests/test_log_source.py +0 -0
  27. {firewatcher-1.64 → firewatcher-1.66}/tests/test_matching.py +0 -0
  28. {firewatcher-1.64 → firewatcher-1.66}/tests/test_patterns.py +0 -0
  29. {firewatcher-1.64 → firewatcher-1.66}/tests/test_slugify.py +0 -0
  30. {firewatcher-1.64 → firewatcher-1.66}/tests/test_systemd.py +0 -0
@@ -1,4 +1,5 @@
1
1
  include LICENSE
2
2
  include README.md
3
3
  include examples/*
4
+ include docs/*.md
4
5
  recursive-include tests *.py
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: firewatcher
3
- Version: 1.64
3
+ Version: 1.66
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
@@ -131,7 +131,7 @@ Useful flags:
131
131
  | Flag | Description |
132
132
  |------|-------------|
133
133
  | `--unit-name NAME` | Unit name (default: `firewatcher`) |
134
- | `--requires-mounts-for PATH` | Add `RequiresMountsFor=` (repeat for NFS/remote output). Each path is made absolute and normalized as text (`.`, `..`, `//`, a trailing `/`; symlinks are not followed, as systemd follows none), quoted for you when it has spaces, quotes or backslashes, and refused if it has a newline or is not UTF-8 (systemd cannot read either back there) |
134
+ | `--requires-mounts-for PATH` | Add `RequiresMountsFor=` (repeat for NFS/remote output). Each path is made absolute and normalized as text (`.`, `..`, `//`, a trailing `/`; symlinks are not followed, as systemd follows none), quoted for you when it has spaces, quotes or backslashes, and refused if it has a newline or is not UTF-8 (systemd cannot read either back there). On systemd 229 and older (EL7), a path with `%`, `"` or `\` is read as a different path ([limitations](https://github.com/yufei-pan/firewatcher/blob/master/docs/limitations.md#on-systemd-229-and-older-some-mount-paths-are-written-wrong)) |
135
135
  | `--no-enable` | Write the unit and reload, but do not enable or start it |
136
136
 
137
137
  ```bash
@@ -183,7 +183,7 @@ sudo firewatcher --install-service -o /mnt/logs/captured_messages \
183
183
 
184
184
  Runtime settings live in an INI file. Explicit command-line flags override the file. Built-in defaults apply when neither sets a value. A missing default file is ignored. `--uninstall-service` does not read the file.
185
185
 
186
- A commented example with all supported settings is in [`examples/firewatcher.conf`](examples/firewatcher.conf). Copy it to `/etc/firewatcher/firewatcher.conf`, or use `firewatcher --config /path/to/firewatcher.conf`.
186
+ A commented example with all supported settings is in [`examples/firewatcher.conf`](https://github.com/yufei-pan/firewatcher/blob/master/examples/firewatcher.conf). Copy it to `/etc/firewatcher/firewatcher.conf`, or use `firewatcher --config /path/to/firewatcher.conf`.
187
187
 
188
188
  ```ini
189
189
  [watch]
@@ -207,14 +207,16 @@ enabled = false
207
207
  ntfy_url = https://ntfy.sh/firewatcher-myhost-REPLACE_ME
208
208
  priority = 4
209
209
  timeout = 10
210
+ events_url =
211
+ events_token =
210
212
  always_notify =
211
213
  ```
212
214
 
213
215
  `patterns` and `always_notify` are one path per line, or comma-separated. Positional pattern arguments replace the `patterns` list.
214
216
 
215
- 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 or ntfy URL that does not start with `http://` or `https://` or that contains spaces.
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
218
 
217
- `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. `--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.
219
+ `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.
218
220
 
219
221
  Generated configs include explanatory comments above each setting. When no ntfy URL is supplied, a new config gets `https://ntfy.sh/firewatcher-<hostname>-<random>`, with a 12-character URL-safe base64 suffix (72 random bits, no padding). The hostname is sanitized and shortened as needed to keep the topic within 64 characters. Explicit URLs are preserved, and reinstalling leaves an existing config and topic unchanged. Notifications still default to off; subscribe to the generated topic in ntfy, then set `[notify] enabled = true`. When copying the example above, replace its topic with your own.
220
222
 
@@ -225,7 +227,9 @@ Both features default off.
225
227
  - Notifications on, LLM off: every finished capture is pushed. The title is `{hostname}: {pattern}`.
226
228
  - LLM on, notifications off: the model writes a title, summary, and notify decision. The report is appended to the capture file and logged. Nothing is pushed.
227
229
  - Both on: a push is sent only when the model sets `notify` to true.
230
+ - With `[notify] events_url` set, the events service judges instead and firewatcher's LLM is off; see [Sending captures to an events service](#sending-captures-to-an-events-service).
228
231
  - If the LLM request times out, returns an HTTP error, or is not the expected JSON, and notifications are on, firewatcher still pushes, using the generated title.
232
+ - No request firewatcher makes (the LLM, ntfy or the events service) follows a redirect: a 3xx answer is a failure, logged as `HTTP 301 from <server> (redirect, not followed)` with only the server, so the request and its token never go on to another host. A failed ntfy push is logged as `ntfy failed`; a failed LLM request falls back as above.
229
233
 
230
234
  The capture window closes even when no further log lines arrive. Analysis runs on a background worker so log following stays live. The queue holds four captures. When the queue is full, that incident skips the model and, if notifications are on, the capture thread sends the generated-title push itself.
231
235
 
@@ -237,6 +241,27 @@ Any user or program on the host can write log lines, and those lines reach the m
237
241
 
238
242
  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.
239
243
 
244
+ ### Sending captures to an events service
245
+
246
+ Set `[notify] events_url` to an `http://` or `https://` URL (empty means off) and firewatcher POSTs every finished capture, with an excerpt of it, to that service as JSON, with `Content-Type: application/json`. If `events_token` is set (or `FIREWATCHER_EVENTS_TOKEN`), it is sent as `Authorization: Bearer <token>`. The service can be a log dashboard, a webhook relay, or anything that accepts the POST; the timeout is `[notify] timeout`.
247
+
248
+ The receiver judges. With `events_url` set, firewatcher's own LLM analysis is off whatever `[llm] enabled` says: no capture goes to the model, nothing is appended to the capture file, and `[llm] base_url` and `model` are not checked at startup. The only judgment left at the source is the rule-based floor, `always_notify`. The fields:
249
+
250
+ | Field | Meaning |
251
+ | --- | --- |
252
+ | `source` | always `firewatcher` |
253
+ | `version` | the firewatcher version |
254
+ | `host` | the host name |
255
+ | `pattern` | the pattern that opened the capture |
256
+ | `title`, `body` | what a fallback ntfy push would carry: the generated title `{hostname}: {pattern}`, and the `always_notify` line or the matched line followed by the capture path |
257
+ | `push` | whether firewatcher itself counts the capture as worth an alert: the same as `always_notify` |
258
+ | `always_notify` | an `always_notify` pattern matched |
259
+ | `excerpt` | the capture, cut the same way as for the model when it is too big, and at most 16384 characters once JSON-encoded, so the whole event stays well under 64 KiB; `""` when the capture could not be saved or is gone |
260
+ | `path` | the capture file, or `null` when it could not be saved |
261
+ | `time` | when the event was sent (ISO 8601 with the UTC offset): after the capture window, not when the line matched |
262
+
263
+ Captures are posted whatever `push` says, so the service sees them all. Any 2xx answer means the service has the capture, and then nothing goes to ntfy. Anything else (a refused connection, a timeout, a TLS error, a redirect, a 4xx or 5xx) is logged as `event post failed`, and then only `always_notify` captures are pushed to ntfy (when notifications are on), with the generated title and the line that matched. Other captures stay in the capture folder and the journal (`event post failed: ...; not pushed (not always_notify)`). While the service does not answer, each push goes out one timeout late ([limitations](https://github.com/yufei-pan/firewatcher/blob/master/docs/limitations.md#while-the-events-receiver-is-down-each-alert-waits-one-timeout-before-ntfy)). `events_url` also works without `[notify] enabled`; a failed POST then only logs. Like the ntfy topic, the URL is shown only as its server, and the token is never logged. A `user:password` in a URL (events, ntfy or LLM) is not sent: use `events_token` (`token` under `[notify]` for ntfy, `api_key` under `[llm]` for the model). firewatcher warns at startup when one is there, naming the setting (`Warning: notify.ntfy_url holds a user:password, ...`) but never its value.
264
+
240
265
  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.
241
266
 
242
267
 
@@ -104,7 +104,7 @@ Useful flags:
104
104
  | Flag | Description |
105
105
  |------|-------------|
106
106
  | `--unit-name NAME` | Unit name (default: `firewatcher`) |
107
- | `--requires-mounts-for PATH` | Add `RequiresMountsFor=` (repeat for NFS/remote output). Each path is made absolute and normalized as text (`.`, `..`, `//`, a trailing `/`; symlinks are not followed, as systemd follows none), quoted for you when it has spaces, quotes or backslashes, and refused if it has a newline or is not UTF-8 (systemd cannot read either back there) |
107
+ | `--requires-mounts-for PATH` | Add `RequiresMountsFor=` (repeat for NFS/remote output). Each path is made absolute and normalized as text (`.`, `..`, `//`, a trailing `/`; symlinks are not followed, as systemd follows none), quoted for you when it has spaces, quotes or backslashes, and refused if it has a newline or is not UTF-8 (systemd cannot read either back there). On systemd 229 and older (EL7), a path with `%`, `"` or `\` is read as a different path ([limitations](https://github.com/yufei-pan/firewatcher/blob/master/docs/limitations.md#on-systemd-229-and-older-some-mount-paths-are-written-wrong)) |
108
108
  | `--no-enable` | Write the unit and reload, but do not enable or start it |
109
109
 
110
110
  ```bash
@@ -156,7 +156,7 @@ sudo firewatcher --install-service -o /mnt/logs/captured_messages \
156
156
 
157
157
  Runtime settings live in an INI file. Explicit command-line flags override the file. Built-in defaults apply when neither sets a value. A missing default file is ignored. `--uninstall-service` does not read the file.
158
158
 
159
- A commented example with all supported settings is in [`examples/firewatcher.conf`](examples/firewatcher.conf). Copy it to `/etc/firewatcher/firewatcher.conf`, or use `firewatcher --config /path/to/firewatcher.conf`.
159
+ A commented example with all supported settings is in [`examples/firewatcher.conf`](https://github.com/yufei-pan/firewatcher/blob/master/examples/firewatcher.conf). Copy it to `/etc/firewatcher/firewatcher.conf`, or use `firewatcher --config /path/to/firewatcher.conf`.
160
160
 
161
161
  ```ini
162
162
  [watch]
@@ -180,14 +180,16 @@ enabled = false
180
180
  ntfy_url = https://ntfy.sh/firewatcher-myhost-REPLACE_ME
181
181
  priority = 4
182
182
  timeout = 10
183
+ events_url =
184
+ events_token =
183
185
  always_notify =
184
186
  ```
185
187
 
186
188
  `patterns` and `always_notify` are one path per line, or comma-separated. Positional pattern arguments replace the `patterns` list.
187
189
 
188
- 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 or ntfy URL that does not start with `http://` or `https://` or that contains spaces.
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)).
189
191
 
190
- `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. `--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.
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.
191
193
 
192
194
  Generated configs include explanatory comments above each setting. When no ntfy URL is supplied, a new config gets `https://ntfy.sh/firewatcher-<hostname>-<random>`, with a 12-character URL-safe base64 suffix (72 random bits, no padding). The hostname is sanitized and shortened as needed to keep the topic within 64 characters. Explicit URLs are preserved, and reinstalling leaves an existing config and topic unchanged. Notifications still default to off; subscribe to the generated topic in ntfy, then set `[notify] enabled = true`. When copying the example above, replace its topic with your own.
193
195
 
@@ -198,7 +200,9 @@ Both features default off.
198
200
  - Notifications on, LLM off: every finished capture is pushed. The title is `{hostname}: {pattern}`.
199
201
  - LLM on, notifications off: the model writes a title, summary, and notify decision. The report is appended to the capture file and logged. Nothing is pushed.
200
202
  - Both on: a push is sent only when the model sets `notify` to true.
203
+ - With `[notify] events_url` set, the events service judges instead and firewatcher's LLM is off; see [Sending captures to an events service](#sending-captures-to-an-events-service).
201
204
  - If the LLM request times out, returns an HTTP error, or is not the expected JSON, and notifications are on, firewatcher still pushes, using the generated title.
205
+ - No request firewatcher makes (the LLM, ntfy or the events service) follows a redirect: a 3xx answer is a failure, logged as `HTTP 301 from <server> (redirect, not followed)` with only the server, so the request and its token never go on to another host. A failed ntfy push is logged as `ntfy failed`; a failed LLM request falls back as above.
202
206
 
203
207
  The capture window closes even when no further log lines arrive. Analysis runs on a background worker so log following stays live. The queue holds four captures. When the queue is full, that incident skips the model and, if notifications are on, the capture thread sends the generated-title push itself.
204
208
 
@@ -210,6 +214,27 @@ Any user or program on the host can write log lines, and those lines reach the m
210
214
 
211
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.
212
216
 
217
+ ### Sending captures to an events service
218
+
219
+ Set `[notify] events_url` to an `http://` or `https://` URL (empty means off) and firewatcher POSTs every finished capture, with an excerpt of it, to that service as JSON, with `Content-Type: application/json`. If `events_token` is set (or `FIREWATCHER_EVENTS_TOKEN`), it is sent as `Authorization: Bearer <token>`. The service can be a log dashboard, a webhook relay, or anything that accepts the POST; the timeout is `[notify] timeout`.
220
+
221
+ The receiver judges. With `events_url` set, firewatcher's own LLM analysis is off whatever `[llm] enabled` says: no capture goes to the model, nothing is appended to the capture file, and `[llm] base_url` and `model` are not checked at startup. The only judgment left at the source is the rule-based floor, `always_notify`. The fields:
222
+
223
+ | Field | Meaning |
224
+ | --- | --- |
225
+ | `source` | always `firewatcher` |
226
+ | `version` | the firewatcher version |
227
+ | `host` | the host name |
228
+ | `pattern` | the pattern that opened the capture |
229
+ | `title`, `body` | what a fallback ntfy push would carry: the generated title `{hostname}: {pattern}`, and the `always_notify` line or the matched line followed by the capture path |
230
+ | `push` | whether firewatcher itself counts the capture as worth an alert: the same as `always_notify` |
231
+ | `always_notify` | an `always_notify` pattern matched |
232
+ | `excerpt` | the capture, cut the same way as for the model when it is too big, and at most 16384 characters once JSON-encoded, so the whole event stays well under 64 KiB; `""` when the capture could not be saved or is gone |
233
+ | `path` | the capture file, or `null` when it could not be saved |
234
+ | `time` | when the event was sent (ISO 8601 with the UTC offset): after the capture window, not when the line matched |
235
+
236
+ Captures are posted whatever `push` says, so the service sees them all. Any 2xx answer means the service has the capture, and then nothing goes to ntfy. Anything else (a refused connection, a timeout, a TLS error, a redirect, a 4xx or 5xx) is logged as `event post failed`, and then only `always_notify` captures are pushed to ntfy (when notifications are on), with the generated title and the line that matched. Other captures stay in the capture folder and the journal (`event post failed: ...; not pushed (not always_notify)`). While the service does not answer, each push goes out one timeout late ([limitations](https://github.com/yufei-pan/firewatcher/blob/master/docs/limitations.md#while-the-events-receiver-is-down-each-alert-waits-one-timeout-before-ntfy)). `events_url` also works without `[notify] enabled`; a failed POST then only logs. Like the ntfy topic, the URL is shown only as its server, and the token is never logged. A `user:password` in a URL (events, ntfy or LLM) is not sent: use `events_token` (`token` under `[notify]` for ntfy, `api_key` under `[llm]` for the model). firewatcher warns at startup when one is there, naming the setting (`Warning: notify.ntfy_url holds a user:password, ...`) but never its value.
237
+
213
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.
214
239
 
215
240
 
@@ -0,0 +1,40 @@
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`).
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".
@@ -69,5 +69,5 @@ priority = 4
69
69
  # HTTP timeout in seconds.
70
70
  timeout = 10
71
71
  # Pattern files or directories. A capture whose matched lines match one of these is pushed
72
- # even when the LLM says not to notify. Blank: the LLM decides for every capture.
72
+ # even when the LLM says not to notify, and with events_url, pushed when the POST fails. Blank: no such floor.
73
73
  always_notify =
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: firewatcher
3
- Version: 1.64
3
+ Version: 1.66
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
@@ -131,7 +131,7 @@ Useful flags:
131
131
  | Flag | Description |
132
132
  |------|-------------|
133
133
  | `--unit-name NAME` | Unit name (default: `firewatcher`) |
134
- | `--requires-mounts-for PATH` | Add `RequiresMountsFor=` (repeat for NFS/remote output). Each path is made absolute and normalized as text (`.`, `..`, `//`, a trailing `/`; symlinks are not followed, as systemd follows none), quoted for you when it has spaces, quotes or backslashes, and refused if it has a newline or is not UTF-8 (systemd cannot read either back there) |
134
+ | `--requires-mounts-for PATH` | Add `RequiresMountsFor=` (repeat for NFS/remote output). Each path is made absolute and normalized as text (`.`, `..`, `//`, a trailing `/`; symlinks are not followed, as systemd follows none), quoted for you when it has spaces, quotes or backslashes, and refused if it has a newline or is not UTF-8 (systemd cannot read either back there). On systemd 229 and older (EL7), a path with `%`, `"` or `\` is read as a different path ([limitations](https://github.com/yufei-pan/firewatcher/blob/master/docs/limitations.md#on-systemd-229-and-older-some-mount-paths-are-written-wrong)) |
135
135
  | `--no-enable` | Write the unit and reload, but do not enable or start it |
136
136
 
137
137
  ```bash
@@ -183,7 +183,7 @@ sudo firewatcher --install-service -o /mnt/logs/captured_messages \
183
183
 
184
184
  Runtime settings live in an INI file. Explicit command-line flags override the file. Built-in defaults apply when neither sets a value. A missing default file is ignored. `--uninstall-service` does not read the file.
185
185
 
186
- A commented example with all supported settings is in [`examples/firewatcher.conf`](examples/firewatcher.conf). Copy it to `/etc/firewatcher/firewatcher.conf`, or use `firewatcher --config /path/to/firewatcher.conf`.
186
+ A commented example with all supported settings is in [`examples/firewatcher.conf`](https://github.com/yufei-pan/firewatcher/blob/master/examples/firewatcher.conf). Copy it to `/etc/firewatcher/firewatcher.conf`, or use `firewatcher --config /path/to/firewatcher.conf`.
187
187
 
188
188
  ```ini
189
189
  [watch]
@@ -207,14 +207,16 @@ enabled = false
207
207
  ntfy_url = https://ntfy.sh/firewatcher-myhost-REPLACE_ME
208
208
  priority = 4
209
209
  timeout = 10
210
+ events_url =
211
+ events_token =
210
212
  always_notify =
211
213
  ```
212
214
 
213
215
  `patterns` and `always_notify` are one path per line, or comma-separated. Positional pattern arguments replace the `patterns` list.
214
216
 
215
- 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 or ntfy URL that does not start with `http://` or `https://` or that contains spaces.
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
218
 
217
- `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. `--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.
219
+ `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.
218
220
 
219
221
  Generated configs include explanatory comments above each setting. When no ntfy URL is supplied, a new config gets `https://ntfy.sh/firewatcher-<hostname>-<random>`, with a 12-character URL-safe base64 suffix (72 random bits, no padding). The hostname is sanitized and shortened as needed to keep the topic within 64 characters. Explicit URLs are preserved, and reinstalling leaves an existing config and topic unchanged. Notifications still default to off; subscribe to the generated topic in ntfy, then set `[notify] enabled = true`. When copying the example above, replace its topic with your own.
220
222
 
@@ -225,7 +227,9 @@ Both features default off.
225
227
  - Notifications on, LLM off: every finished capture is pushed. The title is `{hostname}: {pattern}`.
226
228
  - LLM on, notifications off: the model writes a title, summary, and notify decision. The report is appended to the capture file and logged. Nothing is pushed.
227
229
  - Both on: a push is sent only when the model sets `notify` to true.
230
+ - With `[notify] events_url` set, the events service judges instead and firewatcher's LLM is off; see [Sending captures to an events service](#sending-captures-to-an-events-service).
228
231
  - If the LLM request times out, returns an HTTP error, or is not the expected JSON, and notifications are on, firewatcher still pushes, using the generated title.
232
+ - No request firewatcher makes (the LLM, ntfy or the events service) follows a redirect: a 3xx answer is a failure, logged as `HTTP 301 from <server> (redirect, not followed)` with only the server, so the request and its token never go on to another host. A failed ntfy push is logged as `ntfy failed`; a failed LLM request falls back as above.
229
233
 
230
234
  The capture window closes even when no further log lines arrive. Analysis runs on a background worker so log following stays live. The queue holds four captures. When the queue is full, that incident skips the model and, if notifications are on, the capture thread sends the generated-title push itself.
231
235
 
@@ -237,6 +241,27 @@ Any user or program on the host can write log lines, and those lines reach the m
237
241
 
238
242
  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.
239
243
 
244
+ ### Sending captures to an events service
245
+
246
+ Set `[notify] events_url` to an `http://` or `https://` URL (empty means off) and firewatcher POSTs every finished capture, with an excerpt of it, to that service as JSON, with `Content-Type: application/json`. If `events_token` is set (or `FIREWATCHER_EVENTS_TOKEN`), it is sent as `Authorization: Bearer <token>`. The service can be a log dashboard, a webhook relay, or anything that accepts the POST; the timeout is `[notify] timeout`.
247
+
248
+ The receiver judges. With `events_url` set, firewatcher's own LLM analysis is off whatever `[llm] enabled` says: no capture goes to the model, nothing is appended to the capture file, and `[llm] base_url` and `model` are not checked at startup. The only judgment left at the source is the rule-based floor, `always_notify`. The fields:
249
+
250
+ | Field | Meaning |
251
+ | --- | --- |
252
+ | `source` | always `firewatcher` |
253
+ | `version` | the firewatcher version |
254
+ | `host` | the host name |
255
+ | `pattern` | the pattern that opened the capture |
256
+ | `title`, `body` | what a fallback ntfy push would carry: the generated title `{hostname}: {pattern}`, and the `always_notify` line or the matched line followed by the capture path |
257
+ | `push` | whether firewatcher itself counts the capture as worth an alert: the same as `always_notify` |
258
+ | `always_notify` | an `always_notify` pattern matched |
259
+ | `excerpt` | the capture, cut the same way as for the model when it is too big, and at most 16384 characters once JSON-encoded, so the whole event stays well under 64 KiB; `""` when the capture could not be saved or is gone |
260
+ | `path` | the capture file, or `null` when it could not be saved |
261
+ | `time` | when the event was sent (ISO 8601 with the UTC offset): after the capture window, not when the line matched |
262
+
263
+ Captures are posted whatever `push` says, so the service sees them all. Any 2xx answer means the service has the capture, and then nothing goes to ntfy. Anything else (a refused connection, a timeout, a TLS error, a redirect, a 4xx or 5xx) is logged as `event post failed`, and then only `always_notify` captures are pushed to ntfy (when notifications are on), with the generated title and the line that matched. Other captures stay in the capture folder and the journal (`event post failed: ...; not pushed (not always_notify)`). While the service does not answer, each push goes out one timeout late ([limitations](https://github.com/yufei-pan/firewatcher/blob/master/docs/limitations.md#while-the-events-receiver-is-down-each-alert-waits-one-timeout-before-ntfy)). `events_url` also works without `[notify] enabled`; a failed POST then only logs. Like the ntfy topic, the URL is shown only as its server, and the token is never logged. A `user:password` in a URL (events, ntfy or LLM) is not sent: use `events_token` (`token` under `[notify]` for ntfy, `api_key` under `[llm]` for the model). firewatcher warns at startup when one is there, naming the setting (`Warning: notify.ntfy_url holds a user:password, ...`) but never its value.
264
+
240
265
  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.
241
266
 
242
267
 
@@ -3,6 +3,7 @@ MANIFEST.in
3
3
  README.md
4
4
  firewatcher.py
5
5
  setup.py
6
+ docs/limitations.md
6
7
  examples/firewatcher.conf
7
8
  examples/nvme_failure.regex
8
9
  examples/sys_msg.txt
@@ -16,10 +17,12 @@ tests/test_capture.py
16
17
  tests/test_cli.py
17
18
  tests/test_compressor.py
18
19
  tests/test_config.py
20
+ tests/test_events.py
19
21
  tests/test_log_source.py
20
22
  tests/test_matching.py
21
23
  tests/test_notify.py
22
24
  tests/test_patterns.py
23
25
  tests/test_position.py
26
+ tests/test_redirects.py
24
27
  tests/test_slugify.py
25
28
  tests/test_systemd.py