Commit Graph

25 Commits

Author SHA1 Message Date
Lukas Wagner
3c1c34043e notify: copy sendmail/forward fn's from proxmox_sys
proxmox_notify is the only user of those functions, so it makes
sense to move them here. A future commit will mark the
original functions from proxmox_sys as deprecated.

The functions were slightly modified, mostly to not
rely on anyhow for error reporting. Also they
are now private functions.

Signed-off-by: Lukas Wagner <l.wagner@proxmox.com>
2024-07-11 14:43:37 +02:00
Wolfgang Bumiller
0a0d8a4d73 notify: bump to 0.4.1-1
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2024-06-20 14:02:10 +02:00
Thomas Lamprecht
0af0bad742 notify: bump version to 0.4.0-1
Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
2024-04-23 23:14:19 +02:00
Lukas Wagner
7035d57312 notify: use std::sync::OnceCell instead of lazy_static!
Signed-off-by: Lukas Wagner <l.wagner@proxmox.com>
Tested-by: Maximiliano Sandoval <m.sandoval@proxmox.com>
2024-04-23 23:06:56 +02:00
Lukas Wagner
e83269be1d notify: give each notification a unique ID
We need this for queuing notifications on PBS from the unprivileged
proxy process.

Signed-off-by: Lukas Wagner <l.wagner@proxmox.com>
Reviewed-by: Fiona Ebner <f.ebner@proxmox.com>
2024-04-23 23:06:52 +02:00
Lukas Wagner
efb576385b notify: cargo.toml: add spaces before curly braces
Signed-off-by: Lukas Wagner <l.wagner@proxmox.com>
Reviewed-by: Fiona Ebner <f.ebner@proxmox.com>
2024-04-23 23:06:52 +02:00
Lukas Wagner
2f40b79f8f notify: make the mail-forwarder feature depend on proxmox-sys
It uses proxmox_sys::nodename - the dep is needed, otherwise the code
does not compile in some feature flag permutations.

Signed-off-by: Lukas Wagner <l.wagner@proxmox.com>
Tested-by: Folke Gleumes <f.gleumes@proxmox.com>
Reviewed-by: Fiona Ebner <f.ebner@proxmox.com>
2024-04-23 23:06:52 +02:00
Wolfgang Bumiller
e32081ea5f bump proxmox-notify to 0.3.3-1
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2024-03-19 11:11:02 +01:00
Wolfgang Bumiller
6f1d439f09 notify: adapt to proxmox_schema changes, use const_format
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2024-03-19 10:29:27 +01:00
Wolfgang Bumiller
686453a28c notify: sort and group dependencies
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2024-03-19 10:27:25 +01:00
Wolfgang Bumiller
364b21f3d2 bump proxmox-notify to 0.3.2-1
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2024-02-02 14:21:14 +01:00
Wolfgang Bumiller
1484676ac4 bump proxmox-notify to 0.3.1-1
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2024-01-10 14:04:36 +01:00
Thomas Lamprecht
eb6df88120 notify: bump version to 0.3.0-1
Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
2023-11-17 13:36:55 +01:00
Lukas Wagner
53627a1952 notify: add 'smtp' endpoint
This commit adds a new endpoint type, namely 'smtp'. This endpoint
uses the `lettre` crate to directly send emails to SMTP relays.

The `lettre` crate was chosen since it is by far the most popular SMTP
implementation for Rust that looks like it is well maintained.
Also, it includes async support (for when we want to extend
proxmox-notify to be async).

For this new endpoint type, a new section-config type was introduced
(smtp). It has the same fields as the type for `sendmail`, with the
addition of some new options (smtp server, authentication, tls mode,
etc.).

Some of the behavior that is shared between sendmail and smtp
endpoints has been moved to a new `endpoints::common::mail` module.

Signed-off-by: Lukas Wagner <l.wagner@proxmox.com>
2023-11-17 08:31:36 +01:00
Lukas Wagner
c1a3505e51 notify: add PVE/PBS context
This commit moves PVEContext from `proxmox-perl-rs` into the
`proxmox-notify` crate, since we now also need to access it from
`promxox-mail-forward`. The context is now hidden behind a feature
flag `pve-context`, ensuring that we only compile it when needed.

This commit adds PBSContext, since we now require it for
`proxmox-mail-forward`. Some of the code for PBSContext comes
from `proxmox-mail-forward`.

This commit also changes the global context from being stored in a
`once_cell` to a regular `Mutex`, since we now need to set/reset
the context in `proxmox-mail-forward`.

Signed-off-by: Lukas Wagner <l.wagner@proxmox.com>
2023-11-17 08:31:36 +01:00
Lukas Wagner
5f7ac875f6 notify: add mechanisms for email message forwarding
As preparation for the integration of `proxmox-mail-foward` into the
notification system, this commit makes a few changes that allow us to
forward raw email messages (as passed from postfix).

