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 3FFA971302 for ; Wed, 8 Jun 2022 14:23:13 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 2BA667D07 for ; Wed, 8 Jun 2022 14:22:43 +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 id A6B5C7CCE for ; Wed, 8 Jun 2022 14:22:39 +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 75BCF43A8D for ; Wed, 8 Jun 2022 14:22:39 +0200 (CEST) From: Dominik Csapak To: pbs-devel@lists.proxmox.com Date: Wed, 8 Jun 2022 14:22:32 +0200 Message-Id: <20220608122238.3490889-2-d.csapak@proxmox.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220608122238.3490889-1-d.csapak@proxmox.com> References: <20220608122238.3490889-1-d.csapak@proxmox.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SPAM-LEVEL: Spam detection results: 0 AWL 0.104 Adjusted score from AWL reputation of From: address BAYES_00 -1.9 Bayes spam probability is 0 to 1% 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 T_SCC_BODY_TEXT_LINE -0.01 - URIBL_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to URIBL was blocked. See http://wiki.apache.org/spamassassin/DnsBlocklists#dnsbl-block for more information. [metrics.rs, lib.rs] Subject: [pbs-devel] [PATCH proxmox-backup v8 1/7] pbs-api-types: add metrics api types 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: Wed, 08 Jun 2022 12:23:13 -0000 InfluxDbUdp and InfluxDbHttp for now introduces schemas for host:port and https urls Signed-off-by: Dominik Csapak --- pbs-api-types/src/lib.rs | 17 +++++ pbs-api-types/src/metrics.rs | 138 +++++++++++++++++++++++++++++++++++ 2 files changed, 155 insertions(+) create mode 100644 pbs-api-types/src/metrics.rs diff --git a/pbs-api-types/src/lib.rs b/pbs-api-types/src/lib.rs index d9c8cee1..70c9ec45 100644 --- a/pbs-api-types/src/lib.rs +++ b/pbs-api-types/src/lib.rs @@ -120,6 +120,9 @@ pub use traffic_control::*; mod zfs; pub use zfs::*; +mod metrics; +pub use metrics::*; + #[rustfmt::skip] #[macro_use] mod local_macros { @@ -131,6 +134,7 @@ mod local_macros { macro_rules! DNS_ALIAS_NAME { () => (concat!(r"(?:(?:", DNS_ALIAS_LABEL!() , r"\.)*", DNS_ALIAS_LABEL!(), ")")) } + macro_rules! PORT_REGEX_STR { () => (r"(?:[0-9]{1,4}|[1-5][0-9]{4}|6[0-4][0-9]{3}|65[0-4][0-9]{2}|655[0-2][0-9]|6553[0-5])") } } const_regex! { @@ -144,6 +148,8 @@ const_regex! { pub DNS_NAME_REGEX = concat!(r"^", DNS_NAME!(), r"$"); pub DNS_ALIAS_REGEX = concat!(r"^", DNS_ALIAS_NAME!(), r"$"); pub DNS_NAME_OR_IP_REGEX = concat!(r"^(?:", DNS_NAME!(), "|", IPRE!(), r")$"); + pub HOST_PORT_REGEX = concat!(r"^(?:", DNS_NAME!(), "|", IPRE_BRACKET!(), "):", PORT_REGEX_STR!() ,"$"); + pub HTTP_URL_REGEX = concat!(r"^https?://(?:(?:(?:", DNS_NAME!(), "|", IPRE_BRACKET!(), ")(?::", PORT_REGEX_STR!() ,")?)|", IPV6RE!(),")(?:/[^\x00-\x1F\x7F]*)?$"); pub SHA256_HEX_REGEX = r"^[a-f0-9]{64}$"; // fixme: define in common_regex ? @@ -201,6 +207,8 @@ pub const SYSTEMD_DATETIME_FORMAT: ApiStringFormat = pub const HOSTNAME_FORMAT: ApiStringFormat = ApiStringFormat::Pattern(&HOSTNAME_REGEX); pub const OPENSSL_CIPHERS_TLS_FORMAT: ApiStringFormat = ApiStringFormat::Pattern(&OPENSSL_CIPHERS_REGEX); +pub const HOST_PORT_FORMAT: ApiStringFormat = ApiStringFormat::Pattern(&HOST_PORT_REGEX); +pub const HTTP_URL_FORMAT: ApiStringFormat = ApiStringFormat::Pattern(&HTTP_URL_REGEX); pub const DNS_ALIAS_FORMAT: ApiStringFormat = ApiStringFormat::Pattern(&DNS_ALIAS_REGEX); @@ -244,6 +252,15 @@ pub const DNS_NAME_OR_IP_SCHEMA: Schema = StringSchema::new("DNS name or IP addr .format(&DNS_NAME_OR_IP_FORMAT) .schema(); +pub const HOST_PORT_SCHEMA: Schema = + StringSchema::new("host:port combination (Host can be DNS name or IP address).") + .format(&HOST_PORT_FORMAT) + .schema(); + +pub const HTTP_URL_SCHEMA: Schema = StringSchema::new("HTTP(s) url with optional port.") + .format(&HTTP_URL_FORMAT) + .schema(); + pub const NODE_SCHEMA: Schema = StringSchema::new("Node name (or 'localhost')") .format(&HOSTNAME_FORMAT) .schema(); diff --git a/pbs-api-types/src/metrics.rs b/pbs-api-types/src/metrics.rs new file mode 100644 index 00000000..239d6c80 --- /dev/null +++ b/pbs-api-types/src/metrics.rs @@ -0,0 +1,138 @@ +use serde::{Deserialize, Serialize}; + +use crate::{ + HOST_PORT_SCHEMA, HTTP_URL_SCHEMA, PROXMOX_SAFE_ID_FORMAT, SINGLE_LINE_COMMENT_SCHEMA, +}; +use proxmox_schema::{api, Schema, StringSchema, Updater}; + +pub const METRIC_SERVER_ID_SCHEMA: Schema = StringSchema::new("Metrics Server ID.") + .format(&PROXMOX_SAFE_ID_FORMAT) + .min_length(3) + .max_length(32) + .schema(); + +pub const INFLUXDB_BUCKET_SCHEMA: Schema = StringSchema::new("InfluxDB Bucket.") + .format(&PROXMOX_SAFE_ID_FORMAT) + .min_length(3) + .max_length(32) + .default("proxmox") + .schema(); + +pub const INFLUXDB_ORGANIZATION_SCHEMA: Schema = StringSchema::new("InfluxDB Organization.") + .format(&PROXMOX_SAFE_ID_FORMAT) + .min_length(3) + .max_length(32) + .default("proxmox") + .schema(); + +#[api( + properties: { + name: { + schema: METRIC_SERVER_ID_SCHEMA, + }, + enable: { + type: bool, + optional: true, + default: true, + }, + host: { + schema: HOST_PORT_SCHEMA, + }, + mtu: { + type: u16, + optional: true, + default: 1500, + }, + comment: { + optional: true, + schema: SINGLE_LINE_COMMENT_SCHEMA, + }, + }, +)] +#[derive(Serialize, Deserialize, Updater)] +#[serde(rename_all = "kebab-case")] +/// InfluxDB Server (UDP) +pub struct InfluxDbUdp { + #[updater(skip)] + pub name: String, + #[serde(skip_serializing_if = "Option::is_none")] + /// Enables or disables the metrics server + pub enable: Option, + /// the host + port + pub host: String, + #[serde(skip_serializing_if = "Option::is_none")] + /// The MTU + pub mtu: Option, + #[serde(skip_serializing_if = "Option::is_none")] + pub comment: Option, +} + +#[api( + properties: { + name: { + schema: METRIC_SERVER_ID_SCHEMA, + }, + enable: { + type: bool, + optional: true, + default: true, + }, + url: { + schema: HTTP_URL_SCHEMA, + }, + token: { + type: String, + optional: true, + }, + bucket: { + schema: INFLUXDB_BUCKET_SCHEMA, + optional: true, + }, + organization: { + schema: INFLUXDB_ORGANIZATION_SCHEMA, + optional: true, + }, + "max-body-size": { + type: usize, + optional: true, + default: 25_000_000, + }, + "verify-tls": { + type: bool, + optional: true, + default: true, + }, + comment: { + optional: true, + schema: SINGLE_LINE_COMMENT_SCHEMA, + }, + }, +)] +#[derive(Serialize, Deserialize, Updater)] +#[serde(rename_all = "kebab-case")] +/// InfluxDB Server (HTTP(s)) +pub struct InfluxDbHttp { + #[updater(skip)] + pub name: String, + #[serde(skip_serializing_if = "Option::is_none")] + /// Enables or disables the metrics server + pub enable: Option, + /// The base url of the influxdb server + pub url: String, + /// The Optional Token + #[serde(skip_serializing_if = "Option::is_none")] + /// The (optional) API token + pub token: Option, + #[serde(skip_serializing_if = "Option::is_none")] + pub bucket: Option, + #[serde(skip_serializing_if = "Option::is_none")] + pub organization: Option, + #[serde(skip_serializing_if = "Option::is_none")] + /// The (optional) maximum body size + pub max_body_size: Option, + #[serde(skip_serializing_if = "Option::is_none")] + /// If true, the certificate will be validated. + pub verify_tls: Option, + #[serde(skip_serializing_if = "Option::is_none")] + pub comment: Option, +} -- 2.30.2