From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by lists.proxmox.com (Postfix) with ESMTPS id 11FC19573A for ; Fri, 12 Apr 2024 12:14:31 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id E000E8239 for ; Fri, 12 Apr 2024 12:14:00 +0200 (CEST) Received: from proxmox-new.maurer-it.com (proxmox-new.maurer-it.com [94.136.29.106]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by firstgate.proxmox.com (Proxmox) with ESMTPS for ; Fri, 12 Apr 2024 12:13:59 +0200 (CEST) Received: from proxmox-new.maurer-it.com (localhost.localdomain [127.0.0.1]) by proxmox-new.maurer-it.com (Proxmox) with ESMTP id 462E645198 for ; Fri, 12 Apr 2024 12:06:44 +0200 (CEST) From: Lukas Wagner To: pbs-devel@lists.proxmox.com Date: Fri, 12 Apr 2024 12:06:28 +0200 Message-Id: <20240412100631.94218-31-l.wagner@proxmox.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240412100631.94218-1-l.wagner@proxmox.com> References: <20240412100631.94218-1-l.wagner@proxmox.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SPAM-LEVEL: Spam detection results: 0 AWL -0.005 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 URIBL_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to URIBL was blocked. See http://wiki.apache.org/spamassassin/DnsBlocklists#dnsbl-block for more information. [matchers.rs, mod.rs] Subject: [pbs-devel] [PATCH proxmox-backup 30/33] proxmox-backup-manager: add CLI for notification matchers 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: , X-List-Received-Date: Fri, 12 Apr 2024 10:14:31 -0000 Signed-off-by: Lukas Wagner --- .../notifications/matchers.rs | 93 +++++++++++++++++++ .../notifications/mod.rs | 5 +- 2 files changed, 97 insertions(+), 1 deletion(-) create mode 100644 src/bin/proxmox_backup_manager/notifications/matchers.rs diff --git a/src/bin/proxmox_backup_manager/notifications/matchers.rs b/src/bin/proxmox_backup_manager/notifications/matchers.rs new file mode 100644 index 00000000..cfa3aaa4 --- /dev/null +++ b/src/bin/proxmox_backup_manager/notifications/matchers.rs @@ -0,0 +1,93 @@ +use anyhow::Error; +use proxmox_notify::schema::ENTITY_NAME_SCHEMA; +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 notification matchers. +fn list_matchers(param: Value, rpcenv: &mut dyn RpcEnvironment) -> Result { + let output_format = get_output_format(¶m); + + let info = &api2::config::notifications::matchers::API_METHOD_LIST_MATCHERS; + 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("origin")) + .column(ColumnConfig::new("comment")); + + format_and_print_result_full(&mut data, &info.returns, &output_format, &options); + + Ok(Value::Null) +} + +#[api( + input: { + properties: { + name: { + schema: ENTITY_NAME_SCHEMA, + }, + "output-format": { + schema: OUTPUT_FORMAT, + optional: true, + }, + } + } +)] +/// Show a single matcher. +fn show_matcher(param: Value, rpcenv: &mut dyn RpcEnvironment) -> Result { + let output_format = get_output_format(¶m); + + let info = &api2::config::notifications::matchers::API_METHOD_GET_MATCHER; + let mut data = match info.handler { + ApiHandler::Sync(handler) => (handler)(param, info, rpcenv)?, + _ => unreachable!(), + }; + + let options = default_table_format_options(); + 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_MATCHERS)) + .insert( + "show", + CliCommand::new(&API_METHOD_SHOW_MATCHER).arg_param(&["name"]), + ) + .insert( + "create", + CliCommand::new(&api2::config::notifications::matchers::API_METHOD_ADD_MATCHER) + .arg_param(&["name"]), + ) + .insert( + "update", + CliCommand::new(&api2::config::notifications::matchers::API_METHOD_UPDATE_MATCHER) + .arg_param(&["name"]), + ) + .insert( + "delete", + CliCommand::new(&api2::config::notifications::matchers::API_METHOD_DELETE_MATCHER) + .arg_param(&["name"]), + ); + cmd_def.into() +} diff --git a/src/bin/proxmox_backup_manager/notifications/mod.rs b/src/bin/proxmox_backup_manager/notifications/mod.rs index fdd5abe3..d83563f5 100644 --- a/src/bin/proxmox_backup_manager/notifications/mod.rs +++ b/src/bin/proxmox_backup_manager/notifications/mod.rs @@ -1,9 +1,12 @@ use proxmox_router::cli::{CliCommandMap, CommandLineInterface}; +mod matchers; mod targets; pub fn notification_commands() -> CommandLineInterface { - let cmd_def = CliCommandMap::new().insert("target", targets::commands()); + let cmd_def = CliCommandMap::new() + .insert("target", targets::commands()) + .insert("matcher", matchers::commands()); cmd_def.into() } -- 2.39.2