mirror of
https://git.proxmox.com/git/proxmox
synced 2025-06-14 19:19:12 +00:00
pbs-api-types: add metrics api types
InfluxDbUdp and InfluxDbHttp for now introduces schemas for host:port and https urls Signed-off-by: Dominik Csapak <d.csapak@proxmox.com> Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
This commit is contained in:
parent
2ec6f86f63
commit
57fa204064
@ -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();
|
||||
|
148
pbs-api-types/src/metrics.rs
Normal file
148
pbs-api-types/src/metrics.rs
Normal file
@ -0,0 +1,148 @@
|
||||
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();
|
||||
|
||||
fn return_true() -> bool {
|
||||
true
|
||||
}
|
||||
|
||||
fn is_true(b: &bool) -> bool {
|
||||
*b
|
||||
}
|
||||
|
||||
#[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(default = "return_true", skip_serializing_if = "is_true")]
|
||||
#[updater(serde(skip_serializing_if = "Option::is_none"))]
|
||||
/// Enables or disables the metrics server
|
||||
pub enable: bool,
|
||||
/// the host + port
|
||||
pub host: String,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
/// The MTU
|
||||
pub mtu: Option<u16>,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub comment: Option<String>,
|
||||
}
|
||||
|
||||
#[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(default = "return_true", skip_serializing_if = "is_true")]
|
||||
#[updater(serde(skip_serializing_if = "Option::is_none"))]
|
||||
/// Enables or disables the metrics server
|
||||
pub enable: bool,
|
||||
/// 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<String>,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub bucket: Option<String>,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub organization: Option<String>,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
/// The (optional) maximum body size
|
||||
pub max_body_size: Option<usize>,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
/// If true, the certificate will be validated.
|
||||
pub verify_tls: Option<bool>,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub comment: Option<String>,
|
||||
}
|
Loading…
Reference in New Issue
Block a user