firewatcher 1.64__tar.gz → 1.65__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 (28) hide show
  1. {firewatcher-1.64/firewatcher.egg-info → firewatcher-1.65}/PKG-INFO +28 -4
  2. {firewatcher-1.64 → firewatcher-1.65}/README.md +27 -3
  3. {firewatcher-1.64 → firewatcher-1.65}/examples/firewatcher.conf +1 -1
  4. {firewatcher-1.64 → firewatcher-1.65/firewatcher.egg-info}/PKG-INFO +28 -4
  5. {firewatcher-1.64 → firewatcher-1.65}/firewatcher.egg-info/SOURCES.txt +1 -0
  6. {firewatcher-1.64 → firewatcher-1.65}/firewatcher.py +213 -36
  7. {firewatcher-1.64 → firewatcher-1.65}/tests/conftest.py +1 -0
  8. {firewatcher-1.64 → firewatcher-1.65}/tests/test_cli.py +1 -1
  9. {firewatcher-1.64 → firewatcher-1.65}/tests/test_config.py +17 -0
  10. firewatcher-1.65/tests/test_events.py +610 -0
  11. {firewatcher-1.64 → firewatcher-1.65}/LICENSE +0 -0
  12. {firewatcher-1.64 → firewatcher-1.65}/MANIFEST.in +0 -0
  13. {firewatcher-1.64 → firewatcher-1.65}/examples/nvme_failure.regex +0 -0
  14. {firewatcher-1.64 → firewatcher-1.65}/examples/sys_msg.txt +0 -0
  15. {firewatcher-1.64 → firewatcher-1.65}/firewatcher.egg-info/dependency_links.txt +0 -0
  16. {firewatcher-1.64 → firewatcher-1.65}/firewatcher.egg-info/entry_points.txt +0 -0
  17. {firewatcher-1.64 → firewatcher-1.65}/firewatcher.egg-info/top_level.txt +0 -0
  18. {firewatcher-1.64 → firewatcher-1.65}/setup.cfg +0 -0
  19. {firewatcher-1.64 → firewatcher-1.65}/setup.py +0 -0
  20. {firewatcher-1.64 → firewatcher-1.65}/tests/test_capture.py +0 -0
  21. {firewatcher-1.64 → firewatcher-1.65}/tests/test_compressor.py +0 -0
  22. {firewatcher-1.64 → firewatcher-1.65}/tests/test_log_source.py +0 -0
  23. {firewatcher-1.64 → firewatcher-1.65}/tests/test_matching.py +0 -0
  24. {firewatcher-1.64 → firewatcher-1.65}/tests/test_notify.py +0 -0
  25. {firewatcher-1.64 → firewatcher-1.65}/tests/test_patterns.py +0 -0
  26. {firewatcher-1.64 → firewatcher-1.65}/tests/test_position.py +0 -0
  27. {firewatcher-1.64 → firewatcher-1.65}/tests/test_slugify.py +0 -0
  28. {firewatcher-1.64 → firewatcher-1.65}/tests/test_systemd.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: firewatcher
3
- Version: 1.64
3
+ Version: 1.65
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](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
@@ -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](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,6 +227,7 @@ 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.
229
232
 
230
233
  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.
@@ -237,6 +240,27 @@ Any user or program on the host can write log lines, and those lines reach the m
237
240
 
238
241
  The ntfy topic URL is not printed at startup or in error messages, since on a public ntfy server whoever knows the topic can subscribe to it. Only the server is shown. Keep the topic in the config file (mode `0600`) rather than on the command line: `--ntfy-url` shows in the process list, and when the config already exists, `--install-service --ntfy-url` puts it on the unit's `ExecStart`, which any user can read. `--install-service` warns when that happens.
239
242
 
243
+ ### Sending captures to an events service
244
+
245
+ 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`.
246
+
247
+ 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:
248
+
249
+ | Field | Meaning |
250
+ | --- | --- |
251
+ | `source` | always `firewatcher` |
252
+ | `version` | the firewatcher version |
253
+ | `host` | the host name |
254
+ | `pattern` | the pattern that opened the capture |
255
+ | `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 |
256
+ | `push` | whether firewatcher itself counts the capture as worth an alert: the same as `always_notify` |
257
+ | `always_notify` | an `always_notify` pattern matched |
258
+ | `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 |
259
+ | `path` | the capture file, or `null` when it could not be saved |
260
+ | `time` | when the event was sent (ISO 8601 with the UTC offset): after the capture window, not when the line matched |
261
+
262
+ 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](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).
263
+
240
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.
241
265
 
242
266
 
@@ -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](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
@@ -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](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,6 +200,7 @@ 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.
202
205
 
203
206
  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.
@@ -210,6 +213,27 @@ Any user or program on the host can write log lines, and those lines reach the m
210
213
 
211
214
  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
215
 
216
+ ### Sending captures to an events service
217
+
218
+ 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`.
219
+
220
+ 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:
221
+
222
+ | Field | Meaning |
223
+ | --- | --- |
224
+ | `source` | always `firewatcher` |
225
+ | `version` | the firewatcher version |
226
+ | `host` | the host name |
227
+ | `pattern` | the pattern that opened the capture |
228
+ | `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 |
229
+ | `push` | whether firewatcher itself counts the capture as worth an alert: the same as `always_notify` |
230
+ | `always_notify` | an `always_notify` pattern matched |
231
+ | `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 |
232
+ | `path` | the capture file, or `null` when it could not be saved |
233
+ | `time` | when the event was sent (ISO 8601 with the UTC offset): after the capture window, not when the line matched |
234
+
235
+ 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](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).
236
+
213
237
  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
238
 
215
239
 
@@ -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.65
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](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
@@ -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](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,6 +227,7 @@ 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.
229
232
 
230
233
  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.
@@ -237,6 +240,27 @@ Any user or program on the host can write log lines, and those lines reach the m
237
240
 
238
241
  The ntfy topic URL is not printed at startup or in error messages, since on a public ntfy server whoever knows the topic can subscribe to it. Only the server is shown. Keep the topic in the config file (mode `0600`) rather than on the command line: `--ntfy-url` shows in the process list, and when the config already exists, `--install-service --ntfy-url` puts it on the unit's `ExecStart`, which any user can read. `--install-service` warns when that happens.
239
242
 
243
+ ### Sending captures to an events service
244
+
245
+ 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`.
246
+
247
+ 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:
248
+
249
+ | Field | Meaning |
250
+ | --- | --- |
251
+ | `source` | always `firewatcher` |
252
+ | `version` | the firewatcher version |
253
+ | `host` | the host name |
254
+ | `pattern` | the pattern that opened the capture |
255
+ | `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 |
256
+ | `push` | whether firewatcher itself counts the capture as worth an alert: the same as `always_notify` |
257
+ | `always_notify` | an `always_notify` pattern matched |
258
+ | `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 |
259
+ | `path` | the capture file, or `null` when it could not be saved |
260
+ | `time` | when the event was sent (ISO 8601 with the UTC offset): after the capture window, not when the line matched |
261
+
262
+ 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](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).
263
+
240
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.
241
265
 
242
266
 
@@ -16,6 +16,7 @@ tests/test_capture.py
16
16
  tests/test_cli.py
17
17
  tests/test_compressor.py
18
18
  tests/test_config.py
19
+ tests/test_events.py
19
20
  tests/test_log_source.py
20
21
  tests/test_matching.py
21
22
  tests/test_notify.py