For mail-based notification targets, the email will be forwarded
as-is, including all headers. The only thing that changes is the
message envelope.
For other notification targets, the mail is parsed using the
`mail-parser` crate, which allows us to extract a subject and a body.
As a body we use the plain-text version of the mail. If an email is
HTML-only, the `mail-parser` crate will automatically attempt to
transform the HTML into readable plain text.

Signed-off-by: Lukas Wagner <l.wagner@proxmox.com>
2023-11-17 08:31:36 +01:00
Lukas Wagner
b421a7ca24 notify: replace filters and groups with matcher-based system
This shifts notification routing into the matcher-system. Every
notification has associated metadata (key-value fields, severity -
to be extended) that can be match with match directives in
notification matchers. Right now, there are 2 matching directives,
match-field and match-severity. The first one allows one to do a
regex match/exact match on a metadata field, the other one allows one
to match one or more severites.
Every matcher also allows 'target' directives, these decide which
target(s) will be notified if a matcher matches a notification.

Since routing now happens in matchers, the API for sending is
simplified, since we do not need to specify a target any more.

The API routes for filters and groups have been removed completely.
The parser for the configuration file will still accept filter/group
entries, but will delete them once the config is saved again. This is
needed to allow a smooth transition from the old system to the new
system, since the old system was already available on pvetest.

Signed-off-by: Lukas Wagner <l.wagner@proxmox.com>
2023-11-17 08:31:36 +01:00
Wolfgang Bumiller
5859017061 bump proxmox-notify to 0.2.0
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2023-07-28 11:56:56 +02:00
Lukas Wagner
1a75668dc9 notify: use HttpError from proxmox-http-error
Also improve API documentation in terms of which HttpError is
returned when.

Signed-off-by: Lukas Wagner <l.wagner@proxmox.com>
2023-07-28 10:47:07 +02:00
Lukas Wagner
d6c1f181d6 notify: add context
Since `proxmox-notify` is intended to be used by multiple products,
there needs to be a way to inject product-specific behavior.

Signed-off-by: Lukas Wagner <l.wagner@proxmox.com>
2023-07-24 10:25:51 +02:00
Lukas Wagner
4865711339 notify: add template rendering
This commit adds template rendering to the `proxmox-notify` crate, based
on the `handlebars` crate.

Title and body of a notification are rendered using any `properties`
passed along with the notification. There are also a few helpers,
allowing to render tables from `serde_json::Value`.

'Value' renderers. These can also be used in table cells using the
'renderer' property in a table schema:
  - {{human-bytes val}}
    Render bytes with human-readable units (base 2)
  - {{duration val}}
    Render a duration (based on seconds)
  - {{timestamp val}}
    Render a unix-epoch (based on seconds)

There are also a few 'block-level' helpers.
  - {{table val}}
    Render a table from given val (containing a schema for the columns,
    as well as the table data)
  - {{object val}}
    Render a value as a pretty-printed json
  - {{heading_1 val}}
    Render a top-level heading
  - {{heading_2 val}}
    Render a not-so-top-level heading
  - {{verbatim val}} or {{/verbatim}}<content>{{#verbatim}}
    Do not reflow text. NOP for plain text, but for HTML output the text
    will be contained in a <pre> with a regular font.
  - {{verbatim-monospaced val}} or
      {{/verbatim-monospaced}}<content>{{#verbatim-monospaced}}
    Do not reflow text. NOP for plain text, but for HTML output the text
    will be contained in a <pre> with a monospaced font.

Signed-off-by: Lukas Wagner <l.wagner@proxmox.com>
2023-07-24 10:25:48 +02:00
Lukas Wagner
990fc8efd2 notify: add gotify endpoint
Add an endpoint for Gotify [1], showing the how easy it is to add new
endpoint implementations.

[1] https://gotify.net/

Signed-off-by: Lukas Wagner <l.wagner@proxmox.com>
2023-07-24 10:25:35 +02:00
Lukas Wagner
7c42752690 notify: add sendmail plugin
This plugin uses the 'sendmail' command to send an email
to one or more recipients.

Signed-off-by: Lukas Wagner <l.wagner@proxmox.com>
2023-07-24 10:25:31 +02:00
Lukas Wagner
2726e68afe notify: preparation for the first endpoint plugin
Signed-off-by: Lukas Wagner <l.wagner@proxmox.com>
2023-07-24 10:25:27 +02:00
Lukas Wagner
b8040a23cb add proxmox-notify crate
Signed-off-by: Lukas Wagner <l.wagner@proxmox.com>
2023-07-24 10:25:25 +02:00