#[cfg(feature = "email")]
pub mod email;
#[cfg(feature = "s3")]
pub mod s3;
use anyhow::Result;
use sea_orm::DatabaseConnection;
use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, Serialize, Deserialize, Default)]
pub struct HealthMetrics {
pub cpu_percent: Option<f32>,
pub load: Option<f32>,
pub memory_percent: Option<f32>,
pub disk_read_mb_s: Option<f32>,
pub disk_write_mb_s: Option<f32>,
pub disk_usage_percent: Option<f32>,
pub net_recv_mb_s: Option<f32>,
pub net_trans_mb_s: Option<f32>,
pub bandwidth_mbps: Option<f32>,
}
#[derive(Debug, Clone)]
pub struct ResourceInfo {
pub id: i64,
pub name: String,
pub status: String,
pub region: Option<String>,
pub public_ip: Option<String>,
pub private_ip: Option<String>,
}
#[async_trait::async_trait]
pub trait Provider: Send + Sync {
async fn sync(&self, db: &DatabaseConnection) -> Result<Vec<ResourceInfo>>;
async fn fetch_health(&self, resource_id: i64) -> Result<HealthMetrics>;
fn is_configured(&self) -> bool {
true
}
}
pub struct NoOpProvider;
#[async_trait::async_trait]
impl Provider for NoOpProvider {
async fn sync(&self, _db: &DatabaseConnection) -> Result<Vec<ResourceInfo>> {
Ok(vec![])
}
async fn fetch_health(&self, _resource_id: i64) -> Result<HealthMetrics> {
Ok(HealthMetrics::default())
}
fn is_configured(&self) -> bool {
false
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_health_metrics_default() {
let metrics = HealthMetrics::default();
assert!(metrics.cpu_percent.is_none());
assert!(metrics.memory_percent.is_none());
}
#[test]
fn test_resource_info() {
let info = ResourceInfo {
id: 123,
name: "web-server".to_string(),
status: "running".to_string(),
region: Some("nyc1".to_string()),
public_ip: Some("1.2.3.4".to_string()),
private_ip: Some("10.0.0.1".to_string()),
};
assert_eq!(info.id, 123);
assert_eq!(info.name, "web-server");
}
}