]> git.proxmox.com Git - proxmox-perl-rs.git/commitdiff
notify: add api for sending notifications/testing endpoints
authorLukas Wagner <l.wagner@proxmox.com>
Thu, 20 Jul 2023 14:31:54 +0000 (16:31 +0200)
committerWolfgang Bumiller <w.bumiller@proxmox.com>
Mon, 24 Jul 2023 09:17:33 +0000 (11:17 +0200)
Signed-off-by: Lukas Wagner <l.wagner@proxmox.com>
pve-rs/src/notify.rs

index 6ea9b789e05c9ca674766fbee2e19924456e705e..cff1b4453fa31047c37f0c41890b63abd93b7029 100644 (file)
@@ -2,10 +2,10 @@
 mod export {
     use anyhow::{bail, Error};
     use perlmod::Value;
-
+    use serde_json::Value as JSONValue;
     use std::sync::Mutex;
 
-    use proxmox_notify::Config;
+    use proxmox_notify::{api, api::ApiError, Config, Notification, Severity};
 
     pub struct NotificationConfig {
         config: Mutex<Config>,
@@ -71,4 +71,34 @@ mod export {
         let config = this.config.lock().unwrap();
         hex::encode(config.digest())
     }
+
+    #[export(serialize_error)]
+    fn send(
+        #[try_from_ref] this: &NotificationConfig,
+        channel: &str,
+        severity: Severity,
+        title: String,
+        body: String,
+        properties: Option<JSONValue>,
+    ) -> Result<(), ApiError> {
+        let config = this.config.lock().unwrap();
+
+        let notification = Notification {
+            severity,
+            title,
+            body,
+            properties,
+        };
+
+        api::common::send(&config, channel, &notification)
+    }
+
+    #[export(serialize_error)]
+    fn test_target(
+        #[try_from_ref] this: &NotificationConfig,
+        target: &str,
+    ) -> Result<(), ApiError> {
+        let config = this.config.lock().unwrap();
+        api::common::test_target(&config, target)
+    }
 }