darpan 0.2.5

Linux developer service monitoring utility with auto-detection, real-time health checks, and interactive TUI for databases, APIs, Docker containers, and more
Documentation
use crate::models::{HealthCheckConfig, ServiceRole, ServiceType};
use serde::{Deserialize, Serialize};
use std::collections::HashMap;

/// A service pack defines detection signatures, roles, and defaults for a stack or framework
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ServicePack {
    /// Pack metadata
    pub name: String,
    pub version: String,
    pub description: Option<String>,
    pub author: Option<String>,

    /// Service signatures for auto-detection
    pub signatures: Vec<ServicePackSignature>,

    /// Default health check configurations (keyed by service name pattern)
    #[serde(default)]
    pub default_health_checks: HashMap<String, HealthCheckConfig>,

    /// Default log file paths (keyed by service name pattern)
    #[serde(default)]
    pub default_log_paths: HashMap<String, Vec<String>>,

    /// Default systemd unit names (keyed by service name pattern)
    #[serde(default)]
    pub default_systemd_units: HashMap<String, String>,
}

/// A signature for detecting a service
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ServicePackSignature {
    /// Service name
    pub name: String,

    /// Service type
    #[serde(rename = "type")]
    pub service_type: ServiceType,

    /// Service role
    pub role: ServiceRole,

    /// Port number (if applicable)
    pub port: Option<u16>,

    /// Port range (if applicable, e.g., for multiple instances)
    pub port_range: Option<(u16, u16)>,

    /// Process name pattern (regex or substring)
    pub process_pattern: Option<String>,

    /// Systemd unit name pattern
    pub systemd_unit: Option<String>,

    /// Docker image name pattern
    pub docker_image: Option<String>,

    /// Docker container name pattern
    pub docker_container: Option<String>,

    /// Default health check configuration
    pub health_check: Option<HealthCheckConfig>,

    /// Default log file paths
    #[serde(default)]
    pub log_paths: Vec<String>,

    /// Tags for categorization
    #[serde(default)]
    pub tags: Vec<String>,
}

impl ServicePack {
    /// Create a new empty service pack
    pub fn new(name: String, version: String) -> Self {
        Self {
            name,
            version,
            description: None,
            author: None,
            signatures: Vec::new(),
            default_health_checks: HashMap::new(),
            default_log_paths: HashMap::new(),
            default_systemd_units: HashMap::new(),
        }
    }
}