From: Wolfgang Bumiller <w.bumiller@proxmox.com>
To: pve-devel@lists.proxmox.com
Cc: Lukas Wagner <l.wagner@proxmox.com>
Subject: [pve-devel] [PATCH perl-rs 4/5] pve-rs: common: send apt update notification via proxmox-notify
Date: Tue, 9 Jul 2024 08:20:25 +0200 [thread overview]
Message-ID: <20240709062026.53271-4-w.bumiller@proxmox.com> (raw)
In-Reply-To: <20240709062026.53271-1-w.bumiller@proxmox.com>
From: Lukas Wagner <l.wagner@proxmox.com>
For PMG we for now only provide an empty stub and warn to syslog -
we need basic notification system integration there first.
On PMG, we still use a pure Perl implementation at the moment,
so this should not be an issue unless we change that.
Signed-off-by: Lukas Wagner <l.wagner@proxmox.com>
---
common/src/apt/repositories.rs | 3 +-
pmg-rs/Cargo.toml | 1 +
pmg-rs/src/lib.rs | 10 ++++++
pve-rs/src/lib.rs | 64 ++++++++++++++++++++++++++++++++++
4 files changed, 77 insertions(+), 1 deletion(-)
diff --git a/common/src/apt/repositories.rs b/common/src/apt/repositories.rs
index ccf4f33..8ad29cc 100644
--- a/common/src/apt/repositories.rs
+++ b/common/src/apt/repositories.rs
@@ -63,8 +63,9 @@ pub mod export {
proxmox_apt::update_database(
apt_state_file,
&options,
- |_updates: &[&APTUpdateInfo]| -> Result<(), Error> {
+ |updates: &[&APTUpdateInfo]| -> Result<(), Error> {
// fixme: howto send notifgications?
+ crate::send_updates_available(updates)?;
Ok(())
},
)
diff --git a/pmg-rs/Cargo.toml b/pmg-rs/Cargo.toml
index 2706fcb..8a6d113 100644
--- a/pmg-rs/Cargo.toml
+++ b/pmg-rs/Cargo.toml
@@ -19,6 +19,7 @@ env_logger = "0.10"
hex = "0.4"
http = "0.2.7"
libc = "0.2"
+log = "0.4.17"
nix = "0.26"
openssl = "0.10.40"
serde = "1.0"
diff --git a/pmg-rs/src/lib.rs b/pmg-rs/src/lib.rs
index 4a91632..8bac823 100644
--- a/pmg-rs/src/lib.rs
+++ b/pmg-rs/src/lib.rs
@@ -6,6 +6,10 @@ pub mod apt;
pub mod csr;
pub mod tfa;
+use anyhow::Error;
+
+use proxmox_apt_api_types::APTUpdateInfo;
+
#[perlmod::package(name = "Proxmox::Lib::PMG", lib = "pmg_rs")]
mod export {
use crate::common;
@@ -23,3 +27,9 @@ mod export {
perlmod::ffi::use_safe_putenv(true);
}
}
+
+pub fn send_updates_available(_updates: &[&APTUpdateInfo]) -> Result<(), Error> {
+ log::warn!("update notifications are not implemented for PMG yet");
+
+ Ok(())
+}
diff --git a/pve-rs/src/lib.rs b/pve-rs/src/lib.rs
index 73780f8..0fad753 100644
--- a/pve-rs/src/lib.rs
+++ b/pve-rs/src/lib.rs
@@ -8,6 +8,14 @@ pub mod openid;
pub mod resource_scheduling;
pub mod tfa;
+use std::collections::HashMap;
+
+use anyhow::Error;
+
+use proxmox_apt_api_types::APTUpdateInfo;
+use proxmox_notify::{Config, Notification, Severity};
+use serde_json::json;
+
#[perlmod::package(name = "Proxmox::Lib::PVE", lib = "pve_rs")]
mod export {
use proxmox_notify::context::pve::PVE_CONTEXT;
@@ -20,3 +28,59 @@ mod export {
proxmox_notify::context::set_context(&PVE_CONTEXT);
}
}
+
+fn send_notification(notification: &Notification) -> Result<(), Error> {
+ let config = proxmox_sys::fs::file_read_optional_string("/etc/pve/notifications.cfg")?
+ .unwrap_or_default();
+ let private_config =
+ proxmox_sys::fs::file_read_optional_string("/etc/pve/priv/notifications.cfg")?
+ .unwrap_or_default();
+
+ let config = Config::new(&config, &private_config)?;
+
+ proxmox_notify::api::common::send(&config, notification)?;
+
+ Ok(())
+}
+
+pub fn send_updates_available(updates: &[&APTUpdateInfo]) -> Result<(), Error> {
+ let hostname = proxmox_sys::nodename().to_string();
+
+ let metadata = HashMap::from([
+ ("hostname".into(), hostname.clone()),
+ ("type".into(), "package-updates".into()),
+ ]);
+
+ // The template uses the `table` handlebars helper, so
+ // we need to form the approriate data structure first.
+ let update_table = json!({
+ "schema": {
+ "columns": [
+ {
+ "label": "Package",
+ "id": "Package",
+ },
+ {
+ "label": "Old Version",
+ "id": "OldVersion",
+ },
+ {
+ "label": "New Version",
+ "id": "Version",
+ }
+ ],
+ },
+ "data": updates,
+ });
+
+ let template_data = json!({
+ "hostname": hostname,
+ "updates": update_table,
+ });
+
+ let notification =
+ Notification::from_template(Severity::Info, "package-updates", template_data, metadata);
+
+ send_notification(¬ification)?;
+ Ok(())
+}
--
2.39.2
_______________________________________________
pve-devel mailing list
pve-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel
next prev parent reply other threads:[~2024-07-09 6:20 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-07-09 6:20 [pve-devel] applied-series: [PATCH perl-rs 1/5] perl-rs: use proxmox-apt-api-types Wolfgang Bumiller
2024-07-09 6:20 ` [pve-devel] [PATCH perl-rs 2/5] perl-rs: use api functions from proxmox-apt Wolfgang Bumiller
2024-07-09 6:20 ` [pve-devel] [PATCH perl-rs 3/5] perl-rs: add further apt api calls Wolfgang Bumiller
2024-07-09 6:20 ` Wolfgang Bumiller [this message]
2024-07-09 6:20 ` [pve-devel] [PATCH perl-rs 5/5] apt: minor parameter cleanup Wolfgang Bumiller
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20240709062026.53271-4-w.bumiller@proxmox.com \
--to=w.bumiller@proxmox.com \
--cc=l.wagner@proxmox.com \
--cc=pve-devel@lists.proxmox.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.