From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [IPv6:2a01:7e0:0:424::9]) by lore.proxmox.com (Postfix) with ESMTPS id 125751FF56B for ; Mon, 22 Apr 2024 09:57:47 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 41B40A4F5; Mon, 22 Apr 2024 09:57:48 +0200 (CEST) From: Lukas Wagner To: pbs-devel@lists.proxmox.com Date: Mon, 22 Apr 2024 09:50:23 +0200 Message-Id: <20240422075030.73895-36-l.wagner@proxmox.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240422075030.73895-1-l.wagner@proxmox.com> References: <20240422075030.73895-1-l.wagner@proxmox.com> MIME-Version: 1.0 X-SPAM-LEVEL: Spam detection results: 0 AWL 0.000 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 SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record Subject: [pbs-devel] [PATCH proxmox-backup v3 35/42] proxmox-backup-manager: add CLI for notification targets X-BeenThere: pbs-devel@lists.proxmox.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Proxmox Backup Server development discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: Proxmox Backup Server development discussion Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: pbs-devel-bounces@lists.proxmox.com Sender: "pbs-devel" Signed-off-by: Lukas Wagner Tested-by: Gabriel Goller Reviewed-by: Gabriel Goller --- src/api2/config/notifications/mod.rs | 10 ++-- src/bin/proxmox-backup-manager.rs | 2 + src/bin/proxmox_backup_manager/mod.rs | 2 + .../notifications/mod.rs | 9 ++++ .../notifications/targets.rs | 51 +++++++++++++++++++ 5 files changed, 69 insertions(+), 5 deletions(-) create mode 100644 src/bin/proxmox_backup_manager/notifications/mod.rs create mode 100644 src/bin/proxmox_backup_manager/notifications/targets.rs diff --git a/src/api2/config/notifications/mod.rs b/src/api2/config/notifications/mod.rs index 804626b0..b5589407 100644 --- a/src/api2/config/notifications/mod.rs +++ b/src/api2/config/notifications/mod.rs @@ -17,11 +17,11 @@ use crate::api2::config::datastore::list_datastores; use crate::api2::config::media_pool::list_pools; use crate::api2::tape::backup::list_tape_backup_jobs; -mod gotify; -mod matchers; -mod sendmail; -mod smtp; -mod targets; +pub mod gotify; +pub mod matchers; +pub mod sendmail; +pub mod smtp; +pub mod targets; #[sortable] const SUBDIRS: SubdirMap = &sorted!([ diff --git a/src/bin/proxmox-backup-manager.rs b/src/bin/proxmox-backup-manager.rs index 115207f3..132de290 100644 --- a/src/bin/proxmox-backup-manager.rs +++ b/src/bin/proxmox-backup-manager.rs @@ -430,6 +430,7 @@ async fn get_versions(verbose: bool, param: Value) -> Result { async fn run() -> Result<(), Error> { init_cli_logger("PBS_LOG", "info"); + proxmox_backup::server::notifications::init()?; let cmd_def = CliCommandMap::new() .insert("acl", acl_commands()) @@ -439,6 +440,7 @@ async fn run() -> Result<(), Error> { .insert("ldap", ldap_commands()) .insert("network", network_commands()) .insert("node", node_commands()) + .insert("notification", notification_commands()) .insert("user", user_commands()) .insert("openid", openid_commands()) .insert("remote", remote_commands()) diff --git a/src/bin/proxmox_backup_manager/mod.rs b/src/bin/proxmox_backup_manager/mod.rs index 8a1c140c..8992a7a7 100644 --- a/src/bin/proxmox_backup_manager/mod.rs +++ b/src/bin/proxmox_backup_manager/mod.rs @@ -28,6 +28,8 @@ mod disk; pub use disk::*; mod node; pub use node::*; +mod notifications; +pub use notifications::*; mod openid; pub use openid::*; mod traffic_control; diff --git a/src/bin/proxmox_backup_manager/notifications/mod.rs b/src/bin/proxmox_backup_manager/notifications/mod.rs new file mode 100644 index 00000000..fdd5abe3 --- /dev/null +++ b/src/bin/proxmox_backup_manager/notifications/mod.rs @@ -0,0 +1,9 @@ +use proxmox_router::cli::{CliCommandMap, CommandLineInterface}; + +mod targets; + +pub fn notification_commands() -> CommandLineInterface { + let cmd_def = CliCommandMap::new().insert("target", targets::commands()); + + cmd_def.into() +} diff --git a/src/bin/proxmox_backup_manager/notifications/targets.rs b/src/bin/proxmox_backup_manager/notifications/targets.rs new file mode 100644 index 00000000..37603a92 --- /dev/null +++ b/src/bin/proxmox_backup_manager/notifications/targets.rs @@ -0,0 +1,51 @@ +use anyhow::Error; +use serde_json::Value; + +use proxmox_router::{cli::*, ApiHandler, RpcEnvironment}; +use proxmox_schema::api; + +use proxmox_backup::api2; + +#[api( + input: { + properties: { + "output-format": { + schema: OUTPUT_FORMAT, + optional: true, + }, + } + } +)] +/// List targets. +fn list_targets(param: Value, rpcenv: &mut dyn RpcEnvironment) -> Result { + let output_format = get_output_format(¶m); + + let info = &api2::config::notifications::targets::API_METHOD_LIST_TARGETS; + let mut data = match info.handler { + ApiHandler::Sync(handler) => (handler)(param, info, rpcenv)?, + _ => unreachable!(), + }; + + let options = default_table_format_options() + .column(ColumnConfig::new("disable")) + .column(ColumnConfig::new("name")) + .column(ColumnConfig::new("type")) + .column(ColumnConfig::new("origin")) + .column(ColumnConfig::new("comment")); + + format_and_print_result_full(&mut data, &info.returns, &output_format, &options); + + Ok(Value::Null) +} + +pub fn commands() -> CommandLineInterface { + let cmd_def = CliCommandMap::new() + .insert("list", CliCommand::new(&API_METHOD_LIST_TARGETS)) + .insert( + "test", + CliCommand::new(&api2::config::notifications::targets::API_METHOD_TEST_TARGET) + .arg_param(&["name"]), + ); + + cmd_def.into() +} -- 2.39.2 _______________________________________________ pbs-devel mailing list pbs-devel@lists.proxmox.com https://lists.proxmox.com/cgi-bin/mailman/listinfo/pbs-devel