mirror of
https://git.proxmox.com/git/proxmox-backup
synced 2025-08-14 21:30:45 +00:00
server: notifications: send update notifications via notification system
Signed-off-by: Lukas Wagner <l.wagner@proxmox.com> Tested-by: Gabriel Goller <g.goller@proxmox.com> Reviewed-by: Gabriel Goller <g.goller@proxmox.com> Tested-by: Maximiliano Sandoval <m.sandoval@proxmox.com> Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
This commit is contained in:
parent
5b23a70707
commit
823314c7f4
2
debian/proxmox-backup-server.install
vendored
2
debian/proxmox-backup-server.install
vendored
@ -45,6 +45,8 @@ usr/share/proxmox-backup/templates/default/gc-err-body.txt.hbs
|
|||||||
usr/share/proxmox-backup/templates/default/gc-ok-body.txt.hbs
|
usr/share/proxmox-backup/templates/default/gc-ok-body.txt.hbs
|
||||||
usr/share/proxmox-backup/templates/default/gc-err-subject.txt.hbs
|
usr/share/proxmox-backup/templates/default/gc-err-subject.txt.hbs
|
||||||
usr/share/proxmox-backup/templates/default/gc-ok-subject.txt.hbs
|
usr/share/proxmox-backup/templates/default/gc-ok-subject.txt.hbs
|
||||||
|
usr/share/proxmox-backup/templates/default/package-updates-body.txt.hbs
|
||||||
|
usr/share/proxmox-backup/templates/default/package-updates-subject.txt.hbs
|
||||||
usr/share/proxmox-backup/templates/default/prune-err-body.txt.hbs
|
usr/share/proxmox-backup/templates/default/prune-err-body.txt.hbs
|
||||||
usr/share/proxmox-backup/templates/default/prune-ok-body.txt.hbs
|
usr/share/proxmox-backup/templates/default/prune-ok-body.txt.hbs
|
||||||
usr/share/proxmox-backup/templates/default/prune-err-subject.txt.hbs
|
usr/share/proxmox-backup/templates/default/prune-err-subject.txt.hbs
|
||||||
|
@ -23,18 +23,6 @@ use proxmox_notify::{Endpoint, Notification, Severity};
|
|||||||
|
|
||||||
const SPOOL_DIR: &str = concatcp!(pbs_buildcfg::PROXMOX_BACKUP_STATE_DIR, "/notifications");
|
const SPOOL_DIR: &str = concatcp!(pbs_buildcfg::PROXMOX_BACKUP_STATE_DIR, "/notifications");
|
||||||
|
|
||||||
const PACKAGE_UPDATES_TEMPLATE: &str = r###"
|
|
||||||
Proxmox Backup Server has the following updates available:
|
|
||||||
{{#each updates }}
|
|
||||||
{{Package}}: {{OldVersion}} -> {{Version~}}
|
|
||||||
{{/each }}
|
|
||||||
|
|
||||||
To upgrade visit the web interface:
|
|
||||||
|
|
||||||
<https://{{fqdn}}:{{port}}/#pbsServerAdministration:updates>
|
|
||||||
|
|
||||||
"###;
|
|
||||||
|
|
||||||
const TAPE_BACKUP_OK_TEMPLATE: &str = r###"
|
const TAPE_BACKUP_OK_TEMPLATE: &str = r###"
|
||||||
|
|
||||||
{{#if id ~}}
|
{{#if id ~}}
|
||||||
@ -122,8 +110,6 @@ lazy_static::lazy_static! {
|
|||||||
hb.register_template_string("tape_backup_ok_template", TAPE_BACKUP_OK_TEMPLATE)?;
|
hb.register_template_string("tape_backup_ok_template", TAPE_BACKUP_OK_TEMPLATE)?;
|
||||||
hb.register_template_string("tape_backup_err_template", TAPE_BACKUP_ERR_TEMPLATE)?;
|
hb.register_template_string("tape_backup_err_template", TAPE_BACKUP_ERR_TEMPLATE)?;
|
||||||
|
|
||||||
hb.register_template_string("package_update_template", PACKAGE_UPDATES_TEMPLATE)?;
|
|
||||||
|
|
||||||
hb.register_template_string("certificate_renewal_err_template", ACME_CERTIFICATE_ERR_RENEWAL)?;
|
hb.register_template_string("certificate_renewal_err_template", ACME_CERTIFICATE_ERR_RENEWAL)?;
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
@ -583,24 +569,25 @@ fn get_server_url() -> (String, usize) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn send_updates_available(updates: &[&APTUpdateInfo]) -> Result<(), Error> {
|
pub fn send_updates_available(updates: &[&APTUpdateInfo]) -> Result<(), Error> {
|
||||||
// update mails always go to the root@pam configured email..
|
|
||||||
if let Some(email) = lookup_user_email(Userid::root_userid()) {
|
|
||||||
let nodename = proxmox_sys::nodename();
|
|
||||||
let subject = format!("New software packages available ({nodename})");
|
|
||||||
|
|
||||||
let (fqdn, port) = get_server_url();
|
let (fqdn, port) = get_server_url();
|
||||||
|
let hostname = proxmox_sys::nodename().to_string();
|
||||||
|
|
||||||
let text = HANDLEBARS.render(
|
let data = json!({
|
||||||
"package_update_template",
|
|
||||||
&json!({
|
|
||||||
"fqdn": fqdn,
|
"fqdn": fqdn,
|
||||||
|
"hostname": &hostname,
|
||||||
"port": port,
|
"port": port,
|
||||||
"updates": updates,
|
"updates": updates,
|
||||||
}),
|
});
|
||||||
)?;
|
|
||||||
|
|
||||||
send_job_status_mail(&email, &subject, &text)?;
|
let metadata = HashMap::from([
|
||||||
}
|
("hostname".into(), hostname),
|
||||||
|
("type".into(), "package-updates".into()),
|
||||||
|
]);
|
||||||
|
|
||||||
|
let notification =
|
||||||
|
Notification::from_template(Severity::Info, "package-updates", data, metadata);
|
||||||
|
|
||||||
|
send_notification(notification)?;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -687,7 +674,5 @@ fn test_template_register() {
|
|||||||
assert!(HANDLEBARS.has_template("tape_backup_ok_template"));
|
assert!(HANDLEBARS.has_template("tape_backup_ok_template"));
|
||||||
assert!(HANDLEBARS.has_template("tape_backup_err_template"));
|
assert!(HANDLEBARS.has_template("tape_backup_err_template"));
|
||||||
|
|
||||||
assert!(HANDLEBARS.has_template("package_update_template"));
|
|
||||||
|
|
||||||
assert!(HANDLEBARS.has_template("certificate_renewal_err_template"));
|
assert!(HANDLEBARS.has_template("certificate_renewal_err_template"));
|
||||||
}
|
}
|
||||||
|
@ -5,6 +5,8 @@ NOTIFICATION_TEMPLATES= \
|
|||||||
default/gc-ok-body.txt.hbs \
|
default/gc-ok-body.txt.hbs \
|
||||||
default/gc-err-subject.txt.hbs \
|
default/gc-err-subject.txt.hbs \
|
||||||
default/gc-ok-subject.txt.hbs \
|
default/gc-ok-subject.txt.hbs \
|
||||||
|
default/package-updates-body.txt.hbs \
|
||||||
|
default/package-updates-subject.txt.hbs \
|
||||||
default/prune-err-body.txt.hbs \
|
default/prune-err-body.txt.hbs \
|
||||||
default/prune-ok-body.txt.hbs \
|
default/prune-ok-body.txt.hbs \
|
||||||
default/prune-err-subject.txt.hbs \
|
default/prune-err-subject.txt.hbs \
|
||||||
|
8
templates/default/package-updates-body.txt.hbs
Normal file
8
templates/default/package-updates-body.txt.hbs
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
Proxmox Backup Server has the following updates available:
|
||||||
|
{{#each updates }}
|
||||||
|
{{Package}}: {{OldVersion}} -> {{Version~}}
|
||||||
|
{{/each }}
|
||||||
|
|
||||||
|
To upgrade visit the web interface:
|
||||||
|
|
||||||
|
<https://{{fqdn}}:{{port}}/#pbsServerAdministration:updates>
|
1
templates/default/package-updates-subject.txt.hbs
Normal file
1
templates/default/package-updates-subject.txt.hbs
Normal file
@ -0,0 +1 @@
|
|||||||
|
New software packages available ({{ hostname }})
|
Loading…
Reference in New Issue
Block a user