use crate::client::RestClient;
use crate::error::Result;
use serde::{Deserialize, Serialize};
use serde_json::Value;
use std::collections::HashMap;
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Alert {
pub uid: String,
pub name: String,
pub severity: String,
pub state: String,
#[serde(skip_serializing_if = "Option::is_none")]
pub entity_type: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub entity_name: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub entity_uid: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub threshold: Option<Value>,
#[serde(skip_serializing_if = "Option::is_none")]
pub change_time: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub change_value: Option<Value>,
#[serde(skip_serializing_if = "Option::is_none")]
pub description: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub error_code: Option<String>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ClusterAlertState {
pub enabled: bool,
pub state: bool,
pub severity: String,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub change_time: Option<String>,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub change_value: Option<Value>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct AlertSettings {
pub enabled: bool,
#[serde(skip_serializing_if = "Option::is_none")]
pub threshold: Option<Value>,
#[serde(skip_serializing_if = "Option::is_none")]
pub email_recipients: Option<Vec<String>>,
#[serde(skip_serializing_if = "Option::is_none")]
pub webhook_url: Option<String>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct BdbAlertSettingsWithThreshold {
pub enabled: bool,
pub threshold: String,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct DbAlertsSettings {
#[serde(skip_serializing_if = "Option::is_none")]
pub bdb_backup_delayed: Option<BdbAlertSettingsWithThreshold>,
#[serde(skip_serializing_if = "Option::is_none")]
pub bdb_crdt_src_high_syncer_lag: Option<BdbAlertSettingsWithThreshold>,
#[serde(skip_serializing_if = "Option::is_none")]
pub bdb_crdt_src_syncer_connection_error: Option<BdbAlertSettingsWithThreshold>,
#[serde(skip_serializing_if = "Option::is_none")]
pub bdb_crdt_src_syncer_general_error: Option<BdbAlertSettingsWithThreshold>,
#[serde(skip_serializing_if = "Option::is_none")]
pub bdb_high_latency: Option<BdbAlertSettingsWithThreshold>,
#[serde(skip_serializing_if = "Option::is_none")]
pub bdb_high_syncer_lag: Option<BdbAlertSettingsWithThreshold>,
#[serde(skip_serializing_if = "Option::is_none")]
pub bdb_high_throughput: Option<BdbAlertSettingsWithThreshold>,
#[serde(skip_serializing_if = "Option::is_none")]
pub bdb_long_running_action: Option<BdbAlertSettingsWithThreshold>,
#[serde(skip_serializing_if = "Option::is_none")]
pub bdb_low_throughput: Option<BdbAlertSettingsWithThreshold>,
#[serde(skip_serializing_if = "Option::is_none")]
pub bdb_ram_dataset_overhead: Option<BdbAlertSettingsWithThreshold>,
#[serde(skip_serializing_if = "Option::is_none")]
pub bdb_ram_values: Option<BdbAlertSettingsWithThreshold>,
#[serde(skip_serializing_if = "Option::is_none")]
pub bdb_replica_src_high_syncer_lag: Option<BdbAlertSettingsWithThreshold>,
#[serde(skip_serializing_if = "Option::is_none")]
pub bdb_replica_src_syncer_connection_error: Option<BdbAlertSettingsWithThreshold>,
#[serde(skip_serializing_if = "Option::is_none")]
pub bdb_replica_src_syncer_general_error: Option<BdbAlertSettingsWithThreshold>,
#[serde(skip_serializing_if = "Option::is_none")]
pub bdb_shard_num_ram_values: Option<BdbAlertSettingsWithThreshold>,
#[serde(skip_serializing_if = "Option::is_none")]
pub bdb_size: Option<BdbAlertSettingsWithThreshold>,
#[serde(skip_serializing_if = "Option::is_none")]
pub bdb_syncer_connection_error: Option<BdbAlertSettingsWithThreshold>,
#[serde(skip_serializing_if = "Option::is_none")]
pub bdb_syncer_general_error: Option<BdbAlertSettingsWithThreshold>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ClusterAlertSettingsWithThreshold {
pub enabled: bool,
pub threshold: String,
#[serde(skip_serializing_if = "Option::is_none")]
pub email: Option<Vec<String>>,
#[serde(skip_serializing_if = "Option::is_none")]
pub webhook_url: Option<String>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ClusterAlertsSettings {
#[serde(skip_serializing_if = "Option::is_none")]
pub cluster_ca_cert_about_to_expire: Option<ClusterAlertSettingsWithThreshold>,
#[serde(skip_serializing_if = "Option::is_none")]
pub cluster_certs_about_to_expire: Option<ClusterAlertSettingsWithThreshold>,
#[serde(skip_serializing_if = "Option::is_none")]
pub cluster_license_about_to_expire: Option<ClusterAlertSettingsWithThreshold>,
#[serde(skip_serializing_if = "Option::is_none")]
pub node_cpu_utilization: Option<ClusterAlertSettingsWithThreshold>,
#[serde(skip_serializing_if = "Option::is_none")]
pub node_ephemeral_storage: Option<ClusterAlertSettingsWithThreshold>,
#[serde(skip_serializing_if = "Option::is_none")]
pub node_free_flash: Option<ClusterAlertSettingsWithThreshold>,
#[serde(skip_serializing_if = "Option::is_none")]
pub node_internal_certs_about_to_expire: Option<ClusterAlertSettingsWithThreshold>,
#[serde(skip_serializing_if = "Option::is_none")]
pub node_memory: Option<ClusterAlertSettingsWithThreshold>,
#[serde(skip_serializing_if = "Option::is_none")]
pub node_net_throughput: Option<ClusterAlertSettingsWithThreshold>,
#[serde(skip_serializing_if = "Option::is_none")]
pub node_persistent_storage: Option<ClusterAlertSettingsWithThreshold>,
}
pub struct AlertHandler {
client: RestClient,
}
pub type AlertsHandler = AlertHandler;
impl AlertHandler {
pub fn new(client: RestClient) -> Self {
AlertHandler { client }
}
pub async fn list_by_database(&self, bdb_uid: u32) -> Result<Vec<Alert>> {
self.client
.get(&format!("/v1/bdbs/alerts/{}", bdb_uid))
.await
}
pub async fn list_by_node(&self, node_uid: u32) -> Result<Vec<Alert>> {
self.client
.get(&format!("/v1/nodes/alerts/{}", node_uid))
.await
}
pub async fn list_cluster_alerts(&self) -> Result<HashMap<String, ClusterAlertState>> {
self.client.get("/v1/cluster/alerts").await
}
#[deprecated(note = "Redis Software does not register cluster alert-settings routes")]
pub async fn get_settings(&self, _alert_name: &str) -> Result<AlertSettings> {
crate::error::unsupported_operation("get per-alert cluster settings")
}
#[deprecated(note = "Redis Software does not register cluster alert-settings routes")]
pub async fn update_settings(
&self,
_alert_name: &str,
_settings: AlertSettings,
) -> Result<AlertSettings> {
crate::error::unsupported_operation("update per-alert cluster settings")
}
#[deprecated(note = "Redis Software does not register database alert-settings routes")]
pub async fn get_database_alert_settings(&self, _bdb_uid: u32) -> Result<DbAlertsSettings> {
crate::error::unsupported_operation("get database alert settings")
}
#[deprecated(note = "Redis Software does not register database alert-settings routes")]
pub async fn update_database_alert_settings(
&self,
_bdb_uid: u32,
_settings: &DbAlertsSettings,
) -> Result<DbAlertsSettings> {
crate::error::unsupported_operation("update database alert settings")
}
#[deprecated(note = "Redis Software does not register cluster alert-settings routes")]
pub async fn get_cluster_alert_settings(&self) -> Result<ClusterAlertsSettings> {
crate::error::unsupported_operation("get cluster alert settings")
}
#[deprecated(note = "Redis Software does not register cluster alert-settings routes")]
pub async fn update_cluster_alert_settings(
&self,
_settings: &ClusterAlertsSettings,
) -> Result<ClusterAlertsSettings> {
crate::error::unsupported_operation("update cluster alert settings")
}
}