[pve-devel] [PATCH pve-manager 11/18] add PVE::Notification module
Lukas Wagner
l.wagner at proxmox.com
Mon Mar 27 17:18:50 CEST 2023
The PVE::Notification is a very thin wrapper around the
Proxmox::RS::Notification module, feeding the configuration from the
new 'notifications.cfg' file into it as a raw string.
Signed-off-by: Lukas Wagner <l.wagner at proxmox.com>
---
PVE/Makefile | 1 +
PVE/Notification.pm | 60 +++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 61 insertions(+)
create mode 100644 PVE/Notification.pm
diff --git a/PVE/Makefile b/PVE/Makefile
index 48b85d33..0501b204 100644
--- a/PVE/Makefile
+++ b/PVE/Makefile
@@ -13,6 +13,7 @@ PERLSOURCE = \
HTTPServer.pm \
Jobs.pm \
NodeConfig.pm \
+ Notification.pm \
Report.pm \
VZDump.pm
diff --git a/PVE/Notification.pm b/PVE/Notification.pm
new file mode 100644
index 00000000..9933c4de
--- /dev/null
+++ b/PVE/Notification.pm
@@ -0,0 +1,60 @@
+package PVE::Notification;
+
+use strict;
+use warnings;
+
+use PVE::Cluster;
+use Proxmox::RS::Notification;
+
+PVE::Cluster::cfs_register_file(
+ 'notifications.cfg',
+ \&parse_notification_config,
+ \&write_notification_config,
+);
+
+sub parse_notification_config {
+ my ($filename, $raw) = @_;
+
+ $raw = '' if !defined($raw);
+ my $config = Proxmox::RS::Notification->new($raw);
+
+ return $config;
+}
+
+sub write_notification_config {
+ my ($filename, $config) = @_;
+
+ return $config->write();
+}
+
+sub config {
+ return PVE::Cluster::cfs_read_file('notifications.cfg');
+}
+
+sub send_notification {
+ my ($severity, $title, $message, $properties, $config) = @_;
+ $config = config() if !defined($config);
+ $config->send($severity, $title, $message, $properties);
+}
+
+sub info {
+ my ($title, $message, $config) = @_;
+ send_notification("info", $title, $message, undef, $config);
+}
+
+sub notice {
+ my ($title, $message, $config) = @_;
+ send_notification("notice", $title, $message, undef, $config);
+}
+
+sub warning {
+ my ($title, $message, $config) = @_;
+ send_notification("warning", $title, $message, undef, $config);
+}
+
+sub error {
+ my ($title, $message, $config) = @_;
+ send_notification("error", $title, $message, undef, $config);
+}
+
+1;
--
2.30.2
More information about the pve-devel
mailing list