Skip to content

Latest commit

 

History

History
217 lines (183 loc) · 5.03 KB

ping.rst

File metadata and controls

217 lines (183 loc) · 5.03 KB

Ping Plugin

Overview

The Ping plugin provides network host monitoring capabilities through ICMP ping commands. It can track multiple hosts simultaneously, generate events based on host availability, and provide detailed status information about monitored hosts.

Core Components

Host Monitor

pub struct HostMonitor {
    name: String,
    friendly_name: String,
    ping_delay: Duration,
    event_config: EventConfig,
    monitor_thread: Option<JoinHandle<()>>,
    status: Arc<Mutex<HostStatus>>,
}

impl HostMonitor {
    pub fn start_monitoring(&mut self) -> Result<(), Error> {
        // Initialize monitoring thread
        // Configure ping parameters
        // Start status checks
    }
}

Ping Manager

pub struct PingManager {
    hosts: HashMap<String, HostMonitor>,
    event_emitter: Arc<dyn EventEmitter>,
    ping_config: PingConfig,
}

impl PingManager {
    pub fn add_host(&mut self, config: HostConfig) -> Result<(), Error> {
        // Create host monitor
        // Configure events
        // Start monitoring
    }
}

Event Handler

pub struct EventHandler {
    delay_config: DelayConfig,
    event_queue: Arc<Mutex<VecDeque<HostEvent>>>,
}

impl EventHandler {
    pub fn handle_status_change(&mut self, status: HostStatus) -> Result<(), Error> {
        // Process status change
        // Apply event delays
        // Generate events
    }
}

Key Features

  1. Host Monitoring - Multiple host tracking - Configurable ping delays - Status change detection - Friendly name support - Host status queries
  2. Event System - Host alive events - Host dead events - Delayed event triggering - Custom event names - Status change notifications
  3. Configuration Options - Ping parameters - Event delays - Host properties - Monitor settings - Status reporting
  4. Management Functions - Add hosts - Remove hosts - One-time pings - Status queries - Host configuration

Migration Considerations

  1. Network Integration - ICMP implementation - Thread management - Status tracking - Event coordination
  2. Platform Support - Windows API usage - Command execution - Process handling - Resource management

Implementation Strategy

  1. Host Management .. code-block:: rust

    impl PingPlugin {
    pub fn monitor_host(&mut self, config: HostConfig) -> Result<(), Error> {
    let monitor = HostMonitor::new(

    config.name, config.friendly_name, config.ping_delay,

    );

    monitor.set_event_config(config.events)?; monitor.start_monitoring()?;

    self.hosts.insert(config.name.clone(), monitor); Ok(())

    }

    pub fn remove_host(&mut self, name: &str) -> Result<(), Error> {
    if let Some(monitor) = self.hosts.remove(name) {

    monitor.stop_monitoring()?; monitor.wait_for_completion()?;

    } Ok(())

    }

    }

  2. Status Monitoring .. code-block:: rust

    impl HostMonitor {
    pub fn check_status(&mut self) -> Result<HostStatus, Error> {
    let output = Command::new("ping")

    .arg(&self.name) .arg("-n") .arg("1") .arg("-w") .arg(self.ping_delay.as_millis().to_string()) .output()?;

    self.process_ping_result(output)

    }

    pub fn process_status_change(&mut self, status: HostStatus) -> Result<(), Error> {
    match status {

    HostStatus::Alive => self.handle_alive_status()?, HostStatus::Dead => self.handle_dead_status()?,

    }

    self.notify_status_change(status)

    }

    }

Testing Strategy

  1. Unit Tests - Ping execution - Status processing - Event generation - Configuration validation
  2. Integration Tests - Host monitoring - Event handling - Thread management - Resource cleanup
  3. Performance Tests - Multiple hosts - Network latency - Resource usage - Event throughput

Error Handling

  1. Network Errors - Ping failures - Host unreachable - Timeout handling - Command errors
  2. Thread Management - Start/stop errors - Resource cleanup - State transitions - Deadlock prevention
  3. Event Processing - Event queuing - Delay handling - Status tracking - Resource cleanup

Platform Considerations

  1. Windows Integration - ICMP implementation - Command execution - Process handling - Security context
  2. Resource Management - Thread pools - Process limits - Memory usage - Network resources