From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: <pbs-devel-bounces@lists.proxmox.com> Received: from firstgate.proxmox.com (firstgate.proxmox.com [IPv6:2a01:7e0:0:424::9]) by lore.proxmox.com (Postfix) with ESMTPS id 675DB1FF173 for <inbox@lore.proxmox.com>; Mon, 24 Mar 2025 09:33:10 +0100 (CET) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 9B985DB00; Mon, 24 Mar 2025 09:33:06 +0100 (CET) Message-ID: <747888cd-71f3-4d8d-b223-14654e3f6681@proxmox.com> Date: Mon, 24 Mar 2025 09:32:58 +0100 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird To: Wolfgang Bumiller <w.bumiller@proxmox.com> References: <20250321122521.198725-1-l.wagner@proxmox.com> <20250321122521.198725-3-l.wagner@proxmox.com> <mypjw222ja54377hq5mewvloov4j4bfll34c73cl6h6ednejzv@pirmd3mjqtfp> Content-Language: de-AT, en-US From: Lukas Wagner <l.wagner@proxmox.com> In-Reply-To: <mypjw222ja54377hq5mewvloov4j4bfll34c73cl6h6ednejzv@pirmd3mjqtfp> X-SPAM-LEVEL: Spam detection results: 0 AWL 0.009 Adjusted score from AWL reputation of From: address BAYES_00 -1.9 Bayes spam probability is 0 to 1% DMARC_MISSING 0.1 Missing DMARC policy KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment KAM_SHORT 0.001 Use of a URL Shortener for very short URL RCVD_IN_VALIDITY_CERTIFIED_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to Validity was blocked. See https://knowledge.validity.com/hc/en-us/articles/20961730681243 for more information. RCVD_IN_VALIDITY_RPBL_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to Validity was blocked. See https://knowledge.validity.com/hc/en-us/articles/20961730681243 for more information. RCVD_IN_VALIDITY_SAFE_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to Validity was blocked. See https://knowledge.validity.com/hc/en-us/articles/20961730681243 for more information. SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record URIBL_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to URIBL was blocked. See http://wiki.apache.org/spamassassin/DnsBlocklists#dnsbl-block for more information. [docs.rs, mod.rs] Subject: Re: [pbs-devel] [PATCH proxmox-backup 02/10] notifications: add type for GC notification template data X-BeenThere: pbs-devel@lists.proxmox.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Proxmox Backup Server development discussion <pbs-devel.lists.proxmox.com> List-Unsubscribe: <https://lists.proxmox.com/cgi-bin/mailman/options/pbs-devel>, <mailto:pbs-devel-request@lists.proxmox.com?subject=unsubscribe> List-Archive: <http://lists.proxmox.com/pipermail/pbs-devel/> List-Post: <mailto:pbs-devel@lists.proxmox.com> List-Help: <mailto:pbs-devel-request@lists.proxmox.com?subject=help> List-Subscribe: <https://lists.proxmox.com/cgi-bin/mailman/listinfo/pbs-devel>, <mailto:pbs-devel-request@lists.proxmox.com?subject=subscribe> Reply-To: Proxmox Backup Server development discussion <pbs-devel@lists.proxmox.com> Cc: pbs-devel@lists.proxmox.com Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: pbs-devel-bounces@lists.proxmox.com Sender: "pbs-devel" <pbs-devel-bounces@lists.proxmox.com> On 2025-03-21 14:28, Wolfgang Bumiller wrote: > On Fri, Mar 21, 2025 at 01:25:13PM +0100, Lukas Wagner wrote: >> This commit adds a separate type for the data passed to this type of >> notification template. Also we make sure that we do not expose any >> non-primitive types to the template renderer, any data >> needed in the template is mapped into the new dedicated >> template data type. >> This ensures that any changes in types defined in other places >> do not leak into the template rendering process by accident. >> >> This commit also tries to unify the style and naming of template >> variables. >> >> Signed-off-by: Lukas Wagner <l.wagner@proxmox.com> >> --- >> src/server/notifications/mod.rs | 50 ++++---- >> src/server/notifications/template_data.rs | 132 ++++++++++++++++++++++ >> templates/default/gc-err-body.txt.hbs | 2 +- >> templates/default/gc-err-subject.txt.hbs | 2 +- >> templates/default/gc-ok-body.txt.hbs | 22 ++-- >> templates/default/gc-ok-subject.txt.hbs | 2 +- >> 6 files changed, 170 insertions(+), 40 deletions(-) >> create mode 100644 src/server/notifications/template_data.rs >> >> diff --git a/src/server/notifications/mod.rs b/src/server/notifications/mod.rs >> index eea55202..182af213 100644 >> --- a/src/server/notifications/mod.rs >> +++ b/src/server/notifications/mod.rs >> @@ -21,6 +21,10 @@ use proxmox_notify::{Endpoint, Notification, Severity}; >> >> const SPOOL_DIR: &str = concatcp!(pbs_buildcfg::PROXMOX_BACKUP_STATE_DIR, "/notifications"); >> >> +mod template_data; >> + >> +use template_data::{GcErrTemplateData, GcOkTemplateData}; >> + >> /// Initialize the notification system by setting context in proxmox_notify >> pub fn init() -> Result<(), Error> { >> proxmox_notify::context::set_context(&PBS_CONTEXT); >> @@ -146,38 +150,32 @@ pub fn send_gc_status( >> status: &GarbageCollectionStatus, >> result: &Result<(), Error>, >> ) -> Result<(), Error> { >> - let (fqdn, port) = get_server_url(); >> - let mut data = json!({ >> - "datastore": datastore, >> - "fqdn": fqdn, >> - "port": port, >> - }); >> - >> - let (severity, template) = match result { >> - Ok(()) => { >> - let deduplication_factor = if status.disk_bytes > 0 { >> - (status.index_data_bytes as f64) / (status.disk_bytes as f64) >> - } else { >> - 1.0 >> - }; >> - >> - data["status"] = json!(status); >> - data["deduplication-factor"] = format!("{:.2}", deduplication_factor).into(); >> - >> - (Severity::Info, "gc-ok") >> - } >> - Err(err) => { >> - data["error"] = err.to_string().into(); >> - (Severity::Error, "gc-err") >> - } >> - }; >> let metadata = HashMap::from([ >> ("datastore".into(), datastore.into()), >> ("hostname".into(), proxmox_sys::nodename().into()), >> ("type".into(), "gc".into()), >> ]); >> >> - let notification = Notification::from_template(severity, template, data, metadata); >> + let notification = match result { >> + Ok(()) => { >> + let template_data = GcOkTemplateData::new(datastore.to_string(), status); >> + Notification::from_template( >> + Severity::Info, >> + "gc-ok", >> + serde_json::to_value(template_data)?, >> + metadata, >> + ) >> + } >> + Err(err) => { >> + let template_data = GcErrTemplateData::new(datastore.to_string(), err.to_string()); > > ^ While at it, we could consider switching this error to use > `format!{"{err:#}")` which will include the context as a short form. > This goes for all the templates/commits - but can just be a follow up. > Noticing this since Chris got me looking at anyhow's display > representations[1] > > [1] https://docs.rs/anyhow/latest/anyhow/struct.Error.html#display-representations > Good point, I'll check it out. Will do that in a followup if nothing else comes up. Thanks! -- - Lukas _______________________________________________ pbs-devel mailing list pbs-devel@lists.proxmox.com https://lists.proxmox.com/cgi-bin/mailman/listinfo/pbs-devel