mirror of
				https://git.proxmox.com/git/proxmox-perl-rs
				synced 2025-11-04 06:08:40 +00:00 
			
		
		
		
	notify: add api for sending notifications/testing endpoints
Signed-off-by: Lukas Wagner <l.wagner@proxmox.com>
This commit is contained in:
		
							parent
							
								
									b9c4756445
								
							
						
					
					
						commit
						350cdd6b59
					
				@ -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, ¬ification)
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    #[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)
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
		Loading…
	
		Reference in New Issue
	
	Block a user